1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { LocalizedStrings } from '../../services/localizedStringsService';
- import * as CommandsManagement from '../commands';
- import * as ConditionalExpressionManagement from './conditional_expression';
- import * as ContextualizedMenu from './contextualized_menu';
- import * as GenericExpressionManagement from './generic_expression';
- import * as CodeGenerator from '../code_generator';
- export function createFloatingCommand () {
- return $('<div class="ui whiletrue created_element"> <i class="ui icon small sync"></i> <span> ' + LocalizedStrings.getUI('text_command_while') + ' ( x < 10 ) <br> </span></div>');
- }
- export function renderCommand (command, function_obj) {
- var ret = '';
- ret += '<div class="ui whiletrue command_container"> <i class="ui icon small sync command_drag"></i> <i class="ui icon times red button_remove_command"></i><button class="ui icon button minimize_block_button tiny"><i class="icon window minimize"></i></button> <span class="span_command_spec"> ' + LocalizedStrings.getUI('text_command_while') + ' </span>';
- ret += '<span class="span_command_spec"> ( </span> <div class="conditional_expression"></div> <span class="textual_expression"></span> <span class="span_command_spec"> ) </span>';
- ret += ' </span>';
- ret += '<i class="ui icon unlock button_alternate_expression"></i> <div class="ui context_menu"></div>';
- ret += '<div class="ui block_commands">';
- ret += '</div>';
- ret += '<span> </span>';
- ret += '</div>';
- var el = $(ret);
- el.data('command', command);
- el.find('.block_commands').data('command', command);
- addHandlers(command, function_obj, el);
- ContextualizedMenu.renderMenu(command, el.find('.context_menu'), 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('.block_commands')[0]), 3, function_obj);
- }
- }
- 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, whiletrue_dom) {
- whiletrue_dom.find('.minimize_block_button').on('click', function(evt){
- whiletrue_dom.children('.ui.block_commands').toggle();
- command.collapsed = !command.collapsed;
- });
- $(whiletrue_dom.find('.textual_expression')[0]).toggle();
-
- whiletrue_dom.find('.button_alternate_expression').on('click', function() {
- if (command.expression) {
- var text = CodeGenerator.elementExpressionCode(command.expression);
- if (text) {
- $(whiletrue_dom.find('.conditional_expression')[0]).toggle();
- $(whiletrue_dom.find('.textual_expression')[0]).text(text);
- $(whiletrue_dom.find('.textual_expression')[0]).toggle();
- $(this).toggleClass('unlock').toggleClass('lock');
- command.lockexpression = !command.lockexpression;
- }
- }
- });
- whiletrue_dom.find('.button_remove_command').on('click', function() {
- if (CommandsManagement.removeCommand(command, function_obj, whiletrue_dom)) {
- whiletrue_dom.fadeOut(400, function() {
- whiletrue_dom.remove();
- });
- }
- });
- }
|