import { LocalizedStrings } from '../../services/localizedStringsService'; import * as CommandsManagement from '../commands'; import * as GenericExpressionManagement from './generic_expression'; import * as CodeGenerator from '../code_generator'; export function createFloatingCommand () { return $('
if (x < 1) { }
'); } export function renderCommand (command, function_obj) { var ret = ''; ret += '
'; ret += ' ' + LocalizedStrings.getUI('text_if') + ''; ret += ' (
) '; ret += ''; ret += ' '; ret += '
'; ret += '
'; ret += '
' + LocalizedStrings.getUI('text_else') + ' '; ret += '
'; ret += '
'; ret += '
'; ret += '
'; var el = $(ret); el.data('command', command); el.find('.block_commands').data('command', command); el.find('.data_block_if').data('command', command); el.find('.data_block_else').data('command', command); el.find('.commands_if').data('command', command); addHandlers(command, function_obj, el); //ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression')); GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression); if (command.commands_block) { for (var j = 0; j < command.commands_block.length; j++) { CommandsManagement.renderCommand(command.commands_block[j], $(el.find('.commands_if')[0]), 3, function_obj); } } if (command.commands_else) { for (var j = 0; j < command.commands_else.length; j++) { CommandsManagement.renderCommand(command.commands_else[j], $(el.find('.commands_else')[0]), 3, function_obj); } } if (command.collapsed) { el.children('.data_block_else').toggle(); $(el.find('.block_commands')[0]).toggle(); } if (command.lockexpression) { if (command.expression) { try { var text = CodeGenerator.elementExpressionCode(command.expression); if (text) { $(el.find('.conditional_expression')[0]).toggle(); $(el.find('.textual_expression')[0]).text(text); $(el.find('.textual_expression')[0]).toggle(); $(el.find('.button_alternate_expression')[0]).toggleClass('unlock').toggleClass('lock'); } } catch (e) { command.lockexpression = false; } } } return el; } function addHandlers (command, function_obj, iftrue_dom) { $(iftrue_dom.find('.textual_expression')[0]).toggle(); iftrue_dom.find('.button_alternate_expression').on('click', function() { if (command.expression) { var text = CodeGenerator.elementExpressionCode(command.expression); if (text) { $(iftrue_dom.find('.conditional_expression')[0]).toggle(); $(iftrue_dom.find('.textual_expression')[0]).text(text); $(iftrue_dom.find('.textual_expression')[0]).toggle(); $(this).toggleClass('unlock').toggleClass('lock'); command.lockexpression = !command.lockexpression; } } }); iftrue_dom.find('.button_remove_command').on('click', function() { if (CommandsManagement.removeCommand(command, function_obj, iftrue_dom)) { iftrue_dom.fadeOut(400, function() { iftrue_dom.remove(); }); } }); iftrue_dom.find('.minimize_block_button').on('click', function() { iftrue_dom.children('.data_block_else').toggle(); $(iftrue_dom.find('.block_commands')[0]).toggle(); command.collapsed = !command.collapsed; }); }