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