From ca966979a4ff6d76eb53669fc8e6c2c3e47afc08 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 11 Nov 2014 14:06:02 -0800 Subject: [PATCH] Fix Block Factory when types are saved. --- appengine/index_redirect.py | 2 +- demos/blockfactory/blocks.js | 79 ++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/appengine/index_redirect.py b/appengine/index_redirect.py index 2bc1d0368..286a8e87c 100644 --- a/appengine/index_redirect.py +++ b/appengine/index_redirect.py @@ -1,2 +1,2 @@ print("Status: 302") -print("Location: /static/apps/index.html") +print("Location: /static/demos/index.html") diff --git a/demos/blockfactory/blocks.js b/demos/blockfactory/blocks.js index 6ff5d59b2..039be5366 100644 --- a/demos/blockfactory/blocks.js +++ b/demos/blockfactory/blocks.js @@ -45,40 +45,7 @@ Blockly.Blocks['factory_base'] = { ['↑ top connection', 'TOP'], ['↓ bottom connection', 'BOTTOM']], function(option) { - var block = this.sourceBlock_; - var outputExists = block.getInput('OUTPUTTYPE'); - var topExists = block.getInput('TOPTYPE'); - var bottomExists = block.getInput('BOTTOMTYPE'); - if (option == 'LEFT') { - if (!outputExists) { - block.appendValueInput('OUTPUTTYPE') - .setCheck('Type') - .appendField('output type'); - block.moveInputBefore('OUTPUTTYPE', 'COLOUR'); - } - } else if (outputExists) { - block.removeInput('OUTPUTTYPE'); - } - if (option == 'TOP' || option == 'BOTH') { - if (!topExists) { - block.appendValueInput('TOPTYPE') - .setCheck('Type') - .appendField('top type'); - block.moveInputBefore('TOPTYPE', 'COLOUR'); - } - } else if (topExists) { - block.removeInput('TOPTYPE'); - } - if (option == 'BOTTOM' || option == 'BOTH') { - if (!bottomExists) { - block.appendValueInput('BOTTOMTYPE') - .setCheck('Type') - .appendField('bottom type'); - block.moveInputBefore('BOTTOMTYPE', 'COLOUR'); - } - } else if (bottomExists) { - block.removeInput('BOTTOMTYPE'); - } + this.sourceBlock_.updateShape_(option); }); this.appendDummyInput() .appendField(dropdown, 'CONNECTIONS'); @@ -95,6 +62,50 @@ Blockly.Blocks['factory_base'] = { */ this.setTooltip('Build a custom block by plugging\n' + 'fields, inputs and other blocks here.'); + }, + mutationToDom: function() { + var container = document.createElement('mutation'); + container.setAttribute('connections', this.getFieldValue('CONNECTIONS')); + return container; + }, + domToMutation: function(xmlElement) { + var connections = xmlElement.getAttribute('connections'); + this.updateShape_(connections); + }, + updateShape_: function(option) { + var outputExists = this.getInput('OUTPUTTYPE'); + var topExists = this.getInput('TOPTYPE'); + var bottomExists = this.getInput('BOTTOMTYPE'); + if (option == 'LEFT') { + if (!outputExists) { + this.appendValueInput('OUTPUTTYPE') + .setCheck('Type') + .appendField('output type'); + this.moveInputBefore('OUTPUTTYPE', 'COLOUR'); + } + } else if (outputExists) { + this.removeInput('OUTPUTTYPE'); + } + if (option == 'TOP' || option == 'BOTH') { + if (!topExists) { + this.appendValueInput('TOPTYPE') + .setCheck('Type') + .appendField('top type'); + this.moveInputBefore('TOPTYPE', 'COLOUR'); + } + } else if (topExists) { + this.removeInput('TOPTYPE'); + } + if (option == 'BOTTOM' || option == 'BOTH') { + if (!bottomExists) { + this.appendValueInput('BOTTOMTYPE') + .setCheck('Type') + .appendField('bottom type'); + this.moveInputBefore('BOTTOMTYPE', 'COLOUR'); + } + } else if (bottomExists) { + this.removeInput('BOTTOMTYPE'); + } } };