// 'use strict';

// goog.provide('Blockly.Blocks.easymode');

// goog.require('Blockly.Blocks');
// goog.require('Blockly.Types');

// Blockly.Blocks.easymode.HUE = 215;

// /*wifi easymode
//  *setup for WiFi network
//  */
// Blockly.Blocks['wifiEasymode_network'] = {
//     init: function() {
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_TITLE)
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_SSID)
//             .appendField(new Blockly.FieldTextInput("CocoRobo"), "wifi_ssid")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_PW)
//             .appendField(new Blockly.FieldTextInput("cocorobo"), "wifi_pw")
//         this.setColour("#e55d58");
//         // this.setPreviousStatement(true, null);
//         // this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
// };

// /*****************************************************************************************/

// /*wifi easymode
//  *setup for WiFi network
//  */

// Blockly.Blocks['wifiEasymode_thingspeak'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_THINGSPEAK_APIKEY)
//         this.appendDummyInput()
//             .appendField(" ")
//             .appendField(new Blockly.FieldTextInput("bAssF9YJ_7oZP1k4et_IUx"), "API_KEY")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_THINGSPEAK_SENDDATA)
//         this.itemCount_ = 1;
//         this.updateShape_();
//         this.setMutator(new Blockly.Mutator(['thingspeakEM_create_with_item']));
//         this.setColour("#204d86");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     mutationToDom: function() {
//         var container = document.createElement('mutation');
//         container.setAttribute('items', this.itemCount_);
//         return container;
//     },
//     /**
//      * Parse XML to restore the inputs.
//      * @param {!Element} xmlElement XML storage element.
//      * @this Blockly.Block
//      */
//     domToMutation: function(xmlElement) {
//         this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
//         this.updateShape_();
//     },
//     /**
//      * Populate the mutator's dialog with this block's components.
//      * @param {!Blockly.Workspace} workspace Mutator's workspace.
//      * @return {!Blockly.Block} Root block in mutator.
//      * @this Blockly.Block
//      */
//     decompose: function(workspace) {
//         var containerBlock = workspace.newBlock('thingspeakEM_create_with_container');
//         containerBlock.initSvg();
//         var connection = containerBlock.getInput('STACK').connection;
//         for (var i = 0; i < this.itemCount_; i++) {
//             var itemBlock = workspace.newBlock('thingspeakEM_create_with_item');
//             itemBlock.initSvg();
//             connection.connect(itemBlock.previousConnection);
//             connection = itemBlock.nextConnection;
//         }
//         return containerBlock;
//     },
//     /**
//      * Reconfigure this block based on the mutator dialog's components.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     compose: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         // Count number of inputs.
//         var connections = [];
//         while (itemBlock) {
//             connections.push(itemBlock.valueConnection_);
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//         // Disconnect any children that don't belong.
//         for (var i = 0; i < this.itemCount_; i++) {
//             var connection = this.getInput('ADD' + i).connection.targetConnection;
//             if (connection && connections.indexOf(connection) == -1) {
//                 connection.disconnect();
//             }
//         }
//         this.itemCount_ = connections.length;
//         this.updateShape_();
//         // Reconnect any child blocks.
//         for (var i = 0; i < this.itemCount_; i++) {
//             Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
//         }
//     },
//     /**
//      * Store pointers to any connected child blocks.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     saveConnections: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         var i = 0;
//         while (itemBlock) {
//             var input = this.getInput('ADD' + i);
//             itemBlock.valueConnection_ = input && input.connection.targetConnection;
//             i++;
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//     },
//     /**
//      * Modify this block to have the correct number of inputs.
//      * @private
//      * @this Blockly.Block
//      */
//     updateShape_: function() {
//         if (this.itemCount_ && this.getInput('EMPTY')) {
//             this.removeInput('EMPTY');
//         } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
//             this.appendDummyInput('EMPTY')
//                 .appendField(this.newQuote_(true))
//                 .appendField(this.newQuote_(false));
//         }
//         // Add new inputs.
//         for (var i = 0; i < this.itemCount_; i++) {
//             if (!this.getInput('ADD' + i)) {
//                 var input = this.appendValueInput('ADD' + i);
//                 input.appendField(" " + "Field " + (i + 1) + ":");
//             }
//         }

//         if (!this.getInput('ADD' + this.itemCount_)) {
//             this.appendDummyInput('ADD' + this.itemCount_);
//         }

