return.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. export function createFloatingCommand () {
  7. return $('<div class="ui return created_element"> <i class="ui icon small reply"></i> <span> '+LocalizedStrings.getUI('text_return')+' </span></div>');
  8. }
  9. export function renderCommand (command, function_obj) {
  10. 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>');
  11. el.data('command', command);
  12. addHandlers(command, function_obj, el);
  13. if (function_obj.return_type != Types.VOID) {
  14. //VariableValueMenu.renderMenu(command, command.variable_value_menu, el.find('.var_value_menu_div'), function_obj);
  15. GenericExpressionManagement.renderExpression(command, function_obj, el.find('.expression_elements'), command.variable_value_menu);
  16. } else {
  17. el.find('.expression_elements').remove();
  18. command.variable_value_menu = null;
  19. }
  20. return el;
  21. }
  22. function addHandlers (command, function_obj, return_dom) {
  23. return_dom.find('.button_remove_command').on('click', function() {
  24. if (CommandsManagement.removeCommand(command, function_obj, return_dom)) {
  25. return_dom.fadeOut(400, function() {
  26. return_dom.remove();
  27. });
  28. }
  29. });
  30. }