iftrue.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. export function createFloatingCommand () {
  9. return $('<div class="ui iftrue created_element"> <i class="ui icon small random"></i> <span> if (x < 1) { } </span></div>');
  10. }
  11. export function renderCommand (command, function_obj) {
  12. var ret = '';
  13. ret += '<div class="ui iftrue command_container"> <i class="ui icon small random command_drag"></i> <i class="ui icon times red button_remove_command"></i> <span> if (x < 1) { </span>';
  14. ret += '<div class="ui block_commands" data-if="true">';
  15. /*if ((writer_obj.commands_block == null)
  16. || (writer_obj.commands_block.length == 0)) {
  17. } else {
  18. for (ki = 0; ki < writer_obj.commands_block.length; ki ++) {
  19. ret += renderElementCommandGeneric(writer_obj.commands_block[ki], function_index, ki, iftrue_index, (fullpath + ',' + ki));
  20. }
  21. }*/
  22. ret += '</div>';
  23. ret += '<span> } else { </span>';
  24. ret += '<div class="ui block_commands" data-else="true">';
  25. /*if ((writer_obj.commands_else == null)
  26. || (writer_obj.commands_else.length == 0)) {
  27. } else {
  28. for (ki = 0; ki < writer_obj.commands_else.length; ki ++) {
  29. ret += renderElementCommandGeneric(writer_obj.commands_else[ki], function_index, ki, iftrue_index, (fullpath + ',' + ki));
  30. }
  31. }*/
  32. ret += '</div>';
  33. ret += '<span> }</span>';
  34. ret += '</div>';
  35. var el = $(ret);
  36. el.data('command', command);
  37. addHandlers(command, function_obj, el);
  38. return el;
  39. }
  40. function addHandlers (command, function_obj, iftrue_dom) {
  41. iftrue_dom.find('.button_remove_command').on('click', function() {
  42. if (CommandsManagement.removeCommand(command, function_obj, iftrue_dom)) {
  43. iftrue_dom.remove();
  44. }
  45. });
  46. }