Reputation: 1
I'd like to use Blockly on a form to let users create their own algorithm. For this I'm using a "return" block that I've created so I can call this algo with an eval in PHP.
Here is my block's init :
var jsonReturn = {
"message0" :"Return %1",
"args0" :[
{"type":"input_value", "name":"script"}
],
"previousStatement" :null,
"colour" :70,
"tooltip" :"Renvoie le nouveau prix"}
Blockly.Blocks['return'] = {init: function() { this.jsonInit(jsonReturn);}};
And here's the code generator for PHP :
Blockly.PHP['return'] = function(block) {
var argument0 = Blockly.PHP.valueToCode(block, 'script');
var code = 'return ' + argument0 + ';\n';
return code;
};
What I'd like to do is using a big return block that would contain the whole algorithm in it, and make this return block impossible to remove.
Could anyone help me on this ?
Thanks.
Upvotes: 0
Views: 1099
Reputation: 391
If you want your block to always be on the workspace and be undeletable, you can load it from XML as soon as the page loads.
Your XML would look like this:
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="return" id="my_return_block_id" deletable="false"></block>
</xml>
You would load that with Blockly.Xml.domToWorkspace(yourXml, yourWorkspace)
.
If you want the user to add the block, but for it to then be undeletable, you can make an individual block undeletable with block.setDeletable(false)
after the block has been created.
Upvotes: 2