//         // Remove deleted inputs.
//         while (this.getInput('ADD' + i)) {
//             this.removeInput('ADD' + i);
//             i++;
//         }
//     },
// };
// Blockly.Blocks['thingspeakEM_create_with_container'] = {
//     /**
//      * Mutator block for list container.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#204d86");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
//         this.appendStatementInput('STACK');
//         this.setTooltip('');
//         this.contextMenu = false;
//     }
// };
// Blockly.Blocks['thingspeakEM_create_with_item'] = {
//     /**
//      * Mutator bolck for adding items.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#204d86");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
//         this.setPreviousStatement(true);
//         this.setNextStatement(true);
//         this.setTooltip('');
//         this.contextMenu = false;
//     }
// };


// /*****************************************************************************************/

// /*wifi easymode
//  * CocoCloud 
//  * post data {JSON} to Cloud event
//  */

// Blockly.Blocks['wifiEasymode_cococloud_post'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/blockly-easymode_cococloud.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOClOUD_EVENT);
//         this.appendDummyInput("ADD0")
//             .appendField(" ")
//             // .appendField(new Blockly.FieldDropdown([
//             //     ["Your event", "Your event"]
//             // ]), "event0");
//             .appendField(new Blockly.FieldTextInput("http://api.cocorobo.cn/iot/data/apikey/af69409636e28e959252812bf7397f200f3a9de368f298e8926edc706c534eaa/event/camera"), "event0")
//         this.appendValueInput("dataA")
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SENDDATA)
//             // this.updateEvent_();
//         this.setColour("#5da5f9");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     updateEvent_: function() {
//         // Add new inputs.
//         var self = this;
//         var input = this.getInput('ADD0');
//         var api_key = document.getElementById('api-key').innerHTML || "";
//         $.ajax({
//             // url: '//api.cocorobo.cn/iot/data/apikey/' + api_key + '/event/',
//             url: '//staging.cocorobo.cn/api/iot/data/apikey/' + api_key + '/event/',
//             xhrFields: {
//                 withCredentials: true
//             },
//             type: 'GET',
//             success: function(data) {
//                 var eventsName = [];
//                 if (data != null) {
//                     $.each(data, function(i, obj) {
//                         var temparray = []
//                         temparray.push(obj.name);
//                         temparray.push(obj.url);
//                         eventsName.push(temparray);
//                     });
//                     self.eventsName = eventsName;
//                     input.removeField("event0");
//                     input.appendField(new Blockly.FieldDropdown(eventsName), "event0");
//                 }
//             },
//             error: function(error) {
//                 console.log("error");
//             }
//         });
//     }
// }

// /*wifi easymode
//  * CocoCloud 
//  * post data {JSON} to Cloud event
//  */

// Blockly.Blocks['wifiEasymode_cococloud_get'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/blockly-easymode_cococloud.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOClOUD_EVENT)
//         this.appendDummyInput("ADD0")
//             .appendField(" ")
//             // .appendField(new Blockly.FieldDropdown([
//             //     ["Your event", "Your event"]
//             // ]), "event0");
//             .appendField(new Blockly.FieldTextInput("http://api.cocorobo.cn/iot/data/apikey/af69409636e28e959252812bf7397f200f3a9de368f298e8926edc706c534eaa/event/camera"), "event0")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOCLOUD_GETDATA)
//             .appendField(new Blockly.FieldVariable("dataGet"), "DATAVAR");
//         // this.updateEvent_();
//         this.setColour("#5da5f9");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     updateEvent_: function() {
//         // Add new inputs.
//         var self = this;
//         var input = this.getInput('ADD0');
//         var api_key = document.getElementById('api-key').innerHTML || "";
//         $.ajax({
//             // url: '//api.cocorobo.cn/iot/data/apikey/' + api_key + '/event/',
//             url: '//staging.cocorobo.cn/api/iot/data/apikey/' + api_key + '/event/',
//             xhrFields: {
//                 withCredentials: true
//             },
//             type: 'GET',
//             success: function(data) {
//                 var eventsName = [];
//                 if (data != null) {
//                     $.each(data, function(i, obj) {
//                         var temparray = []
//                         temparray.push(obj.name);
//                         temparray.push(obj.url);
//                         eventsName.push(temparray);
//                     });
//                     self.eventsName = eventsName;
//                     input.removeField("event0");
//                     input.appendField(new Blockly.FieldDropdown(eventsName), "event0");
//                 }
//             },
//             error: function(error) {
//                 console.log("error");
//             }
//         });
//     },
//     getVarType: function(varName) {
//         let vartype = Blockly.Types.TEXT;
//         return vartype;
//     }
// }

