contextualized_menu.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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" ><i class="icon code"></i> <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="download icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
  12. } else {
  13. menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.break+'"><i class="download icon"></i> '+LocalizedStrings.getUI('btn_break')+' </a>';
  14. menu_div += '<a class="item" data-command="'+Models.COMMAND_TYPES.switchcase+'"><i class="download 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. }
  21. function addHandlers (command, dom_where_render, function_obj, dom_command) {
  22. dom_where_render.find('.menu_commands').dropdown({
  23. on: 'hover'
  24. });
  25. dom_where_render.find('.menu_commands a').on('click', function(evt){
  26. if ((command.type == Models.COMMAND_TYPES.repeatNtimes)
  27. || (command.type == Models.COMMAND_TYPES.whiletrue)
  28. || (command.type == Models.COMMAND_TYPES.dowhiletrue)) {
  29. if (command.commands_block == null || command.commands_block.length == 0) {
  30. command.commands_block = [];
  31. var new_cmd = CommandsManagement.genericCreateCommand($(this).data('command'));
  32. command.commands_block.push(new_cmd);
  33. CommandsManagement.renderCommand(new_cmd, dom_command.find('.block_commands'), 3, function_obj);
  34. } else {
  35. CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
  36. }
  37. } else {
  38. switch ($(this).data('command')) {
  39. case Models.COMMAND_TYPES.break:
  40. CommandsManagement.createFloatingCommand(function_obj, dom_command.find('.block_commands'), $(this).data('command'), evt);
  41. break;
  42. case Models.COMMAND_TYPES.switchcase:
  43. addCaseToSwitch(command, dom_where_render, function_obj, dom_command);
  44. break;
  45. }
  46. }
  47. });
  48. }
  49. function addCaseToSwitch (command, dom_where_render, function_obj, dom_command) {
  50. if ((command.cases == null)) {
  51. command.cases = [];
  52. }
  53. var sc = new Models.SwitchCase(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
  54. command.cases.push(sc);
  55. SwitchManagement.renderCase(sc, command, function_obj, dom_command.find('.all_cases_div'));
  56. }