import $ from 'jquery'; import { Types } from '../types'; import * as Models from '../ivprog_elements'; import { LocalizedStrings } from '../../services/localizedStringsService'; import * as GlobalsManagement from '../globals'; import * as VariablesManagement from '../variables'; import * as CommandsManagement from '../commands'; import * as VariableValueMenu from './variable_value_menu'; import * as ContextualizedMenu from './contextualized_menu'; export function createFloatingCommand () { return $('
'+LocalizedStrings.getUI('text_code_switch')+' ( x ) {
'+LocalizedStrings.getUI('text_code_case')+' 1:
'+LocalizedStrings.getUI('text_code_case')+' 2:
}
'); } export function renderCommand (command, function_obj) { var ret = ''; ret += '
'+LocalizedStrings.getUI('text_code_switch')+' (
)
'; ret += '
'; var el = $(ret); el.data('command', command); addHandlers(command, function_obj, el); ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el); VariableValueMenu.renderMenu(command, command.variable, el.find('.variable_to_switch'), function_obj); if (command.cases) { for (var i = 0; i < command.cases.length; i++) { renderCase(command.cases[i], command, function_obj, el.find('.all_cases_div')); } } return el; } export function renderCase (switchcase, command, function_obj, el) { var casediv = $('
'+LocalizedStrings.getUI('text_code_case')+'
:
'); VariableValueMenu.renderMenu(command, switchcase.variable_value_menu, casediv.find('.variable_case'), function_obj); casediv.data('switchcase', switchcase); casediv.find('.case_commands_block').data('switchcase', switchcase); el.append(casediv); if (switchcase.commands_block) { for (var j = 0; j < switchcase.commands_block.length; j++) { CommandsManagement.renderCommand(switchcase.commands_block[j], $(casediv.find('.case_commands_block')[0]), 3, function_obj); } } casediv.find('.button_remove_command').on('click', function() { for (var i = 0; i < command.cases.length; i++) { if (switchcase == command.cases[i]) { delete command.cases[i]; command.cases.splice(i, 1); casediv.remove(); break; } } }); } function addHandlers (command, function_obj, switch_dom) { switch_dom.find('.button_remove_command').on('click', function() { if (CommandsManagement.removeCommand(command, function_obj, switch_dom)) { switch_dom.fadeOut(400, function() { switch_dom.remove(); }); } }); }