// /*****************************************************************************************/

// /*wifi easymode
//  * CocoCloud 
//  * post data {JSON} to Cloud event
//  */
// Blockly.Blocks['wifiEasymode_cococloud2_post'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/cloud-tx.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOClOUD_EVENT);
//         this.appendDummyInput()
//             .appendField(" ")
//             // .appendField(new Blockly.FieldDropdown([
//             //     ["Your event", "Your event"]
//             // ]), "event0");
//             .appendField(new Blockly.FieldTextInput("d0f98bb70ae070cd89725780e67dfe6b"), "event0")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SENDDATA);
//         this.appendValueInput("ADD0")
//             .appendField(Blockly.Msg.WIFIEASYMODE_COCOClOUD_DATA_NAME)
//             .appendField(new Blockly.FieldTextInput("EM_data0"), "field0")
//         this.itemCount_ = 1;
//         this.updateShape_();
//         this.setMutator(new Blockly.Mutator(['cococloud_create_with_item']));
//         // this.updateEvent_();
//         this.setColour("#5da5f9");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     mutationToDom: function() {
//         var container = document.createElement('mutation');
//         container.setAttribute('items', this.itemCount_);
//         return container;
//     },
//     /**
//      * Parse XML to restore the inputs.
//      * @param {!Element} xmlElement XML storage element.
//      * @this Blockly.Block
//      */
//     domToMutation: function(xmlElement) {
//         this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
//         this.updateShape_();
//     },
//     /**
//      * Populate the mutator's dialog with this block's components.
//      * @param {!Blockly.Workspace} workspace Mutator's workspace.
//      * @return {!Blockly.Block} Root block in mutator.
//      * @this Blockly.Block
//      */
//     decompose: function(workspace) {
//         var containerBlock = workspace.newBlock('cococloud_create_with_container');
//         containerBlock.initSvg();
//         var connection = containerBlock.getInput('STACK').connection;
//         for (var i = 0; i < this.itemCount_; i++) {
//             var itemBlock = workspace.newBlock('cococloud_create_with_item');
//             itemBlock.initSvg();
//             connection.connect(itemBlock.previousConnection);
//             connection = itemBlock.nextConnection;
//         }
//         return containerBlock;
//     },
//     /**
//      * Reconfigure this block based on the mutator dialog's components.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     compose: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         // Count number of inputs.
//         var connections = [];
//         while (itemBlock) {
//             connections.push(itemBlock.valueConnection_);
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//         // Disconnect any children that don't belong.
//         for (var i = 0; i < this.itemCount_; i++) {
//             var connection = this.getInput('ADD' + i).connection.targetConnection;
//             if (connection && connections.indexOf(connection) == -1) {
//                 connection.disconnect();
//             }
//         }
//         this.itemCount_ = connections.length;
//         this.updateShape_();
//         // Reconnect any child blocks.
//         for (var i = 0; i < this.itemCount_; i++) {
//             Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
//         }
//     },
//     /**
//      * Store pointers to any connected child blocks.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     saveConnections: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         var i = 0;
//         while (itemBlock) {
//             var input = this.getInput('ADD' + i);
//             itemBlock.valueConnection_ = input && input.connection.targetConnection;
//             i++;
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//     },
//     /**
//      * Modify this block to have the correct number of inputs.
//      * @private
//      * @this Blockly.Block
//      */
//     updateShape_: function() {
//         if (this.itemCount_ && this.getInput('EMPTY')) {
//             this.removeInput('EMPTY');
//         } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
//             this.appendDummyInput('EMPTY')
//                 .appendField(this.newQuote_(true))
//                 .appendField(this.newQuote_(false));
//         }
//         // Add new inputs.
//         for (var i = 0; i < this.itemCount_; i++) {
//             if (!this.getInput('ADD' + i)) {
//                 var input = this.appendValueInput('ADD' + i);
//                 input.appendField(Blockly.Msg.WIFIEASYMODE_COCOClOUD_DATA_NAME)
//                     .appendField(new Blockly.FieldTextInput("EM_data" + i), "field" + i);
//             }
//         }

//         if (!this.getInput('ADD' + this.itemCount_)) {
//             this.appendDummyInput('ADD' + this.itemCount_);
//         }

