How to use the blockly.mainWorkspace function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github binary-com / binary-bot / src / botPage / view / view.js View on Github external
return function (e) {
			try {
				blockly.mainWorkspace.clear();
				var xml = blockly.Xml.textToDom(e.target.result);
				blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
				botUtils.addPurchaseOptions();
				blockly.mainWorkspace.clearUndo();
				blockly.mainWorkspace.zoomToFit();
        setBlockColors();
				botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
			} catch (err) {
				botUtils.showError(err);
			}
		};
	})(f);
github binary-com / binary-bot / src / botPage / view / view.js View on Github external
return function (e) {
			try {
				blockly.mainWorkspace.clear();
				var xml = blockly.Xml.textToDom(e.target.result);
				blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
				botUtils.addPurchaseOptions();
				blockly.mainWorkspace.clearUndo();
				blockly.mainWorkspace.zoomToFit();
        setBlockColors();
				botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
			} catch (err) {
				botUtils.showError(err);
			}
		};
	})(f);
github binary-com / binary-bot / src / cat / bot / view / index.js View on Github external
return function (e) {
			try {
				blockly.mainWorkspace.clear();
				var xml = blockly.Xml.textToDom(e.target.result);
				blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
				botUtils.addPurchaseOptions();
				var tokenList = storageManager.getTokenList();
				if (tokenList.length !== 0) {
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setValue(tokenList[0].token);
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setText(tokenList[0].account_name);
				}
				blockly.mainWorkspace.clearUndo();
				blockly.mainWorkspace.zoomToFit();
				botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
			} catch (err) {
github binary-com / binary-bot / src / cat / bot / view / index.js View on Github external
var saveXml = function saveXml(showOnly) {
	var xmlDom = blockly.Xml.workspaceToDom(blockly.mainWorkspace);
	Array.prototype.slice.apply(xmlDom.getElementsByTagName('field'))
		.forEach(function (field) {
			if (field.getAttribute('name') === 'ACCOUNT_LIST') {
				if (field.childNodes.length >= 1) {
					field.childNodes[0].nodeValue = '';
				}
			}
		});
	Array.prototype.slice.apply(xmlDom.getElementsByTagName('block'))
		.forEach(function (block) {
			switch (block.getAttribute('type')) {
			case 'trade':
				block.setAttribute('id', 'trade');
				break;
			case 'on_strategy':
				block.setAttribute('id', 'strategy');
github binary-com / binary-bot / src / ui.js View on Github external
$.get('xml/main.xml', function (main) {
		blockly.Xml.domToWorkspace(main.getElementsByTagName('xml')[0], workspace);
		blockly.mainWorkspace.getBlockById('trade')
			.setDeletable(false);
		blockly.mainWorkspace.getBlockById('strategy')
			.setDeletable(false);
		blockly.mainWorkspace.getBlockById('finish')
			.setDeletable(false);
		view.updateTokenList();
		view.addPurchaseOptions();
		blockly.mainWorkspace.clearUndo();
		view.initTours();
	});
});
github binary-com / binary-bot / src / bot / utils / view.js View on Github external
var updateTokenList = function updateTokenList(tokenToAdd) {
	var tokenList = storageManager.getTokenList();
	blockly.WidgetDiv.hideIfOwner(blockly.mainWorkspace.getBlockById('trade')
		.getField('ACCOUNT_LIST'));
	if (tokenList.length === 0) {
		$('#addAccount')
			.text('Login');
		$('#logout')
			.hide();
		globals.lists.accounts = [
			[i18n._('Please add a token first'), '']
		];
		blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.setValue('');
		blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.setText(i18n._('Please add a token first'));
	} else {
github binary-com / binary-bot / src / newdesign / pages / bot / tools / index.js View on Github external
})
			.text('Add Token');
		$('#logout')
			.show();
		global.lists.accounts = [];
		tokenList.forEach(function (tokenInfo) {
			global.lists.accounts.push([tokenInfo.account_name, tokenInfo.token]);
		});
		var tokenInfoToAdd = tokenList[0];
		if (tokenToAdd !== undefined) {
			var tokenInfoIndex = storageManager.findToken(tokenToAdd);
			if (tokenInfoIndex >= 0) {
				tokenInfoToAdd = tokenList[tokenInfoIndex];
			}
		}
		if (blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.getValue() !== tokenInfoToAdd.token) {
			blockly.mainWorkspace.getBlockById('trade')
				.getField('ACCOUNT_LIST')
				.setValue(tokenInfoToAdd.token);
		}
		if (blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.getText() !== tokenInfoToAdd.account_name) {
			blockly.mainWorkspace.getBlockById('trade')
				.getField('ACCOUNT_LIST')
				.setText(tokenInfoToAdd.account_name);
		}
	}
};
github binary-com / binary-bot / src / newdesign / pages / bot / tools / index.js View on Github external
if (tokenList.length === 0) {
		$('#addAccount')
			.unbind('.addAccount')
			.bind('click.login', function(e){
				appId.redirectOauth();
			})
			.text('Login');
		$('#logout')
			.hide();
		global.lists.accounts = [
			[i18n._('Please add a token first'), '']
		];
		blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.setValue('');
		blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.setText(i18n._('Please add a token first'));
	} else {
		$('#addAccount')
			.unbind('.login')
			.bind('click.addAccount', function(e){
				addAccount();
			})
			.text('Add Token');
		$('#logout')
			.show();
		global.lists.accounts = [];
		tokenList.forEach(function (tokenInfo) {
			global.lists.accounts.push([tokenInfo.account_name, tokenInfo.token]);
		});
		var tokenInfoToAdd = tokenList[0];
github binary-com / binary-bot / src / newdesign / pages / bot / tools / index.js View on Github external
var updateTokenList = function updateTokenList(tokenToAdd) {
	var tokenList = storageManager.getTokenList();
	blockly.WidgetDiv.hideIfOwner(blockly.mainWorkspace.getBlockById('trade')
		.getField('ACCOUNT_LIST'));
	if (tokenList.length === 0) {
		$('#addAccount')
			.unbind('.addAccount')
			.bind('click.login', function(e){
				appId.redirectOauth();
			})
			.text('Login');
		$('#logout')
			.hide();
		global.lists.accounts = [
			[i18n._('Please add a token first'), '']
		];
		blockly.mainWorkspace.getBlockById('trade')
			.getField('ACCOUNT_LIST')
			.setValue('');