1
0

variable_value_menu.js 45 KB

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