contextualized_menu.js 3.2 KB

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