1
0

repeatNtimes.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 repeatNtimes created_element"> <i class="ui icon small sync"></i> <span> para (x = 0; x < 10; x ++) { } </span></div>');
  11. }
  12. export function renderCommand (command, function_obj) {
  13. var ret = '<div class="ui repeatNtimes command_container"> <i class="ui icon small random command_drag"></i> <i class="ui icon times red button_remove_command"></i> <span> para ( </span> ??? ; <div class="conditional_expression"></div> ; ??? ) { </span>';
  14. ret += '<div class="ui block_commands">';
  15. ret += '</div>';
  16. ret += '<span> }</span>';
  17. ret += '</div>';
  18. var el = $(ret);
  19. el.data('command', command);
  20. addHandlers(command, function_obj, el);
  21. ConditionalExpressionManagement.renderExpression(command, command.expression2, function_obj, el.find('.conditional_expression'));
  22. return el;
  23. }
  24. function addHandlers (command, function_obj, repeatNtimes_dom) {
  25. repeatNtimes_dom.find('.button_remove_command').on('click', function() {
  26. if (CommandsManagement.removeCommand(command, function_obj, repeatNtimes_dom)) {
  27. repeatNtimes_dom.remove();
  28. }
  29. });
  30. }