//         // Remove deleted inputs.
//         while (this.getInput('ADD' + i)) {
//             this.removeInput('ADD' + i);
//             i++;
//         }
//     },
//     updateEvent_: function() {
//         // Add new inputs.
//         var self = this;
//         var input = this.getInput('ADD0');
//         var api_key = document.getElementById('api-key').innerHTML || "";
//         $.ajax({
//             // url: '//api.cocorobo.cn/iot/data/apikey/' + api_key + '/event/',
//             url: '//staging.cocorobo.cn/api/iot/data/apikey/' + api_key + '/event/',
//             xhrFields: {
//                 withCredentials: true
//             },
//             type: 'GET',
//             success: function(data) {
//                 var eventsName = [];
//                 if (data != null) {
//                     $.each(data, function(i, obj) {
//                         var temparray = []
//                         temparray.push(obj.name);
//                         temparray.push(obj.url);
//                         eventsName.push(temparray);
//                     });
//                     self.eventsName = eventsName;
//                     input.removeField("event0");
//                     input.appendField(new Blockly.FieldDropdown(eventsName), "event0");
//                 }
//             },
//             error: function(error) {
//                 console.log("error");
//             }
//         });
//     }
// };
// Blockly.Blocks['cococloud_create_with_container'] = {
//     /**
//      * Mutator block for list container.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#5da5f9");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
//         this.appendStatementInput('STACK');
//         this.setTooltip('');
//         this.contextMenu = false;
//     }
// };
// Blockly.Blocks['cococloud_create_with_item'] = {
//     /**
//      * Mutator bolck for adding items.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#5da5f9");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
//         this.setPreviousStatement(true);
//         this.setNextStatement(true);
//         this.setTooltip('');
//         this.contextMenu = false;
//     },

// }

// /*wifi easymode
//  * CocoCloud 
//  * post data {JSON} to Cloud event
//  */
// Blockly.Blocks['wifiEasymode_cococloud2_get'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/cloud-rx.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOClOUD_EVENT)
//         this.appendDummyInput()
//             .appendField(" ")
//             .appendField(new Blockly.FieldTextInput("d0f98bb70ae070cd89725780e67dfe6b"), "event0")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_COCOCLOUD_GETDATA)
//             // .appendField(new Blockly.FieldVariable("dataGet"), "DATAVAR");
//         this.appendValueInput("ADD0")
//             .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SETVAR)
//             .appendField(new Blockly.FieldVariable("data_0"), "DATA0")
//             .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SETVAR_FROM)
//             // this.updateEvent_();
//         this.itemCount_ = 1;
//         this.updateShape_();
//         this.setMutator(new Blockly.Mutator(['cococloud_create_with_item']));
//         // this.updateEvent_();
//         this.setColour("#5da5f9");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     mutationToDom: function() {
//         var container = document.createElement('mutation');
//         container.setAttribute('items', this.itemCount_);
//         return container;
//     },
//     /**
//      * Parse XML to restore the inputs.
//      * @param {!Element} xmlElement XML storage element.
//      * @this Blockly.Block
//      */
//     domToMutation: function(xmlElement) {
//         this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
//         this.updateShape_();
//     },
//     /**
//      * Populate the mutator's dialog with this block's components.
//      * @param {!Blockly.Workspace} workspace Mutator's workspace.
//      * @return {!Blockly.Block} Root block in mutator.
//      * @this Blockly.Block
//      */
//     decompose: function(workspace) {
//         var containerBlock = workspace.newBlock('cococloud_create_with_container');
//         containerBlock.initSvg();
//         var connection = containerBlock.getInput('STACK').connection;
//         for (var i = 0; i < this.itemCount_; i++) {
//             var itemBlock = workspace.newBlock('cococloud_create_with_item');
//             itemBlock.initSvg();
//             connection.connect(itemBlock.previousConnection);
//             connection = itemBlock.nextConnection;
//         }
//         return containerBlock;
//     },
//     /**
//      * Reconfigure this block based on the mutator dialog's components.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     compose: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         // Count number of inputs.
//         var connections = [];
//         while (itemBlock) {
//             connections.push(itemBlock.valueConnection_);
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//         // Disconnect any children that don't belong.
//         for (var i = 0; i < this.itemCount_; i++) {
//             var connection = this.getInput('ADD' + i).connection.targetConnection;
//             if (connection && connections.indexOf(connection) == -1) {
//                 connection.disconnect();
//             }
//         }
//         this.itemCount_ = connections.length;
//         this.updateShape_();
//         // Reconnect any child blocks.
//         for (var i = 0; i < this.itemCount_; i++) {
//             Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
//         }
//     },
//     /**
//      * Store pointers to any connected child blocks.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     saveConnections: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         var i = 0;
//         while (itemBlock) {
//             var input = this.getInput('ADD' + i);
//             itemBlock.valueConnection_ = input && input.connection.targetConnection;
//             i++;
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//     },
//     /**
//      * Modify this block to have the correct number of inputs.
//      * @private
//      * @this Blockly.Block
//      */
//     updateShape_: function() {
//         if (this.itemCount_ && this.getInput('EMPTY')) {
//             this.removeInput('EMPTY');
//         } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
//             this.appendDummyInput('EMPTY')
//                 .appendField(this.newQuote_(true))
//                 .appendField(this.newQuote_(false));
//         }
//         // Add new inputs.
//         for (var i = 0; i < this.itemCount_; i++) {
//             if (!this.getInput('ADD' + i)) {
//                 var input = this.appendValueInput('ADD' + i)
//                     .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SETVAR)
//                     .appendField(new Blockly.FieldVariable("data_" + i), "DATA" + i)
//                     .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_SETVAR_FROM)
//             }
//         }

