dowhiletrue.js 2.3 KB

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