1
0

attribution.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 VariableValueMenuManagement from './variable_value_menu';
  9. export function createFloatingCommand () {
  10. return $('<div class="ui attribution created_element"> <i class="ui icon small arrow left"></i> <span> x = 1 + 1 </span></div>');
  11. }
  12. export function renderCommand (command, function_obj) {
  13. var el = $('<div class="ui attribution"> <i class="ui icon small arrow left command_drag"></i> <div class="var_attributed"></div> <span class="text_attr_receives">'+LocalizedStrings.getUI('text_receives')+'</span> '
  14. + '<div class="expression_operand_1"></div> </div>');
  15. $(el).data('command', command);
  16. VariableValueMenu.renderMenu(command, command.variable, $(el).find('.var_attributed'), function_obj);
  17. VariableValueMenu.renderMenu(command, command.expression, $(el).find('.expression_operand_1'), function_obj);
  18. return el;
  19. }
  20. export function renderMenuOperations (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected) {
  21. if ($(dom_object).hasClass('var_attributed')) {
  22. return;
  23. }
  24. $(dom_object).find('.context_menu_clear').remove();
  25. var menu_operations = '<div class="ui dropdown menu_operations"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  26. for (var tm in Models.ARITHMETIC_TYPES) {
  27. menu_operations += '<div class="item" data-option="'+tm+'">'+LocalizedStrings.getUI('btn_arithmetic_' + tm)+'</div>';
  28. }
  29. menu_operations += '<div class="item" data-option="clear">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  30. menu_operations += '</div></div>';
  31. menu_operations = $(menu_operations);
  32. $(dom_object).append(menu_operations);
  33. $(menu_operations).dropdown({
  34. onChange: function(value, text, $selectedItem) {
  35. switch ($($selectedItem).data('option')) {
  36. case "clear":
  37. $(dom_object).text('');
  38. VariableValueMenu.renderMenu(command, ref_object, dom_object, function_obj);
  39. break;
  40. default:
  41. createExpressionAround(command, ref_object, dom_object, function_obj);
  42. $(menu_operations).find('.text').text('');
  43. }
  44. }
  45. });
  46. }
  47. function createExpressionAround (command, ref_object, dom_object, function_obj) {
  48. $('<span> ( </span>').insertBefore(dom_object);
  49. $('<span> ) </span>').insertAfter(dom_object);
  50. VariableValueMenu.renderMenu(command, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true), dom_object, function_obj);
  51. }