//         if (!this.getInput('ADD' + this.itemCount_)) {
//             this.appendDummyInput('ADD' + this.itemCount_);
//         }

//         // Remove deleted inputs.
//         while (this.getInput('ADD' + i)) {
//             this.removeInput('ADD' + i);
//             i++;
//         }
//     },
//     updateEvent_: function() {
//         // Add new inputs.
//         var self = this;
//         var input = this.getInput('ADD0');
//         var api_key = document.getElementById('api-key').innerHTML || "";
//         $.ajax({
//             // url: '//api.cocorobo.cn/iot/data/apikey/' + api_key + '/event/',
//             url: '//staging.cocorobo.cn/api/iot/data/apikey/' + api_key + '/event/',
//             xhrFields: {
//                 withCredentials: true
//             },
//             type: 'GET',
//             success: function(data) {
//                 var eventsName = [];
//                 if (data != null) {
//                     $.each(data, function(i, obj) {
//                         var temparray = []
//                         temparray.push(obj.name);
//                         temparray.push(obj.url);
//                         eventsName.push(temparray);
//                     });
//                     self.eventsName = eventsName;
//                     input.removeField("event0");
//                     input.appendField(new Blockly.FieldDropdown(eventsName), "event0");
//                 }
//             },
//             error: function(error) {
//                 console.log("error");
//             }
//         });
//     },
//     getVarType: function(varName) {
//         return Blockly.Types.TEXT;
//     }
// };

// Blockly.Blocks['wifiEasymode_cococloud2_get_data'] = {
//     init: function() {
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_KEY)
//             .appendField(new Blockly.FieldTextInput("EM_data"), "KEY")
//             // .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_TYPE)
//             // .appendField(new Blockly.FieldDropdown(
//             //     [
//             //         ["Text", "Text"],
//             //         ["Number", "Number"],
//             //         ["Boolean", "Boolean"],
//             //         ["Large Number", "Large Number"],
//             //         ["Decimal", "Decimal"]
//             //     ]), 'VAR_TYPE')
//             .appendField(Blockly.Msg.WIFIEASYMODE_COCOCLOUD_END)
//             // this.updateEvent_();
//         this.setColour("#5da5f9");
//         this.setOutput(true);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     getBlockType: function() {
//         // var blocktype = Blockly.Types.TEXT
//         // switch (this.getFieldValue("VAR_TYPE")) {
//         //     case "Text":
//         //         blocktype = Blockly.Types.TEXT;
//         //         break;
//         //     case "Number":
//         //         blocktype = Blockly.Types.NUMBER;
//         //         break;
//         //     case "Boolean":
//         //         blocktype = Blockly.Types.BOOLEAN;
//         //         break;
//         //     case "Large Number":
//         //         blocktype = Blockly.Types.LARGE_NUMBER;
//         //         break;
//         //     case "Decimal":
//         //         blocktype = Blockly.Types.DECIMAL;
//         //         break;
//         // }
//         return Blockly.Types.TEXT;
//     }
// };


// /*****************************************************************************************/

