dowhiletrue.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 dowhiletrue created_element"> <i class="ui icon small sync"></i> <span> faça {<br>} enquanto(x < 10) </span></div>');
  12. }
  13. export function renderCommand (command, function_obj) {
  14. var ret = '';
  15. ret += '<div class="ui dowhiletrue 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_do') + ' { </span>';
  16. ret += '<div class="ui block_commands" data-subblock="" data-idcommand="">';
  17. ret += '</div>';
  18. ret += '<span> } ' + LocalizedStrings.getUI('text_code_while') + ' </span> <div class="conditional_expression"></div>';
  19. ret += '</div>';
  20. var el = $(ret);
  21. el.data('command', command);
  22. addHandlers(command, function_obj, el);
  23. ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
  24. ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
  25. return el;
  26. }
  27. function addHandlers (command, function_obj, dowhiletrue_dom) {
  28. dowhiletrue_dom.find('.button_remove_command').on('click', function() {
  29. if (CommandsManagement.removeCommand(command, function_obj, dowhiletrue_dom)) {
  30. dowhiletrue_dom.remove();
  31. }
  32. });
  33. }