Greetings fellow block-heads,
I have implemented the original Blockly into my Angularjs controller, and have trimmed down the toolbox options.
I am trying to clear the blocks from the following form div with a "cancel" button:
<div class="form-group" id="editor" data-ng-show="seeEditor" style="height: 500px; width: 1200px;"
data-ng-class="{'has-error' : saveForm.name.$invalid && saveForm.name.$dirty,
'has-error': saveForm.description.$invalid && regForm.description.$dirty}">
I am using Blockly injection and the div should look a little familiar to this:
Here is my js code:
//cancel new script
$scope.cancel = function () {
ClearEditor();
$scope.seeEditor = false;
}
//clears blocks from editor
function ClearEditor(form) {
$scope.scriptName = '';
$scope.scriptDescription = '';
$scope.userDomXml = '';
$scope.userJavascriptCode = '';
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
function discard() {
var count = Blockly.mainWorkspace.getAllBlocks().length;
if (count < 2 || window.confirm('Delete all ' + count + ' blocks?')) {
Blockly.mainWorkspace.clear();
renderContent();
}
}
}
Here is the original Blockly function to clear all blocks:
/**
* Discard all blocks from the workspace.
*/
Code.discard = function() {
var count = Blockly.mainWorkspace.getAllBlocks().length;
if (count < 2 ||
window.confirm(BlocklyApps.getMsg('Code_discard').replace('%1', count))) {
Blockly.mainWorkspace.clear();
window.location.hash = '';
}
};
Note the only difference is I do not reference "Code.discard" at the very beginning of the function. Doing so causes the following console message in Batarang:
ReferenceError: Code is not defined
I have tried substituting "Blockly.discard" which does not cause an error, but also does not clear the blocks from the editor. Also the two lines
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);"
do not effect the results either.
Right now, if I select to "cancel" creating a new Blockly script the editor is hidden from view. However if I select a "New" (not shown here) script option the editor appears with the previously selected blocks.
How can I clear the blocks from the editor so that it is completely clear when the user navigates to it again?