dowhiletrue.js 1.6 KB

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