1
0

iftrue.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. export function createFloatingCommand () {
  10. return $('<div class="ui iftrue created_element"> <i class="ui icon small random"></i> <span> if (x < 1) { } </span></div>');
  11. }
  12. export function renderCommand (command, function_obj) {
  13. var ret = '';
  14. ret += '<div class="ui iftrue command_container"><div class="ui data_block_if" data-if="true"> <i class="ui icon small random command_drag"></i> <i class="ui icon times red button_remove_command"></i>';
  15. ret += '<span class="span_command_spec"> ' + LocalizedStrings.getUI('text_if') + '</span>';
  16. ret += ' <span class="span_command_spec"> ( </span> <div class="conditional_expression"></div> <span class="span_command_spec"> ) </span>';
  17. ret += '<span> </span> ';
  18. ret += '<div class="ui block_commands commands_if conditional_comands_block" data-if="true">';
  19. ret += '</div></div>';
  20. ret += '<div class="ui data_block_else" data-else="true"> <span class="span_command_spec"> ' + LocalizedStrings.getUI('text_else') + ' </span>';
  21. ret += '<div class="ui block_commands commands_else conditional_comands_block" data-else="true">';
  22. ret += '</div>';
  23. ret += '<span></span></div>';
  24. ret += '</div>';
  25. var el = $(ret);
  26. el.data('command', command);
  27. el.find('.block_commands').data('command', command);
  28. el.find('.data_block_if').data('command', command);
  29. el.find('.data_block_else').data('command', command);
  30. addHandlers(command, function_obj, el);
  31. ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
  32. if (command.commands_block) {
  33. for (var j = 0; j < command.commands_block.length; j++) {
  34. CommandsManagement.renderCommand(command.commands_block[j], $(el.find('.commands_if')[0]), 3, function_obj);
  35. }
  36. }
  37. if (command.commands_else) {
  38. for (var j = 0; j < command.commands_else.length; j++) {
  39. CommandsManagement.renderCommand(command.commands_else[j], $(el.find('.commands_else')[0]), 3, function_obj);
  40. }
  41. }
  42. return el;
  43. }
  44. function addHandlers (command, function_obj, iftrue_dom) {
  45. iftrue_dom.find('.button_remove_command').on('click', function() {
  46. if (CommandsManagement.removeCommand(command, function_obj, iftrue_dom)) {
  47. iftrue_dom.fadeOut();
  48. }
  49. });
  50. }