iftrue.js 2.6 KB

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