contextualized_menu.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import * as Models from '../ivprog_elements';
  2. import { LocalizedStrings } from '../../services/localizedStringsService';
  3. import * as CommandsManagement from '../commands';
  4. import * as VariableValueMenuManagement from './variable_value_menu';
  5. import * as SwitchManagement from './switch';
  6. export function renderMenu (command, dom_where_render, function_obj, dom_command) {
  7. var menu_div = '<div class="ui dropdown menu_commands pause" ><button><i class="icon code"></i></button> <div class="menu"> ';
  8. if ((command.type == Models.COMMAND_TYPES.repeatNtimes)
  9. || (command.type == Models.COMMAND_TYPES.whiletrue)
  10. || (command.type == Models.COMMAND_TYPES.dowhiletrue)) {
  11. menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.break+'"><i class="pause icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
  12. } else {
  13. menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.break+'"><i class="pause icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
  14. menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.switchcase+'"><i class="plus icon"></i> '+LocalizedStrings.getUI('btn_case')+' </a>';
  15. }
  16. menu_div += '</div></div>';
  17. menu_div = $(menu_div);
  18. dom_where_render.append(menu_div);
  19. addHandlers(command, dom_where_render, function_obj, dom_command);
  20. if (command.collapsed) {
  21. dom_command.children('.ui.block_commands').toggle();
  22. }
  23. }
  24. function addHandlers (command, dom_where_render, function_obj, dom_command) {
  25. dom_where_render.find('.menu_commands').dropdown({
  26. on: 'hover'
  27. });
  28. dom_where_render.find('.menu_commands a').on('click', function(evt){
  29. if ((command.type == Models.COMMAND_TYPES.repeatNtimes)
  30. || (command.type == Models.COMMAND_TYPES.whiletrue)
  31. || (command.type == Models.COMMAND_TYPES.dowhiletrue)) {
  32. if (command.commands_block == null || command.commands_block.length == 0) {
  33. command.commands_block = [];
  34. var new_cmd = CommandsManagement.genericCreateCommand($(this).data('command'));
  35. command.commands_block.push(new_cmd);
  36. CommandsManagement.renderCommand(new_cmd, dom_command.find('.block_commands'), 3, function_obj);
  37. } else {
  38. CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
  39. }
  40. } else {
  41. switch ($(this).data('command')) {
  42. case Models.COMMAND_TYPES.break:
  43. CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
  44. break;
  45. case Models.COMMAND_TYPES.switchcase:
  46. addCaseToSwitch(command, dom_where_render, function_obj, dom_command);
  47. break;
  48. }
  49. }
  50. });
  51. }
  52. function addCaseToSwitch (command, dom_where_render, function_obj, dom_command) {
  53. if ((command.cases == null)) {
  54. command.cases = [];
  55. }
  56. var sc = new Models.SwitchCase(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
  57. command.cases.push(sc);
  58. SwitchManagement.renderCase(sc, command, function_obj, dom_command.find('.all_cases_div'));
  59. }