// /*wifi easymode
//  * IFTTT
//  * post data {JSON} to Cloud event
//  */
// Blockly.Blocks['wifiEasymode_IFTTT'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/blockly-easymode_thingspeak.png", 180, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/blockly-easymode_ifttt.png", 180, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_IFTTT_KEY);
//         this.appendDummyInput()
//             .appendField(" ")
//             .appendField(new Blockly.FieldTextInput("bAssF9YJ_7oZP1k4et_IUx"), "IFTTT_KEY")
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_IFTTT_EVENT);
//         this.appendDummyInput()
//             .appendField(" ")
//             .appendField(new Blockly.FieldTextInput("cocorobo_webhook"), "IFTTT_EVENT")
//         this.appendValueInput("dataA")
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_IFTTT_SENDDATA)
//         this.setColour("#ee9220");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },

// }

// /*****************************************************************************************/

// /*wifi easymode
//  * wifi-2-main transfer
//  * send msg from wifi to main
//  */
// Blockly.Blocks['wifiEasymode_transfer_send'] = {
//     init: function() {
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND)
//             .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND_LINE2);
//         this.setColour("#1e61bf");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     getVarType: function(varName) {
//         let vartype = Blockly.Types.ARRAY;
//         return vartype;
//     }
// }

// /*wifi easymode
//  * wifi-2-main transfer
//  * receive msg from main to wifi
//  */
// Blockly.Blocks['wifiEasymode_transfer_receive'] = {
//     init: function() {
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE)
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_LINE2)
//             .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
//         this.setColour("#1e61bf");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     getVarType: function(varName) {
//         let vartype = Blockly.Types.ARRAY;
//         return vartype;
//     }
// }


// /*****************************************************************************************/

// /*wifi easymode
//  * wifi-2-main transfer
//  * send msg from wifi to main
//  */
// Blockly.Blocks['wifiEasymode_transfer2_send'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/transfer-2.png", 50, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND)
//             .appendField(new Blockly.FieldDropdown([
//                 ["txData", "txData"]
//             ]), "DATAMAIN");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND_LINE2);
//         this.appendValueInput("ADD0")
//             .appendField(Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND_VALUE + "0")
//         this.setColour("#1e61bf");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");

//         this.itemCount_ = 1;
//         this.updateShape_();
//         this.setMutator(new Blockly.Mutator(['Easymode_transfer_create_with_item']));


//     },
//     mutationToDom: function() {
//         var container = document.createElement('mutation');
//         container.setAttribute('items', this.itemCount_);
//         return container;
//     },
//     /**
//      * Parse XML to restore the inputs.
//      * @param {!Element} xmlElement XML storage element.
//      * @this Blockly.Block
//      */
//     domToMutation: function(xmlElement) {
//         this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
//         this.updateShape_();
//     },
//     /**
//      * Populate the mutator's dialog with this block's components.
//      * @param {!Blockly.Workspace} workspace Mutator's workspace.
//      * @return {!Blockly.Block} Root block in mutator.
//      * @this Blockly.Block
//      */
//     decompose: function(workspace) {
//         var containerBlock = workspace.newBlock('Easymode_transfer_create_with_container');
//         containerBlock.initSvg();
//         var connection = containerBlock.getInput('STACK').connection;
//         for (var i = 0; i < this.itemCount_; i++) {
//             var itemBlock = workspace.newBlock('Easymode_transfer_create_with_item');
//             itemBlock.initSvg();
//             connection.connect(itemBlock.previousConnection);
//             connection = itemBlock.nextConnection;
//         }
//         return containerBlock;
//     },
//     /**
//      * Reconfigure this block based on the mutator dialog's components.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     compose: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         // Count number of inputs.
//         var connections = [];
//         while (itemBlock) {
//             connections.push(itemBlock.valueConnection_);
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//         // Disconnect any children that don't belong.
//         for (var i = 0; i < this.itemCount_; i++) {
//             var connection = this.getInput('ADD' + i).connection.targetConnection;
//             if (connection && connections.indexOf(connection) == -1) {
//                 connection.disconnect();
//             }
//         }
//         this.itemCount_ = connections.length;
//         this.updateShape_();
//         // Reconnect any child blocks.
//         for (var i = 0; i < this.itemCount_; i++) {
//             Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
//         }
//     },
//     /**
//      * Store pointers to any connected child blocks.
//      * @param {!Blockly.Block} containerBlock Root block in mutator.
//      * @this Blockly.Block
//      */
//     saveConnections: function(containerBlock) {
//         var itemBlock = containerBlock.getInputTargetBlock('STACK');
//         var i = 0;
//         while (itemBlock) {
//             var input = this.getInput('ADD' + i);
//             itemBlock.valueConnection_ = input && input.connection.targetConnection;
//             i++;
//             itemBlock = itemBlock.nextConnection &&
//                 itemBlock.nextConnection.targetBlock();
//         }
//     },
//     /**
//      * Modify this block to have the correct number of inputs.
//      * @private
//      * @this Blockly.Block
//      */
//     updateShape_: function() {
//         if (this.itemCount_ && this.getInput('EMPTY')) {
//             this.removeInput('EMPTY');
//         } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
//             this.appendDummyInput('EMPTY')
//                 .appendField(this.newQuote_(true))
//                 .appendField(this.newQuote_(false));
//         }
//         // Add new inputs.
//         for (var i = 0; i < this.itemCount_; i++) {
//             if (!this.getInput('ADD' + i)) {
//                 var input = this.appendValueInput('ADD' + i)
//                     .appendField(Blockly.Msg.WIFIEASYMODE_TRANSFER_SEND_VALUE + i);
//             }

