variable_value_menu.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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 AttribuitionsManagement from './attribution';
  8. import * as WritersManagement from './writer';
  9. import * as RepeatNTimesManagement from './repeatNtimes';
  10. export const VAR_OR_VALUE_TYPES = Object.freeze({only_variable: 1, only_value: 2, only_function: 3, variable_and_function: 4, variable_and_value_opt: 5,
  11. value_and_function: 6, all: 7});
  12. export function renderMenu (command, ref_object, dom_object, function_obj, size_field = 2, expression_element) {
  13. var menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom" data-algo="12"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  14. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_variable) {
  15. menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom"><div class="text"></div><i class="dropdown icon"></i><div class="menu menu_only_vars">';
  16. menu_var_or_value += '</div>';
  17. }
  18. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_value_opt) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  19. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('variable');
  20. menu_var_or_value += '<div class="menu menu_only_vars">';
  21. menu_var_or_value += '</div></div>';
  22. }
  23. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_value) {
  24. menu_var_or_value = '<input type="text" class="width-dynamic" size="'+size_field+'" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />';
  25. }
  26. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_value_opt)
  27. || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  28. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_value+'">'+LocalizedStrings.getUI('text_value')+'</div>';
  29. }
  30. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_function) {
  31. menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom"><div class="text"></div><i class="dropdown icon"></i><div class="menu menu_only_functions">';
  32. menu_var_or_value += '</div>';
  33. }
  34. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function)
  35. || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  36. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_function+'"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('btn_function');
  37. menu_var_or_value += '<div class="menu menu_only_functions">';
  38. menu_var_or_value += '</div></div>';
  39. if (command.type == Models.COMMAND_TYPES.attribution) {
  40. menu_var_or_value += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  41. menu_var_or_value += '<div class="menu">';
  42. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  43. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  44. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  45. menu_var_or_value += '</div></div>';
  46. }
  47. }
  48. menu_var_or_value += '</div></div>';
  49. menu_var_or_value = $(menu_var_or_value);
  50. dom_object.append(menu_var_or_value);
  51. addHandlers(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  52. addVariablesToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  53. addFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  54. addIVProgFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  55. if (ref_object.content || ref_object.function_called) {
  56. // Verificar se a variável ainda existe:
  57. if (isVarInProgram(ref_object.content, function_obj)) {
  58. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  59. } else {
  60. if (ref_object.content && ref_object.content.type) {
  61. ref_object.content = null;
  62. appendSelectText(ref_object, menu_var_or_value);
  63. } else {
  64. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  65. }
  66. }
  67. } else {
  68. appendSelectText(ref_object, menu_var_or_value);
  69. }
  70. }
  71. function appendSelectText (ref_object, menu_var_or_value) {
  72. switch(ref_object.variable_and_value) {
  73. case VAR_OR_VALUE_TYPES.only_variable:
  74. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_var')+'</i>');
  75. break;
  76. case VAR_OR_VALUE_TYPES.all:
  77. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_all')+'</i>');
  78. break;
  79. case VAR_OR_VALUE_TYPES.variable_and_function:
  80. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_all')+'</i>');
  81. break;
  82. case VAR_OR_VALUE_TYPES.only_function:
  83. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_function')+'</i>');
  84. break;
  85. }
  86. }
  87. function isVarInProgram (var_obj, function_obj) {
  88. // Verify in globals:
  89. if (window.program_obj.globals) {
  90. for (var i = 0; i < window.program_obj.globals.length; i++) {
  91. if (window.program_obj.globals[i] == var_obj) {
  92. return true;
  93. }
  94. }
  95. }
  96. // Verify in locals:
  97. if (function_obj.variables_list) {
  98. for (var i = 0; i < function_obj.variables_list.length; i++) {
  99. if (function_obj.variables_list[i] == var_obj) {
  100. return true;
  101. }
  102. }
  103. }
  104. // Verify in parameters:
  105. if (function_obj.parameters_list) {
  106. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  107. if (function_obj.parameters_list[i] == var_obj) {
  108. return true;
  109. }
  110. }
  111. }
  112. return false;
  113. }
  114. export function refreshMenu (menu_var_or_value_dom) {
  115. console.log('\n\n');
  116. console.log(menu_var_or_value_dom);
  117. console.log("olá, fui chamado! note alguns DATAS recuperados: ");
  118. console.log(menu_var_or_value_dom.data());
  119. console.log('\n\n\n');
  120. }
  121. function renderPreviousContent (function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element) {
  122. if (ref_object.function_called) {
  123. menu_var_or_value.remove();
  124. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  125. } else if (ref_object.content.type) {
  126. menu_var_or_value.remove();
  127. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  128. } else {
  129. menu_var_or_value.remove();
  130. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  131. }
  132. }
  133. function variableValueMenuCode (command, variable_obj, dom_object, function_obj, menu_var_or_value, expression_element) {
  134. if (variable_obj.content || variable_obj.function_called) {
  135. // Verificar se a variável ainda existe:
  136. if (isVarInProgram(variable_obj.content, function_obj)) {
  137. } else {
  138. if (variable_obj.content && variable_obj.content.type) {
  139. variable_obj.content = null;
  140. appendSelectText(variable_obj, menu_var_or_value);
  141. }
  142. }
  143. } else {
  144. appendSelectText(variable_obj, menu_var_or_value);
  145. }
  146. if (variable_obj.content == null && variable_obj.function_called == null) {
  147. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  148. return;
  149. }
  150. var ret = '';
  151. if (variable_obj.function_called) {
  152. if (variable_obj.function_called.parameters_list == null || variable_obj.function_called.length == 0) {
  153. menu_var_or_value.find('.text').text(' ');
  154. dom_object.find('.menu_var_or_value_dom').remove();
  155. var parameters_menu;
  156. if (variable_obj.function_called.name) {
  157. parameters_menu = '<div class="parameters_function_called"> '+variable_obj.function_called.name+' <span> ( </span>';
  158. } else {
  159. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.getUI(variable_obj.function_called.category)+'.'+LocalizedStrings.getUI(variable_obj.function_called.identifier)+'</i> <span> ( </span>';
  160. }
  161. parameters_menu += '<span> ) </span></div>';
  162. parameters_menu = $(parameters_menu);
  163. dom_object.append(parameters_menu);
  164. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  165. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  166. if (command.type == Models.COMMAND_TYPES.attribution) {
  167. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  168. context_menu += '<div class="menu">';
  169. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  170. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  171. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  172. context_menu += '</div></div>';
  173. }
  174. context_menu += '</div></div>';
  175. context_menu = $(context_menu);
  176. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  177. context_menu.dropdown({
  178. onChange: function(value, text, $selectedItem) {
  179. console.log('S1');
  180. if ($selectedItem.data('clear')) {
  181. console.log('PP1');
  182. dom_object.text('');
  183. variable_obj.content = null;
  184. variable_obj.row = null;
  185. variable_obj.column = null;
  186. delete variable_obj.function_called;
  187. delete variable_obj.parameters_list;
  188. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  189. }
  190. if ($selectedItem.data('exp')) {
  191. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  192. }
  193. }
  194. });
  195. } else {
  196. menu_var_or_value.find('.text').text(' ');
  197. dom_object.find('.menu_var_or_value_dom').remove();
  198. var parameters_menu;
  199. if (variable_obj.function_called.name) {
  200. parameters_menu = '<div class="parameters_function_called"> '+variable_obj.function_called.name+' <span> ( </span>';
  201. } else {
  202. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.getUI(variable_obj.function_called.category)+'.'+LocalizedStrings.getUI(variable_obj.function_called.identifier)+'</i> <span> ( </span>';
  203. }
  204. for (var j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  205. parameters_menu += '<div class="render_style_param parameter_'+j+'"></div>';
  206. if ((j + 1) != variable_obj.function_called.parameters_list.length) {
  207. parameters_menu += ' , ';
  208. }
  209. }
  210. parameters_menu += '<span> ) </span></div>';
  211. parameters_menu = $(parameters_menu);
  212. dom_object.append(parameters_menu);
  213. for (var j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  214. renderMenu(command, variable_obj.parameters_list[j], parameters_menu.find('.parameter_'+j), function_obj, 2, expression_element);
  215. }
  216. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  217. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  218. if (command.type == Models.COMMAND_TYPES.attribution) {
  219. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  220. context_menu += '<div class="menu">';
  221. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  222. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  223. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  224. context_menu += '</div></div>';
  225. }
  226. context_menu += '</div></div>';
  227. context_menu = $(context_menu);
  228. context_menu.insertAfter( parameters_menu );
  229. context_menu.dropdown({
  230. onChange: function(value, text, $selectedItem) {
  231. console.log('S2');
  232. if ($selectedItem.data('clear')) {
  233. console.log('PP2');
  234. dom_object.text('');
  235. variable_obj.content = null;
  236. variable_obj.row = null;
  237. variable_obj.column = null;
  238. delete variable_obj.function_called;
  239. delete variable_obj.parameters_list;
  240. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  241. }
  242. if ($selectedItem.data('exp')) {
  243. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  244. }
  245. }
  246. });
  247. }
  248. } else if (variable_obj.content.type) {
  249. var variable_render = "";
  250. if (variable_obj.content.dimensions == 1) {
  251. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  252. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  253. variable_render += '</div>';
  254. variable_render = $(variable_render);
  255. dom_object.append(variable_render);
  256. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  257. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  258. if (command.type == Models.COMMAND_TYPES.attribution) {
  259. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  260. context_menu += '<div class="menu">';
  261. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  262. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  263. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  264. context_menu += '</div></div>';
  265. }
  266. context_menu += '</div></div>';
  267. context_menu = $(context_menu);
  268. variable_render.append(context_menu);
  269. context_menu.dropdown({
  270. onChange: function(value, text, $selectedItem) {
  271. console.log('S3');
  272. if ($selectedItem.data('clear')) {
  273. console.log('PP3');
  274. dom_object.text('');
  275. variable_obj.content = null;
  276. variable_obj.row = null;
  277. variable_obj.column = null;
  278. delete variable_obj.function_called;
  279. delete variable_obj.parameters_list;
  280. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  281. }
  282. if ($selectedItem.data('exp')) {
  283. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  284. }
  285. }
  286. });
  287. if (!variable_obj.column) {
  288. variable_obj.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  289. }
  290. variableValueMenuCode(command, variable_obj.column, $(variable_render.find('.column_container')), function_obj, menu_var_or_value, expression_element);
  291. } else if (variable_obj.content.dimensions == 2) {
  292. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  293. variable_render += ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  294. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  295. variable_render += '</div>';
  296. variable_render = $(variable_render);
  297. dom_object.append(variable_render);
  298. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  299. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  300. if (command.type == Models.COMMAND_TYPES.attribution) {
  301. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  302. context_menu += '<div class="menu">';
  303. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  304. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  305. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  306. context_menu += '</div></div>';
  307. }
  308. context_menu += '</div></div>';
  309. context_menu = $(context_menu);
  310. variable_render.append(context_menu);
  311. context_menu.dropdown({
  312. onChange: function(value, text, $selectedItem) {
  313. console.log('S4');
  314. if ($selectedItem.data('clear')) {
  315. console.log('PP4');
  316. dom_object.text('');
  317. variable_obj.content = null;
  318. variable_obj.row = null;
  319. variable_obj.column = null;
  320. delete variable_obj.function_called;
  321. delete variable_obj.parameters_list;
  322. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  323. }
  324. if ($selectedItem.data('exp')) {
  325. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  326. }
  327. }
  328. });
  329. if (!variable_obj.column) {
  330. variable_obj.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  331. }
  332. if (!variable_obj.row) {
  333. variable_obj.row = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  334. }
  335. variableValueMenuCode(command, variable_obj.row, $(variable_render.find('.row_container')), function_obj, menu_var_or_value, expression_element);
  336. variableValueMenuCode(command, variable_obj.column, $(variable_render.find('.column_container')), function_obj, menu_var_or_value, expression_element);
  337. } else {
  338. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  339. variable_render += '</div>';
  340. variable_render = $(variable_render);
  341. dom_object.append(variable_render);
  342. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  343. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  344. if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  345. console.log('dom_object6');
  346. console.log(dom_object);
  347. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  348. context_menu += '<div class="menu">';
  349. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  350. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  351. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  352. context_menu += '</div></div>';
  353. }
  354. context_menu += '</div></div>';
  355. context_menu = $(context_menu);
  356. variable_render.append(context_menu);
  357. context_menu.dropdown({
  358. onChange: function(value, text, $selectedItem) {
  359. console.log('S5');
  360. if ($selectedItem.data('clear')) {
  361. console.log('PP5');
  362. dom_object.text('');
  363. variable_obj.content = null;
  364. variable_obj.row = null;
  365. variable_obj.column = null;
  366. delete variable_obj.function_called;
  367. delete variable_obj.parameters_list;
  368. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  369. }
  370. if ($selectedItem.data('exp')) {
  371. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  372. }
  373. }
  374. });
  375. }
  376. } else {
  377. var variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content+'</span>';
  378. variable_render += '</div>';
  379. variable_render = $(variable_render);
  380. dom_object.append(variable_render);
  381. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  382. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  383. if (command.type == Models.COMMAND_TYPES.attribution) {
  384. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  385. context_menu += '<div class="menu">';
  386. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  387. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  388. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  389. context_menu += '</div></div>';
  390. }
  391. context_menu += '</div></div>';
  392. context_menu = $(context_menu);
  393. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  394. context_menu.insertAfter( variable_render );
  395. }
  396. context_menu.dropdown({
  397. onChange: function(value, text, $selectedItem) {
  398. console.log('S6');
  399. if ($selectedItem.data('clear')) {
  400. console.log('PP6');
  401. dom_object.text('');
  402. variable_obj.content = null;
  403. variable_obj.row = null;
  404. variable_obj.column = null;
  405. delete variable_obj.function_called;
  406. delete variable_obj.parameters_list;
  407. dom_object.find('.value_rendered').remove();
  408. dom_object.find('.context_menu_clear').remove();
  409. dom_object.find('.width-dynamic-minus').remove();
  410. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  411. }
  412. if ($selectedItem.data('exp')) {
  413. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  414. }
  415. }
  416. });
  417. variable_render.on('click', function(e) {
  418. variable_render.remove();
  419. variable_render.empty();
  420. variable_render.remove();
  421. dom_object.empty();
  422. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  423. openInputToValue(command, variable_obj, dom_object, menu_var_or_value, function_obj, expression_element);
  424. });
  425. }
  426. }
  427. function addIVProgFunctionsToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  428. var sub_menu = menu_var_or_value.find('.menu_only_functions');
  429. sub_menu.append('<div class="divider"></div><div class="header">'+LocalizedStrings.getUI('text_header_ivprog_functions')+'</div>');
  430. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_math')+'<div class="menu menu_math_functions"></div></div>');
  431. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_text')+'<div class="menu menu_text_functions"></div></div>');
  432. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_arrangement')+'<div class="menu menu_arrangement_functions"></div></div>');
  433. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_conversion')+'<div class="menu menu_conversion_functions"></div></div>');
  434. // Insert Math functions:
  435. for (var i = 0; i < window.system_functions.length; i++) {
  436. var t = $('<div class="item"></div>');
  437. t.data('function_reference', window.system_functions[i]);
  438. t.data('option', VAR_OR_VALUE_TYPES.only_function);
  439. t.text(LocalizedStrings.getUI(window.system_functions[i].identifier));
  440. switch(window.system_functions[i].category) {
  441. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  442. sub_menu.find('.menu_math_functions').append(t);
  443. break;
  444. }
  445. }
  446. }
  447. function addFunctionsToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  448. var sub_menu = menu_var_or_value.find('.menu_only_functions');
  449. sub_menu.text('');
  450. for (var i = 0; i < window.program_obj.functions.length; i++) {
  451. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_function+'">' + window.program_obj.functions[i].name + ' </div>');
  452. temp.data('function_reference', window.program_obj.functions[i]);
  453. sub_menu.append(temp);
  454. }
  455. }
  456. function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  457. var sub_menu = menu_var_or_value.find('.menu_only_vars');
  458. sub_menu.text('');
  459. if (window.program_obj.globals) {
  460. if (ref_object.include_constant) {
  461. for (var i = 0; i < window.program_obj.globals.length; i++) {
  462. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
  463. temp.data('variable_reference', window.program_obj.globals[i]);
  464. sub_menu.append(temp);
  465. }
  466. } else {
  467. for (var i = 0; i < window.program_obj.globals.length; i++) {
  468. if (!window.program_obj.globals[i].is_constant) {
  469. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
  470. temp.data('variable_reference', window.program_obj.globals[i]);
  471. sub_menu.append(temp);
  472. }
  473. }
  474. }
  475. }
  476. if (function_obj.parameters_list) {
  477. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  478. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.parameters_list[i].name + ' </div>');
  479. temp.data('variable_reference', function_obj.parameters_list[i]);
  480. sub_menu.append(temp);
  481. }
  482. }
  483. if (function_obj.variables_list) {
  484. for (var i = 0; i < function_obj.variables_list.length; i++) {
  485. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.variables_list[i].name + ' </div>');
  486. temp.data('variable_reference', function_obj.variables_list[i]);
  487. sub_menu.append(temp);
  488. }
  489. }
  490. }
  491. function addHandlers (command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element) {
  492. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  493. menu_var_or_value.dropdown({
  494. onChange: function(value, text, $selectedItem) {
  495. console.log('S7');
  496. dom_object.find('.var_name').remove();
  497. switch ($selectedItem.data('option')) {
  498. case VAR_OR_VALUE_TYPES.only_function:
  499. openInputToFunction(command, ref_object, dom_object, menu_var_or_value, function_obj, $($selectedItem).data('function_reference'), expression_element);
  500. break;
  501. case VAR_OR_VALUE_TYPES.only_value:
  502. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  503. break;
  504. case VAR_OR_VALUE_TYPES.only_variable:
  505. openInputToVariable(command, ref_object, dom_object, menu_var_or_value, function_obj, $($selectedItem).data('variable_reference'), expression_element);
  506. break;
  507. }
  508. if ($selectedItem.data('exp')) {
  509. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  510. }
  511. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  512. RepeatNTimesManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  513. }
  514. }
  515. });
  516. }
  517. dom_object.find('.width-dynamic').on('input', function() {
  518. var inputWidth = $(this).textWidth()+10;
  519. $(this).focus();
  520. var tmpStr = $(this).val();
  521. $(this).val('');
  522. $(this).val(tmpStr);
  523. $(this).css({
  524. width: inputWidth
  525. })
  526. }).trigger('input');
  527. if (command.type == Models.COMMAND_TYPES.comment) {
  528. dom_object.parent().on('click', function(e) {
  529. dom_object.find('.value_rendered').remove();
  530. dom_object.find('.value_rendered').empty();
  531. dom_object.find('.value_rendered').remove();
  532. dom_object.empty();
  533. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  534. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  535. });
  536. }
  537. }
  538. function openInputToFunction (command, ref_object, dom_object, menu_var_or_value, function_obj, function_selected, expression_element) {
  539. ref_object.function_called = function_selected;
  540. ref_object.parameters_list = [];
  541. if (function_selected.parameters_list != null && function_selected.parameters_list.length > 0) {
  542. menu_var_or_value.find('.text').text(' ');
  543. dom_object.find('.menu_var_or_value_dom').remove();
  544. var parameters_menu;
  545. if (function_selected.name) {
  546. parameters_menu = '<div class="parameters_function_called"> '+function_selected.name+' <span> ( </span>';
  547. } else {
  548. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.getUI(function_selected.category)+'.'+LocalizedStrings.getUI(function_selected.identifier)+'</i> <span> ( </span>';
  549. }
  550. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  551. parameters_menu += '<div class="render_style_param parameter_'+j+'"></div>';
  552. if ((j + 1) != function_selected.parameters_list.length) {
  553. parameters_menu += ' , ';
  554. }
  555. }
  556. parameters_menu += '<span> ) </span></div>';
  557. parameters_menu = $(parameters_menu);
  558. dom_object.append(parameters_menu);
  559. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  560. var temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  561. ref_object.parameters_list.push(temp);
  562. renderMenu(command, temp, parameters_menu.find('.parameter_'+j), function_obj, 2, expression_element);
  563. }
  564. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  565. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  566. if (command.type == Models.COMMAND_TYPES.attribution) {
  567. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  568. context_menu += '<div class="menu">';
  569. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  570. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  571. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  572. context_menu += '</div></div>';
  573. }
  574. context_menu += '</div></div>';
  575. context_menu = $(context_menu);
  576. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  577. context_menu.dropdown({
  578. onChange: function(value, text, $selectedItem) {
  579. console.log('S8');
  580. if ($selectedItem.data('clear')) {
  581. console.log('PP7');
  582. dom_object.text('');
  583. ref_object.content = null;
  584. ref_object.row = null;
  585. ref_object.column = null;
  586. delete ref_object.function_called;
  587. delete ref_object.parameters_list;
  588. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  589. }
  590. if ($selectedItem.data('exp')) {
  591. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  592. }
  593. }
  594. });
  595. } else {
  596. menu_var_or_value.find('.text').text(' ');
  597. dom_object.find('.menu_var_or_value_dom').remove();
  598. var parameters_menu;
  599. if (function_selected.name) {
  600. parameters_menu = '<div class="parameters_function_called"> '+function_selected.name+' <span> ( </span>';
  601. } else {
  602. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.getUI(function_selected.category)+'.'+LocalizedStrings.getUI(function_selected.identifier)+'</i> <span> ( </span>';
  603. }
  604. parameters_menu += '<span> ) </span></div>';
  605. parameters_menu = $(parameters_menu);
  606. dom_object.append(parameters_menu);
  607. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  608. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  609. if (command.type == Models.COMMAND_TYPES.attribution) {
  610. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  611. context_menu += '<div class="menu">';
  612. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  613. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  614. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  615. context_menu += '</div></div>';
  616. }
  617. context_menu += '</div></div>';
  618. context_menu = $(context_menu);
  619. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  620. context_menu.dropdown({
  621. onChange: function(value, text, $selectedItem) {
  622. console.log('S9');
  623. if ($selectedItem.data('clear')) {
  624. console.log('PP8');
  625. dom_object.text('');
  626. ref_object.content = null;
  627. ref_object.row = null;
  628. ref_object.column = null;
  629. delete ref_object.function_called;
  630. delete ref_object.parameters_list;
  631. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  632. }
  633. if ($selectedItem.data('exp')) {
  634. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  635. }
  636. }
  637. });
  638. }
  639. if (command.type == Models.COMMAND_TYPES.attribution) {
  640. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  641. }
  642. }
  643. function openInputToVariable (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected, expression_element) {
  644. ref_object.content = variable_selected;
  645. menu_var_or_value.find('.text').text(' ');
  646. dom_object.find('.menu_var_or_value_dom').remove();
  647. var variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_selected.name+'</span>';
  648. if (variable_selected.dimensions == 1) {
  649. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  650. }
  651. if (variable_selected.dimensions == 2) {
  652. variable_render += ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  653. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  654. }
  655. variable_render += '</div>';
  656. variable_render = $(variable_render);
  657. dom_object.append(variable_render);
  658. if (variable_selected.dimensions == 1) {
  659. ref_object.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  660. renderMenu(command, ref_object.column, variable_render.find('.column_container'), function_obj, 2, expression_element);
  661. }
  662. if (variable_selected.dimensions == 2) {
  663. ref_object.row = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  664. renderMenu(command, ref_object.row, variable_render.find('.row_container'), function_obj, 2, expression_element);
  665. ref_object.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  666. renderMenu(command, ref_object.column, variable_render.find('.column_container'), function_obj, 2, expression_element);
  667. }
  668. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  669. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  670. if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  671. console.log("dom_object 10: ");
  672. console.log(dom_object);
  673. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  674. context_menu += '<div class="menu">';
  675. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  676. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  677. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  678. context_menu += '</div></div>';
  679. }
  680. context_menu += '</div></div>';
  681. context_menu = $(context_menu);
  682. context_menu.insertAfter( dom_object.find('.variable_rendered') );
  683. context_menu.dropdown({
  684. onChange: function(value, text, $selectedItem) {
  685. console.log('S10');
  686. if ($selectedItem.data('clear')) {
  687. console.log('PP9');
  688. dom_object.text('');
  689. ref_object.content = null;
  690. ref_object.row = null;
  691. ref_object.column = null;
  692. delete ref_object.function_called;
  693. delete ref_object.parameters_list;
  694. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  695. }
  696. if ($selectedItem.data('exp')) {
  697. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  698. }
  699. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  700. RepeatNTimesManagement.manageClearExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  701. }
  702. }
  703. });
  704. if (command.type == Models.COMMAND_TYPES.attribution) {
  705. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  706. }
  707. }
  708. function openInputToValue (command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element) {
  709. if (ref_object.content == null) {
  710. ref_object.content = "";
  711. }
  712. menu_var_or_value.find('.text').text(' ');
  713. var field = $('<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />');
  714. field.insertBefore(dom_object.find('.menu_var_or_value_dom'));
  715. var rendered = $('<div class="value_rendered"></div>');
  716. rendered.insertBefore(field);
  717. field.focus();
  718. field.val(ref_object.content);
  719. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  720. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  721. if (command.type == Models.COMMAND_TYPES.attribution) {
  722. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  723. context_menu += '<div class="menu">';
  724. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  725. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  726. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  727. context_menu += '</div></div>';
  728. }
  729. context_menu += '</div></div>';
  730. context_menu = $(context_menu);
  731. dom_object.find('.menu_var_or_value_dom').remove();
  732. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  733. context_menu.insertAfter( field );
  734. }
  735. context_menu.dropdown({
  736. onChange: function(value, text, $selectedItem) {
  737. console.log('S11');
  738. if ($selectedItem.data('clear')) {
  739. console.log('PP10');
  740. dom_object.text('');
  741. dom_object.find('.value_rendered').remove();
  742. dom_object.find('.context_menu_clear').remove();
  743. dom_object.find('.width-dynamic-minus').remove();
  744. ref_object.content = null;
  745. ref_object.row = null;
  746. ref_object.column = null;
  747. delete ref_object.function_called;
  748. delete ref_object.parameters_list;
  749. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  750. }
  751. if ($selectedItem.data('exp')) {
  752. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  753. }
  754. }
  755. });
  756. dom_object.find('.width-dynamic-minus').focusout(function() {
  757. if ($(this).val().trim()) {
  758. ref_object.content = $(this).val().trim();
  759. }
  760. rendered.text(ref_object.content);
  761. $(this).remove();
  762. });
  763. dom_object.find('.width-dynamic-minus').on('keydown', function(e) {
  764. var code = e.keyCode || e.which;
  765. if(code == 13) {
  766. if ($(this).val().trim()) {
  767. ref_object.content = $(this).val().trim();
  768. }
  769. rendered.text(ref_object.content);
  770. $(this).remove();
  771. }
  772. if(code == 27) {
  773. rendered.text(ref_object.content);
  774. $(this).remove();
  775. }
  776. });
  777. if (command.type == Models.COMMAND_TYPES.comment) {
  778. rendered.parent().on('click', function(e) {
  779. console.log("TTT14");
  780. rendered.remove();
  781. rendered.empty();
  782. rendered.remove();
  783. dom_object.empty();
  784. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  785. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  786. });
  787. }
  788. rendered.on('click', function(e) {
  789. console.log("TTT2");
  790. rendered.remove();
  791. rendered.empty();
  792. rendered.remove();
  793. dom_object.empty();
  794. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  795. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  796. });
  797. if (command.type == Models.COMMAND_TYPES.attribution) {
  798. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  799. }
  800. }
  801. $.fn.textWidth = function(text, font) {
  802. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  803. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  804. return $.fn.textWidth.fakeEl.width();
  805. };