whiletrue.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. export function createFloatingCommand () {
  11. return $('<div class="ui whiletrue created_element"> <i class="ui icon small sync"></i> <span> ' + LocalizedStrings.getUI('text_code_while') + ' ( x < 10 ) { } </span></div>');
  12. }
  13. export function renderCommand (command, function_obj) {
  14. var ret = '';
  15. ret += '<div class="ui whiletrue command_container"> <i class="ui icon small random command_drag"></i> <i class="ui icon times red button_remove_command"></i> <div class="ui context_menu"></div> <span> ' + LocalizedStrings.getUI('text_code_while') + ' </span>';
  16. ret += ' <div class="conditional_expression"></div>';
  17. ret += ' { </span>';
  18. ret += '<div class="ui block_commands">';
  19. ret += '</div>';
  20. ret += '<span> }</span>';
  21. ret += '</div>';
  22. var el = $(ret);
  23. el.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. return el;
  28. }
  29. function addHandlers (command, function_obj, whiletrue_dom) {
  30. whiletrue_dom.find('.button_remove_command').on('click', function() {
  31. if (CommandsManagement.removeCommand(command, function_obj, whiletrue_dom)) {
  32. whiletrue_dom.remove();
  33. }
  34. });
  35. }