//         }
//         this.removeInput('ADD' + this.itemCount_)
//             // Remove deleted inputs.
//         while (this.getInput('ADD' + i)) {
//             this.removeInput('ADD' + i);
//             i++;
//         }
//     },
// };
// Blockly.Blocks['Easymode_transfer_create_with_container'] = {
//     /**
//      * Mutator block for list container.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#1e61bf");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
//         this.appendStatementInput('STACK');
//         this.setTooltip('');
//         this.contextMenu = false;
//     }
// };
// Blockly.Blocks['Easymode_transfer_create_with_item'] = {
//     /**
//      * Mutator bolck for adding items.
//      * @this Blockly.Block
//      */
//     init: function() {
//         this.setColour("#1e61bf");
//         this.appendDummyInput()
//             .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
//         this.setPreviousStatement(true);
//         this.setNextStatement(true);
//         this.setTooltip('');
//         this.contextMenu = false;
//     }
// };


// /*wifi easymode
//  * wifi-2-main transfer
//  * receive msg from main to wifi
//  */
// Blockly.Blocks['wifiEasymode_transfer2_receive'] = {
//     init: function() {
//         this.appendDummyInput()
//             // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
//             .appendField(new Blockly.FieldImage("./../blockly/media/transfer-2.png", 50, 40, "0"));
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE)
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_LINE2)
//             .appendField(new Blockly.FieldDropdown([
//                 ["rxData", "rxData"]
//             ]), "DATAMAIN");
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_LINE3)
//             .appendField(new Blockly.FieldDropdown([
//                 ["1", "1"],
//                 ["2", "2"],
//                 ["3", "3"],
//                 ["4", "4"],
//                 ["5", "5"],
//                 ["6", "6"],
//             ]), "LENGTH");
//         this.setColour("#1e61bf");
//         this.setPreviousStatement(true, null);
//         this.setNextStatement(true, null);
//         // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     getVarType: function(varName) {
//         let vartype = Blockly.Types.ARRAY;
//         return vartype;
//     }
// }

// /*wifi easymode
//  * wifi-2-main transfer
//  * get data from dataMain 
//  * @param {dataMain} :where data tranferred stored in 
//  */
// Blockly.Blocks['wifiEasymode_transfer2_receive_getValue'] = {
//     init: function() {
//         this.appendDummyInput()
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_GET)
//             .appendField(new Blockly.FieldDropdown([
//                 ["rxData", "rxData"]
//             ]), "DATAMAIN")
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
//             .appendField(new Blockly.FieldDropdown([
//                 ["0", "0"],
//                 ["1", "1"],
//                 ["2", "2"],
//                 ["3", "3"],
//                 ["4", "4"],
//                 ["5", "5"],
//             ]), "INDEX")
//             .appendField(" " + Blockly.Msg.WIFIEASYMODE_TRANSFER_RECEIVE_GET_LINE3);
//         this.setColour("#1e61bf");
//         this.setOutput(true)
//             // this.setInputsInline(true);
//         this.setTooltip("");
//         this.setHelpUrl("");
//     },
//     getBlockType: function() {
//         return Blockly.Types.NUMBER;
//     }
// }