whiletrue.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { LocalizedStrings } from '../../services/localizedStringsService';
  2. import * as CommandsManagement from '../commands';
  3. import * as ConditionalExpressionManagement from './conditional_expression';
  4. import * as ContextualizedMenu from './contextualized_menu';
  5. export function createFloatingCommand () {
  6. return $('<div class="ui whiletrue created_element"> <i class="ui icon small sync"></i> <span> ' + LocalizedStrings.getUI('text_code_while') + ' ( x < 10 ) <br> </span></div>');
  7. }
  8. export function renderCommand (command, function_obj) {
  9. var ret = '';
  10. ret += '<div class="ui whiletrue 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_code_while') + ' </span>';
  11. ret += '<span class="span_command_spec"> ( </span> <div class="conditional_expression"></div> <span class="span_command_spec"> ) </span>';
  12. ret += ' </span>';
  13. ret += '<div class="ui block_commands">';
  14. ret += '</div>';
  15. ret += '<span> </span>';
  16. ret += '</div>';
  17. var el = $(ret);
  18. el.data('command', command);
  19. el.find('.block_commands').data('command', command);
  20. addHandlers(command, function_obj, el);
  21. ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
  22. ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
  23. if (command.commands_block) {
  24. for (var j = 0; j < command.commands_block.length; j++) {
  25. CommandsManagement.renderCommand(command.commands_block[j], $(el.find('.block_commands')[0]), 3, function_obj);
  26. }
  27. }
  28. return el;
  29. }
  30. function addHandlers (command, function_obj, whiletrue_dom) {
  31. whiletrue_dom.find('.button_remove_command').on('click', function() {
  32. if (CommandsManagement.removeCommand(command, function_obj, whiletrue_dom)) {
  33. whiletrue_dom.fadeOut(400, function() {
  34. whiletrue_dom.remove();
  35. });
  36. }
  37. });
  38. }