123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import $ from 'jquery';
- import { Types } from '../types';
- import * as Models from '../ivprog_elements';
- import { LocalizedStrings } from '../../services/localizedStringsService';
- import * as CommandsManagement from '../commands';
- import * as VariableValueMenuManagement from './variable_value_menu';
- import * as SwitchManagement from './switch';
- import * as RepeatNTimesManagement from './repeatNtimes';
- export function renderMenu (command, dom_where_render, function_obj, dom_command) {
- var menu_div = '<div class="ui dropdown menu_commands" ><i class="icon code"></i> <div class="menu"> ';
- if ((command.type == Models.COMMAND_TYPES.repeatNtimes)
- || (command.type == Models.COMMAND_TYPES.whiletrue)
- || (command.type == Models.COMMAND_TYPES.dowhiletrue)) {
- menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.break+'"><i class="download icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
- } else {
- menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.break+'"><i class="download icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
- menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.switchcase+'"><i class="download icon"></i> '+LocalizedStrings.getUI('btn_case')+' </a>';
- }
- menu_div += '</div></div>';
- menu_div = $(menu_div);
-
- dom_where_render.append(menu_div);
- addHandlers(command, dom_where_render, function_obj, dom_command);
- }
- function addHandlers (command, dom_where_render, function_obj, dom_command) {
- console.log('command, dom_where_render, function_obj, dom_command');
- console.log(command, dom_where_render, function_obj, dom_command);
- console.log(dom_where_render.parents());
- dom_where_render.find('.menu_commands').dropdown({
- on: 'hover'
- });
-
- dom_where_render.find('.menu_commands a').on('click', function(evt){
- if ((command.type == Models.COMMAND_TYPES.repeatNtimes)
- || (command.type == Models.COMMAND_TYPES.whiletrue)
- || (command.type == Models.COMMAND_TYPES.dowhiletrue)) {
- if (command.commands_block == null || command.commands_block.length == 0) {
- command.commands_block = [];
- var new_cmd = CommandsManagement.genericCreateCommand($(this).data('command'));
- command.commands_block.push(new_cmd);
- CommandsManagement.renderCommand(new_cmd, dom_command.find('.block_commands'), 3, function_obj);
- } else {
- CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
- }
- } else {
- switch ($(this).data('command')) {
- case Models.COMMAND_TYPES.break:
- CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
- break;
- case Models.COMMAND_TYPES.switchcase:
- addCaseToSwitch(command, dom_where_render, function_obj, dom_command);
- break;
- }
- }
- });
- }
- function addCaseToSwitch (command, dom_where_render, function_obj, dom_command) {
-
- if ((command.cases == null)) {
- command.cases = [];
- }
-
- var sc = new Models.SwitchCase(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
- command.cases.push(sc);
- SwitchManagement.renderCase(sc, command, function_obj, dom_command.find('.all_cases_div'));
- }
|