dowhiletrue.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 GlobalsManagement from '../globals';
  6. import * as VariablesManagement from '../variables';
  7. import * as CommandsManagement from '../commands';
  8. import * as ConditionalExpressionManagement from './conditional_expression';
  9. import * as ContextualizedMenu from './contextualized_menu';
  10. import * as GenericExpressionManagement from './generic_expression';
  11. export function createFloatingCommand () {
  12. return $('<div class="ui dowhiletrue created_element"> <i class="ui icon small sync"></i> <span> '+ LocalizedStrings.getUI('text_command_do') +' <br> ' + LocalizedStrings.getUI('text_code_while') +'(x < 10) </span></div>');
  13. }
  14. export function renderCommand (command, function_obj) {
  15. var ret = '';
  16. ret += '<div class="ui dowhiletrue command_container"> <i class="ui icon small sync command_drag"></i> <i class="ui icon times red button_remove_command"></i> <div class="ui context_menu"></div> <span class="span_command_spec"> ' + LocalizedStrings.getUI('text_command_do') + ' </span>';
  17. ret += '<div class="ui block_commands" data-subblock="" data-idcommand="">';
  18. ret += '</div>';
  19. ret += ' <span class="span_command_spec"> ' + LocalizedStrings.getUI('text_code_while') + ' </span> <span class="span_command_spec"> ( </span> <div class="conditional_expression"></div> <span class="span_command_spec"> ) </span>';
  20. ret += '</div>';
  21. var el = $(ret);
  22. el.data('command', command);
  23. el.find('.block_commands').data('command', command);
  24. addHandlers(command, function_obj, el);
  25. ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
  26. //ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
  27. if (command.expression) {
  28. GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression);
  29. }
  30. if (command.commands_block) {
  31. for (var j = 0; j < command.commands_block.length; j++) {
  32. CommandsManagement.renderCommand(command.commands_block[j], $(el.find('.block_commands')[0]), 3, function_obj);
  33. }
  34. }
  35. return el;
  36. }
  37. function addHandlers (command, function_obj, dowhiletrue_dom) {
  38. dowhiletrue_dom.find('.button_remove_command').on('click', function() {
  39. if (CommandsManagement.removeCommand(command, function_obj, dowhiletrue_dom)) {
  40. dowhiletrue_dom.fadeOut(400, function() {
  41. dowhiletrue_dom.remove();
  42. });
  43. }
  44. });
  45. }