return.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Types } from '../types';
  2. import { LocalizedStrings } from '../../services/localizedStringsService';
  3. import * as VariableValueMenu from './variable_value_menu';
  4. import * as CommandsManagement from '../commands';
  5. import * as GenericExpressionManagement from './generic_expression';
  6. import * as Models from '../ivprog_elements';
  7. export function createFloatingCommand () {
  8. return $('<div class="ui return created_element"> <i class="ui icon small reply"></i> <span> '+LocalizedStrings.getUI('text_return')+' </span></div>');
  9. }
  10. export function renderCommand (command, function_obj) {
  11. var el = $('<div class="ui return command_container"> <i class="ui icon small reply command_drag"></i> <i class="ui icon times red button_remove_command"></i> <span class="span_command_spec"> '+LocalizedStrings.getUI('text_return')+' </span> <div class="expression_elements"></div></div>');
  12. el.data('command', command);
  13. addHandlers(command, function_obj, el);
  14. if (function_obj.return_type != Types.VOID) {
  15. if (!command.variable_value_menu) {
  16. command.variable_value_menu = [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)];
  17. }
  18. GenericExpressionManagement.renderExpression(command, function_obj, el.find('.expression_elements'), command.variable_value_menu);
  19. } else {
  20. el.find('.expression_elements').remove();
  21. command.variable_value_menu = null;
  22. }
  23. return el;
  24. }
  25. function addHandlers (command, function_obj, return_dom) {
  26. return_dom.find('.button_remove_command').on('click', function() {
  27. if (CommandsManagement.removeCommand(command, function_obj, return_dom)) {
  28. return_dom.fadeOut(400, function() {
  29. return_dom.remove();
  30. });
  31. }
  32. });
  33. }