variable_value_menu.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. import * as Models from "../ivprog_elements";
  2. import { LocalizedStrings } from "../../services/localizedStringsService";
  3. import * as AttribuitionsManagement from "./attribution";
  4. import * as RepeatNTimesManagement from "./repeatNtimes";
  5. export const VAR_OR_VALUE_TYPES = Object.freeze({
  6. only_variable: 1,
  7. only_value: 2,
  8. only_function: 3,
  9. variable_and_function: 4,
  10. variable_and_value_opt: 5,
  11. value_and_function: 6,
  12. all: 7,
  13. });
  14. export function renderMenu (
  15. command,
  16. ref_object,
  17. dom_object,
  18. function_obj,
  19. size_field = 2,
  20. expression_element
  21. ) {
  22. // Verificar se o objeto atual trata-se de uma chamada de função e conferir se possui a quantidade correta de parâmetros
  23. // Caso não possua, tem que adicionar as variáveis que servirão de parâmetros:
  24. if (ref_object.function_called) {
  25. if (ref_object.function_called.parameters_list) {
  26. while (
  27. ref_object.function_called.parameters_list.length !=
  28. ref_object.parameters_list.length
  29. ) {
  30. if (
  31. ref_object.parameters_list.length >
  32. ref_object.function_called.parameters_list.length
  33. ) {
  34. ref_object.parameters_list.pop();
  35. } else {
  36. ref_object.parameters_list.push(
  37. new Models.VariableValueMenu(
  38. VAR_OR_VALUE_TYPES.all,
  39. null,
  40. null,
  41. null,
  42. true
  43. )
  44. );
  45. }
  46. }
  47. }
  48. }
  49. let menu_var_or_value =
  50. '<div class="ui dropdown menu_var_or_value_dom" data-varmenu="true"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  51. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_variable) {
  52. menu_var_or_value =
  53. '<div class="ui dropdown menu_var_or_value_dom" data-varmenu="true"><div class="text"></div><i class="dropdown icon"></i><div class="menu menu_only_vars">';
  54. menu_var_or_value += "</div>";
  55. }
  56. if (
  57. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function ||
  58. ref_object.variable_and_value ==
  59. VAR_OR_VALUE_TYPES.variable_and_value_opt ||
  60. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all
  61. ) {
  62. menu_var_or_value +=
  63. '<div class="item" data-option="' +
  64. VAR_OR_VALUE_TYPES.only_variable +
  65. '"><i class="dropdown icon"></i>' +
  66. LocalizedStrings.getUI("variable");
  67. menu_var_or_value += '<div class="menu menu_only_vars">';
  68. menu_var_or_value += "</div></div>";
  69. }
  70. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_value) {
  71. menu_var_or_value =
  72. '<input type="text" class="width-dynamic" size="' +
  73. size_field +
  74. '" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />';
  75. }
  76. if (
  77. ref_object.variable_and_value ==
  78. VAR_OR_VALUE_TYPES.variable_and_value_opt ||
  79. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function ||
  80. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all
  81. ) {
  82. menu_var_or_value +=
  83. '<div class="item" data-option="' +
  84. VAR_OR_VALUE_TYPES.only_value +
  85. '">' +
  86. LocalizedStrings.getUI("text_value") +
  87. "</div>";
  88. }
  89. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_function) {
  90. menu_var_or_value =
  91. '<div class="ui dropdown menu_var_or_value_dom" data-varmenu="true"><div class="text"></div><i class="dropdown icon"></i><div class="menu menu_only_functions">';
  92. menu_var_or_value += "</div>";
  93. }
  94. if (
  95. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function ||
  96. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function ||
  97. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all
  98. ) {
  99. menu_var_or_value +=
  100. '<div class="item" data-option="' +
  101. VAR_OR_VALUE_TYPES.only_function +
  102. '"><i class="dropdown icon"></i>' +
  103. LocalizedStrings.getUI("btn_function");
  104. menu_var_or_value += '<div class="menu menu_only_functions">';
  105. menu_var_or_value += "</div></div>";
  106. /* if (command.type == Models.COMMAND_TYPES.attribution) {
  107. menu_var_or_value += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  108. menu_var_or_value += '<div class="menu">';
  109. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  110. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  111. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  112. menu_var_or_value += '</div></div>';
  113. }*/
  114. }
  115. menu_var_or_value += "</div></div>";
  116. menu_var_or_value = $(menu_var_or_value);
  117. dom_object.append(menu_var_or_value);
  118. ref_object.dom_object = menu_var_or_value;
  119. addHandlers(
  120. command,
  121. ref_object,
  122. dom_object,
  123. menu_var_or_value,
  124. function_obj,
  125. expression_element
  126. );
  127. addVariablesToMenu(
  128. function_obj,
  129. menu_var_or_value,
  130. ref_object,
  131. expression_element
  132. );
  133. addFunctionsToMenu(
  134. function_obj,
  135. menu_var_or_value,
  136. ref_object,
  137. expression_element
  138. );
  139. addIVProgFunctionsToMenu(
  140. function_obj,
  141. menu_var_or_value,
  142. ref_object,
  143. expression_element
  144. );
  145. if (ref_object.content || ref_object.function_called) {
  146. if (ref_object.content) {
  147. // Verificar se a variável ainda existe:
  148. const variable_fun = isVarInProgram(ref_object.content, function_obj);
  149. if (variable_fun) {
  150. ref_object.content = variable_fun;
  151. renderPreviousContent(
  152. function_obj,
  153. menu_var_or_value,
  154. ref_object,
  155. dom_object,
  156. command,
  157. expression_element
  158. );
  159. } else {
  160. if (ref_object.content && ref_object.content.type) {
  161. ref_object.content = null;
  162. appendSelectText(ref_object, menu_var_or_value);
  163. } else {
  164. renderPreviousContent(
  165. function_obj,
  166. menu_var_or_value,
  167. ref_object,
  168. dom_object,
  169. command,
  170. expression_element
  171. );
  172. }
  173. }
  174. } else if (ref_object.function_called) {
  175. // Verificar se a função ainda existe:
  176. const ret_function = isFunctionInProgram(ref_object.function_called);
  177. if (ret_function) {
  178. ref_object.function_called = ret_function;
  179. renderPreviousContent(
  180. function_obj,
  181. menu_var_or_value,
  182. ref_object,
  183. dom_object,
  184. command,
  185. expression_element
  186. );
  187. } else {
  188. ref_object.content = null;
  189. ref_object.row = null;
  190. ref_object.column = null;
  191. delete ref_object.function_called;
  192. delete ref_object.parameters_list;
  193. appendSelectText(ref_object, menu_var_or_value);
  194. }
  195. }
  196. } else {
  197. appendSelectText(ref_object, menu_var_or_value);
  198. }
  199. }
  200. function appendSelectText (ref_object, menu_var_or_value) {
  201. switch (ref_object.variable_and_value) {
  202. case VAR_OR_VALUE_TYPES.only_variable:
  203. menu_var_or_value
  204. .find(".text")
  205. .append("<i>" + LocalizedStrings.getUI("var_menu_select_var") + "</i>");
  206. break;
  207. case VAR_OR_VALUE_TYPES.all:
  208. menu_var_or_value
  209. .find(".text")
  210. .append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  211. break;
  212. case VAR_OR_VALUE_TYPES.variable_and_function:
  213. menu_var_or_value
  214. .find(".text")
  215. .append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  216. break;
  217. case VAR_OR_VALUE_TYPES.only_function:
  218. menu_var_or_value
  219. .find(".text")
  220. .append(
  221. "<i>" + LocalizedStrings.getUI("var_menu_select_function") + "</i>"
  222. );
  223. break;
  224. }
  225. }
  226. function isFunctionInProgram (function_called_obj) {
  227. if (function_called_obj.name) {
  228. if (window.program_obj.functions) {
  229. for (var i = 0; i < window.program_obj.functions.length; i++) {
  230. if (window.program_obj.functions[i] == function_called_obj) {
  231. return window.program_obj.functions[i];
  232. }
  233. }
  234. for (var i = 0; i < window.program_obj.functions.length; i++) {
  235. if (window.program_obj.functions[i].name == function_called_obj.name) {
  236. return window.program_obj.functions[i];
  237. }
  238. }
  239. }
  240. } else if (function_called_obj.identifier) {
  241. for (var i = 0; i < window.system_functions.length; i++) {
  242. if (
  243. window.system_functions[i].identifier == function_called_obj.identifier
  244. ) {
  245. return window.system_functions[i];
  246. }
  247. }
  248. }
  249. return null;
  250. }
  251. function isVarInProgram (var_obj, function_obj) {
  252. // Verify in locals:
  253. if (function_obj.variables_list) {
  254. for (var i = 0; i < function_obj.variables_list.length; i++) {
  255. if (function_obj.variables_list[i] == var_obj) {
  256. return function_obj.variables_list[i];
  257. }
  258. }
  259. }
  260. // Verify in parameters:
  261. if (function_obj.parameters_list) {
  262. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  263. if (function_obj.parameters_list[i] == var_obj) {
  264. return function_obj.parameters_list[i];
  265. }
  266. }
  267. }
  268. // Verify in globals:
  269. if (window.program_obj.globals) {
  270. for (var i = 0; i < window.program_obj.globals.length; i++) {
  271. if (window.program_obj.globals[i] == var_obj) {
  272. return window.program_obj.globals[i];
  273. }
  274. }
  275. }
  276. // If not found, verify if the reference was lost
  277. if (var_obj) {
  278. if (function_obj.variables_list) {
  279. for (var i = 0; i < function_obj.variables_list.length; i++) {
  280. if (function_obj.variables_list[i].name == var_obj.name) {
  281. return function_obj.variables_list[i];
  282. }
  283. }
  284. }
  285. if (function_obj.parameters_list) {
  286. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  287. if (function_obj.parameters_list[i].name == var_obj.name) {
  288. return function_obj.parameters_list[i];
  289. }
  290. }
  291. }
  292. if (window.program_obj.globals) {
  293. for (var i = 0; i < window.program_obj.globals.length; i++) {
  294. if (window.program_obj.globals[i].name == var_obj.name) {
  295. return window.program_obj.globals[i];
  296. }
  297. }
  298. }
  299. }
  300. return null;
  301. }
  302. function renderPreviousContent (
  303. function_obj,
  304. menu_var_or_value,
  305. ref_object,
  306. dom_object,
  307. command,
  308. expression_element
  309. ) {
  310. if (ref_object.function_called) {
  311. menu_var_or_value.remove();
  312. variableValueMenuCode(
  313. command,
  314. ref_object,
  315. dom_object,
  316. function_obj,
  317. menu_var_or_value,
  318. expression_element
  319. );
  320. } else if (ref_object.content.type) {
  321. menu_var_or_value.remove();
  322. variableValueMenuCode(
  323. command,
  324. ref_object,
  325. dom_object,
  326. function_obj,
  327. menu_var_or_value,
  328. expression_element
  329. );
  330. } else {
  331. menu_var_or_value.remove();
  332. variableValueMenuCode(
  333. command,
  334. ref_object,
  335. dom_object,
  336. function_obj,
  337. menu_var_or_value,
  338. expression_element
  339. );
  340. }
  341. }
  342. function variableValueMenuCode (
  343. command,
  344. variable_obj,
  345. dom_object,
  346. function_obj,
  347. menu_var_or_value,
  348. expression_element
  349. ) {
  350. if (variable_obj.content || variable_obj.function_called) {
  351. // Verificar se a variável ainda existe:
  352. const var_fun = isVarInProgram(variable_obj.content, function_obj);
  353. if (var_fun) {
  354. variable_obj.content = var_fun;
  355. } else {
  356. if (variable_obj.content && variable_obj.content.type) {
  357. variable_obj.content = null;
  358. appendSelectText(variable_obj, menu_var_or_value);
  359. }
  360. }
  361. } else {
  362. appendSelectText(variable_obj, menu_var_or_value);
  363. }
  364. if (variable_obj.content == null && variable_obj.function_called == null) {
  365. renderMenu(
  366. command,
  367. variable_obj,
  368. dom_object,
  369. function_obj,
  370. 2,
  371. expression_element
  372. );
  373. return;
  374. }
  375. const ret = "";
  376. if (variable_obj.function_called) {
  377. if (
  378. variable_obj.function_called.parameters_list == null ||
  379. variable_obj.function_called.length == 0
  380. ) {
  381. menu_var_or_value.find(".text").text(" ");
  382. dom_object.find(".menu_var_or_value_dom").remove();
  383. var parameters_menu;
  384. if (variable_obj.function_called.name) {
  385. parameters_menu =
  386. '<div class="parameters_function_called"> ' +
  387. variable_obj.function_called.name +
  388. " <span> ( </span>";
  389. } else {
  390. parameters_menu =
  391. '<div class="parameters_function_called"> <i>' +
  392. LocalizedStrings.translateInternalFunction(
  393. variable_obj.function_called.identifier,
  394. variable_obj.function_called.category
  395. ) +
  396. "</i> <span> ( </span>";
  397. }
  398. parameters_menu += "<span> ) </span></div>";
  399. parameters_menu = $(parameters_menu);
  400. dom_object.append(parameters_menu);
  401. var context_menu =
  402. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  403. context_menu +=
  404. '<div class="item" data-clear="true">' +
  405. LocalizedStrings.getUI("btn_clear") +
  406. "</div>";
  407. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  408. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  409. context_menu += '<div class="menu">';
  410. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  411. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  412. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  413. context_menu += '</div></div>';
  414. }*/
  415. context_menu += "</div></div>";
  416. context_menu = $(context_menu);
  417. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  418. context_menu.dropdown({
  419. onChange: function (value, text, $selectedItem) {
  420. console.log("S1");
  421. if ($selectedItem.data("clear")) {
  422. console.log("PP1");
  423. dom_object.text("");
  424. variable_obj.content = null;
  425. variable_obj.row = null;
  426. variable_obj.column = null;
  427. delete variable_obj.function_called;
  428. delete variable_obj.parameters_list;
  429. renderMenu(
  430. command,
  431. variable_obj,
  432. dom_object,
  433. function_obj,
  434. 2,
  435. expression_element
  436. );
  437. }
  438. if ($selectedItem.data("exp")) {
  439. AttribuitionsManagement.manageExpressionElements(
  440. command,
  441. variable_obj,
  442. dom_object,
  443. menu_var_or_value,
  444. function_obj,
  445. $selectedItem,
  446. expression_element
  447. );
  448. }
  449. },
  450. selectOnKeydown: false,
  451. });
  452. } else {
  453. menu_var_or_value.find(".text").text(" ");
  454. dom_object.find(".menu_var_or_value_dom").remove();
  455. var parameters_menu;
  456. if (variable_obj.function_called.name) {
  457. parameters_menu =
  458. '<div class="parameters_function_called"> ' +
  459. variable_obj.function_called.name +
  460. " <span> ( </span>";
  461. } else {
  462. parameters_menu =
  463. '<div class="parameters_function_called"> <i>' +
  464. LocalizedStrings.translateInternalFunction(
  465. variable_obj.function_called.identifier,
  466. variable_obj.function_called.category
  467. ) +
  468. "</i> <span> ( </span>";
  469. }
  470. for (
  471. let j = 0;
  472. j < variable_obj.function_called.parameters_list.length;
  473. j++
  474. ) {
  475. parameters_menu +=
  476. '<div class="render_style_param parameter_' + j + '"></div>';
  477. if (j + 1 != variable_obj.function_called.parameters_list.length) {
  478. parameters_menu += " , ";
  479. }
  480. }
  481. parameters_menu += "<span> ) </span></div>";
  482. parameters_menu = $(parameters_menu);
  483. dom_object.append(parameters_menu);
  484. for (
  485. let j = 0;
  486. j < variable_obj.function_called.parameters_list.length;
  487. j++
  488. ) {
  489. renderMenu(
  490. command,
  491. variable_obj.parameters_list[j],
  492. parameters_menu.find(".parameter_" + j),
  493. function_obj,
  494. 2,
  495. expression_element
  496. );
  497. }
  498. let context_menu =
  499. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  500. context_menu +=
  501. '<div class="item" data-clear="true">' +
  502. LocalizedStrings.getUI("btn_clear") +
  503. "</div>";
  504. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  505. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  506. context_menu += '<div class="menu">';
  507. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  508. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  509. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  510. context_menu += '</div></div>';
  511. }*/
  512. context_menu += "</div></div>";
  513. context_menu = $(context_menu);
  514. context_menu.insertAfter(parameters_menu);
  515. context_menu.dropdown({
  516. onChange: function (value, text, $selectedItem) {
  517. console.log("S2");
  518. if ($selectedItem.data("clear")) {
  519. console.log("PP2");
  520. dom_object.text("");
  521. variable_obj.content = null;
  522. variable_obj.row = null;
  523. variable_obj.column = null;
  524. delete variable_obj.function_called;
  525. delete variable_obj.parameters_list;
  526. renderMenu(
  527. command,
  528. variable_obj,
  529. dom_object,
  530. function_obj,
  531. 2,
  532. expression_element
  533. );
  534. }
  535. if ($selectedItem.data("exp")) {
  536. AttribuitionsManagement.manageExpressionElements(
  537. command,
  538. variable_obj,
  539. dom_object,
  540. menu_var_or_value,
  541. function_obj,
  542. $selectedItem,
  543. expression_element
  544. );
  545. }
  546. },
  547. selectOnKeydown: false,
  548. });
  549. }
  550. } else if (variable_obj.content.type) {
  551. let variable_render = "";
  552. if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
  553. variable_render =
  554. '<div class="variable_rendered"> <span class="var_name">' +
  555. variable_obj.content.name +
  556. "</span>";
  557. variable_render +=
  558. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  559. variable_render += "</div>";
  560. variable_render = $(variable_render);
  561. dom_object.append(variable_render);
  562. let context_menu =
  563. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  564. context_menu +=
  565. '<div class="item" data-clear="true">' +
  566. LocalizedStrings.getUI("btn_clear") +
  567. "</div>";
  568. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  569. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  570. context_menu += '<div class="menu">';
  571. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  572. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  573. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  574. context_menu += '</div></div>';
  575. }*/
  576. context_menu += "</div></div>";
  577. context_menu = $(context_menu);
  578. variable_render.append(context_menu);
  579. context_menu.dropdown({
  580. onChange: function (value, text, $selectedItem) {
  581. console.log("S3");
  582. if ($selectedItem.data("clear")) {
  583. console.log("PP3");
  584. dom_object.text("");
  585. variable_obj.content = null;
  586. variable_obj.row = null;
  587. variable_obj.column = null;
  588. delete variable_obj.function_called;
  589. delete variable_obj.parameters_list;
  590. renderMenu(
  591. command,
  592. variable_obj,
  593. dom_object,
  594. function_obj,
  595. 2,
  596. expression_element
  597. );
  598. }
  599. if ($selectedItem.data("exp")) {
  600. AttribuitionsManagement.manageExpressionElements(
  601. command,
  602. variable_obj,
  603. dom_object,
  604. menu_var_or_value,
  605. function_obj,
  606. $selectedItem,
  607. expression_element
  608. );
  609. }
  610. },
  611. selectOnKeydown: false,
  612. });
  613. if (!variable_obj.column) {
  614. variable_obj.column = new Models.VariableValueMenu(
  615. VAR_OR_VALUE_TYPES.all,
  616. null,
  617. null,
  618. null,
  619. true
  620. );
  621. }
  622. variableValueMenuCode(
  623. command,
  624. variable_obj.column,
  625. $(variable_render.find(".column_container")),
  626. function_obj,
  627. menu_var_or_value,
  628. expression_element
  629. );
  630. } else if (
  631. variable_obj.content.dimensions == 2 &&
  632. variable_obj.dimensions != 2
  633. ) {
  634. variable_render =
  635. '<div class="variable_rendered"> <span class="var_name">' +
  636. variable_obj.content.name +
  637. "</span>";
  638. variable_render +=
  639. ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  640. variable_render +=
  641. ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  642. variable_render += "</div>";
  643. variable_render = $(variable_render);
  644. dom_object.append(variable_render);
  645. let context_menu =
  646. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  647. context_menu +=
  648. '<div class="item" data-clear="true">' +
  649. LocalizedStrings.getUI("btn_clear") +
  650. "</div>";
  651. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  652. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  653. context_menu += '<div class="menu">';
  654. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  655. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  656. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  657. context_menu += '</div></div>';
  658. }*/
  659. context_menu += "</div></div>";
  660. context_menu = $(context_menu);
  661. variable_render.append(context_menu);
  662. context_menu.dropdown({
  663. onChange: function (value, text, $selectedItem) {
  664. console.log("S4");
  665. if ($selectedItem.data("clear")) {
  666. console.log("PP4");
  667. dom_object.text("");
  668. variable_obj.content = null;
  669. variable_obj.row = null;
  670. variable_obj.column = null;
  671. delete variable_obj.function_called;
  672. delete variable_obj.parameters_list;
  673. renderMenu(
  674. command,
  675. variable_obj,
  676. dom_object,
  677. function_obj,
  678. 2,
  679. expression_element
  680. );
  681. }
  682. if ($selectedItem.data("exp")) {
  683. AttribuitionsManagement.manageExpressionElements(
  684. command,
  685. variable_obj,
  686. dom_object,
  687. menu_var_or_value,
  688. function_obj,
  689. $selectedItem,
  690. expression_element
  691. );
  692. }
  693. },
  694. selectOnKeydown: false,
  695. });
  696. if (!variable_obj.column) {
  697. variable_obj.column = new Models.VariableValueMenu(
  698. VAR_OR_VALUE_TYPES.all,
  699. null,
  700. null,
  701. null,
  702. true
  703. );
  704. }
  705. if (!variable_obj.row) {
  706. variable_obj.row = new Models.VariableValueMenu(
  707. VAR_OR_VALUE_TYPES.all,
  708. null,
  709. null,
  710. null,
  711. true
  712. );
  713. }
  714. variableValueMenuCode(
  715. command,
  716. variable_obj.row,
  717. $(variable_render.find(".row_container")),
  718. function_obj,
  719. menu_var_or_value,
  720. expression_element
  721. );
  722. variableValueMenuCode(
  723. command,
  724. variable_obj.column,
  725. $(variable_render.find(".column_container")),
  726. function_obj,
  727. menu_var_or_value,
  728. expression_element
  729. );
  730. } else {
  731. variable_render =
  732. '<div class="variable_rendered"> <span class="var_name">' +
  733. variable_obj.content.name +
  734. "</span>";
  735. variable_render += "</div>";
  736. variable_render = $(variable_render);
  737. dom_object.append(variable_render);
  738. let context_menu =
  739. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  740. context_menu +=
  741. '<div class="item" data-clear="true">' +
  742. LocalizedStrings.getUI("btn_clear") +
  743. "</div>";
  744. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  745. console.log('dom_object6');
  746. console.log(dom_object);
  747. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  748. context_menu += '<div class="menu">';
  749. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  750. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  751. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  752. context_menu += '</div></div>';
  753. }*/
  754. context_menu += "</div></div>";
  755. context_menu = $(context_menu);
  756. variable_render.append(context_menu);
  757. context_menu.dropdown({
  758. onChange: function (value, text, $selectedItem) {
  759. console.log("S5");
  760. if ($selectedItem.data("clear")) {
  761. console.log("PP5");
  762. dom_object.text("");
  763. variable_obj.content = null;
  764. variable_obj.row = null;
  765. variable_obj.column = null;
  766. delete variable_obj.function_called;
  767. delete variable_obj.parameters_list;
  768. renderMenu(
  769. command,
  770. variable_obj,
  771. dom_object,
  772. function_obj,
  773. 2,
  774. expression_element
  775. );
  776. }
  777. if ($selectedItem.data("exp")) {
  778. AttribuitionsManagement.manageExpressionElements(
  779. command,
  780. variable_obj,
  781. dom_object,
  782. menu_var_or_value,
  783. function_obj,
  784. $selectedItem,
  785. expression_element
  786. );
  787. }
  788. },
  789. selectOnKeydown: false,
  790. });
  791. }
  792. } else {
  793. let variable_render =
  794. '<div class="variable_rendered"> <span class="var_name">' +
  795. variable_obj.content +
  796. "</span>";
  797. variable_render += "</div>";
  798. variable_render = $(variable_render);
  799. dom_object.append(variable_render);
  800. var context_menu =
  801. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  802. context_menu +=
  803. '<div class="item" data-clear="true">' +
  804. LocalizedStrings.getUI("btn_clear") +
  805. "</div>";
  806. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  807. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  808. context_menu += '<div class="menu">';
  809. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  810. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  811. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  812. context_menu += '</div></div>';
  813. }*/
  814. context_menu += "</div></div>";
  815. context_menu = $(context_menu);
  816. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  817. context_menu.insertAfter(variable_render);
  818. }
  819. context_menu.dropdown({
  820. onChange: function (value, text, $selectedItem) {
  821. console.log("S6");
  822. if ($selectedItem.data("clear")) {
  823. console.log("PP6");
  824. dom_object.text("");
  825. variable_obj.content = null;
  826. variable_obj.row = null;
  827. variable_obj.column = null;
  828. delete variable_obj.function_called;
  829. delete variable_obj.parameters_list;
  830. dom_object.find(".value_rendered").remove();
  831. dom_object.find(".context_menu_clear").remove();
  832. dom_object.find(".width-dynamic-minus").remove();
  833. renderMenu(
  834. command,
  835. variable_obj,
  836. dom_object,
  837. function_obj,
  838. 2,
  839. expression_element
  840. );
  841. }
  842. if ($selectedItem.data("exp")) {
  843. AttribuitionsManagement.manageExpressionElements(
  844. command,
  845. variable_obj,
  846. dom_object,
  847. menu_var_or_value,
  848. function_obj,
  849. $selectedItem,
  850. expression_element
  851. );
  852. }
  853. },
  854. selectOnKeydown: false,
  855. });
  856. variable_render.on("click", function (e) {
  857. variable_render.remove();
  858. variable_render.empty();
  859. variable_render.remove();
  860. dom_object.empty();
  861. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  862. openInputToValue(
  863. command,
  864. variable_obj,
  865. dom_object,
  866. menu_var_or_value,
  867. function_obj,
  868. expression_element
  869. );
  870. });
  871. }
  872. }
  873. function addIVProgFunctionsToMenu (
  874. function_obj,
  875. menu_var_or_value,
  876. ref_object,
  877. expression_element
  878. ) {
  879. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  880. sub_menu.append(
  881. '<div class="divider"></div><div class="header">' +
  882. LocalizedStrings.getUI("text_header_ivprog_functions") +
  883. "</div>"
  884. );
  885. sub_menu.append(
  886. '<div class="item"><i class="dropdown icon"></i>' +
  887. LocalizedStrings.getUI("text_menu_functions_math") +
  888. '<div class="menu menu_math_functions"></div></div>'
  889. );
  890. sub_menu.append(
  891. '<div class="item"><i class="dropdown icon"></i>' +
  892. LocalizedStrings.getUI("text_menu_functions_text") +
  893. '<div class="menu menu_text_functions"></div></div>'
  894. );
  895. sub_menu.append(
  896. '<div class="item"><i class="dropdown icon"></i>' +
  897. LocalizedStrings.getUI("text_menu_functions_array") +
  898. '<div class="menu menu_arrangement_functions"></div></div>'
  899. );
  900. sub_menu.append(
  901. '<div class="item"><i class="dropdown icon"></i>' +
  902. LocalizedStrings.getUI("text_menu_functions_conversion") +
  903. '<div class="menu menu_conversion_functions"></div></div>'
  904. );
  905. // Insert Math functions:
  906. for (let i = 0; i < window.system_functions.length; i++) {
  907. const t = $('<div class="item"></div>');
  908. t.data("function_reference", window.system_functions[i]);
  909. t.data("option", VAR_OR_VALUE_TYPES.only_function);
  910. t.text(
  911. LocalizedStrings.translateInternalFunction(
  912. window.system_functions[i].identifier
  913. )
  914. );
  915. switch (window.system_functions[i].category) {
  916. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  917. sub_menu.find(".menu_math_functions").append(t);
  918. break;
  919. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  920. sub_menu.find(".menu_text_functions").append(t);
  921. break;
  922. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  923. sub_menu.find(".menu_arrangement_functions").append(t);
  924. break;
  925. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  926. sub_menu.find(".menu_conversion_functions").append(t);
  927. break;
  928. }
  929. }
  930. }
  931. function addFunctionsToMenu (
  932. function_obj,
  933. menu_var_or_value,
  934. ref_object,
  935. expression_element
  936. ) {
  937. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  938. sub_menu.text("");
  939. for (let i = 0; i < window.program_obj.functions.length; i++) {
  940. const temp = $(
  941. '<div class="item" data-option="' +
  942. VAR_OR_VALUE_TYPES.only_function +
  943. '">' +
  944. window.program_obj.functions[i].name +
  945. " </div>"
  946. );
  947. temp.data("function_reference", window.program_obj.functions[i]);
  948. sub_menu.append(temp);
  949. }
  950. }
  951. function addVariablesToMenu (
  952. function_obj,
  953. menu_var_or_value,
  954. ref_object,
  955. expression_element
  956. ) {
  957. const sub_menu = menu_var_or_value.find(".menu_only_vars");
  958. sub_menu.text("");
  959. let is_there = false;
  960. if (window.program_obj.globals) {
  961. if (ref_object.include_constant) {
  962. for (var i = 0; i < window.program_obj.globals.length; i++) {
  963. var temp = $(
  964. '<div class="item" data-option="' +
  965. VAR_OR_VALUE_TYPES.only_variable +
  966. '">' +
  967. window.program_obj.globals[i].name +
  968. " </div>"
  969. );
  970. temp.data("variable_reference", window.program_obj.globals[i]);
  971. sub_menu.append(temp);
  972. is_there = true;
  973. }
  974. } else {
  975. for (var i = 0; i < window.program_obj.globals.length; i++) {
  976. if (!window.program_obj.globals[i].is_constant) {
  977. var temp = $(
  978. '<div class="item" data-option="' +
  979. VAR_OR_VALUE_TYPES.only_variable +
  980. '">' +
  981. window.program_obj.globals[i].name +
  982. " </div>"
  983. );
  984. temp.data("variable_reference", window.program_obj.globals[i]);
  985. sub_menu.append(temp);
  986. is_there = true;
  987. }
  988. }
  989. }
  990. }
  991. if (function_obj.parameters_list) {
  992. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  993. var temp = $(
  994. '<div class="item" data-option="' +
  995. VAR_OR_VALUE_TYPES.only_variable +
  996. '">' +
  997. function_obj.parameters_list[i].name +
  998. " </div>"
  999. );
  1000. temp.data("variable_reference", function_obj.parameters_list[i]);
  1001. sub_menu.append(temp);
  1002. is_there = true;
  1003. }
  1004. }
  1005. if (function_obj.variables_list) {
  1006. for (var i = 0; i < function_obj.variables_list.length; i++) {
  1007. var temp = $(
  1008. '<div class="item" data-option="' +
  1009. VAR_OR_VALUE_TYPES.only_variable +
  1010. '">' +
  1011. function_obj.variables_list[i].name +
  1012. " </div>"
  1013. );
  1014. temp.data("variable_reference", function_obj.variables_list[i]);
  1015. sub_menu.append(temp);
  1016. is_there = true;
  1017. }
  1018. }
  1019. if (!is_there) {
  1020. sub_menu.append(
  1021. $(
  1022. '<div class="header">' +
  1023. LocalizedStrings.getUI("text_no_variable") +
  1024. "</div>"
  1025. )
  1026. );
  1027. sub_menu.append(
  1028. $(
  1029. '<div class="item disabled">' +
  1030. LocalizedStrings.getUI("text_no_variable_instruction") +
  1031. "</div>"
  1032. )
  1033. );
  1034. }
  1035. }
  1036. function addHandlers (
  1037. command,
  1038. ref_object,
  1039. dom_object,
  1040. menu_var_or_value,
  1041. function_obj,
  1042. expression_element
  1043. ) {
  1044. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1045. menu_var_or_value.dropdown({
  1046. onChange: function (value, text, $selectedItem) {
  1047. console.log("S7");
  1048. dom_object.find(".var_name").remove();
  1049. switch ($selectedItem.data("option")) {
  1050. case VAR_OR_VALUE_TYPES.only_function:
  1051. openInputToFunction(
  1052. command,
  1053. ref_object,
  1054. dom_object,
  1055. menu_var_or_value,
  1056. function_obj,
  1057. $($selectedItem).data("function_reference"),
  1058. expression_element
  1059. );
  1060. break;
  1061. case VAR_OR_VALUE_TYPES.only_value:
  1062. openInputToValue(
  1063. command,
  1064. ref_object,
  1065. dom_object,
  1066. menu_var_or_value,
  1067. function_obj,
  1068. expression_element
  1069. );
  1070. break;
  1071. case VAR_OR_VALUE_TYPES.only_variable:
  1072. openInputToVariable(
  1073. command,
  1074. ref_object,
  1075. dom_object,
  1076. menu_var_or_value,
  1077. function_obj,
  1078. $($selectedItem).data("variable_reference"),
  1079. expression_element
  1080. );
  1081. break;
  1082. }
  1083. if ($selectedItem.data("exp")) {
  1084. AttribuitionsManagement.manageExpressionElements(
  1085. command,
  1086. ref_object,
  1087. dom_object,
  1088. menu_var_or_value,
  1089. function_obj,
  1090. $selectedItem,
  1091. expression_element
  1092. );
  1093. }
  1094. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1095. RepeatNTimesManagement.manageExpressionElements(
  1096. command,
  1097. ref_object,
  1098. dom_object,
  1099. menu_var_or_value,
  1100. function_obj,
  1101. $selectedItem,
  1102. expression_element
  1103. );
  1104. }
  1105. },
  1106. selectOnKeydown: false,
  1107. });
  1108. }
  1109. dom_object
  1110. .find(".width-dynamic")
  1111. .on("input", function () {
  1112. const inputWidth = $(this).textWidth() + 10;
  1113. $(this).focus();
  1114. const tmpStr = $(this).val();
  1115. $(this).val("");
  1116. $(this).val(tmpStr);
  1117. $(this).css({
  1118. width: inputWidth,
  1119. });
  1120. })
  1121. .trigger("input");
  1122. if (command.type == Models.COMMAND_TYPES.comment) {
  1123. dom_object.parent().on("click", function (e) {
  1124. dom_object.find(".value_rendered").remove();
  1125. dom_object.find(".value_rendered").empty();
  1126. dom_object.find(".value_rendered").remove();
  1127. dom_object.empty();
  1128. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1129. openInputToValue(
  1130. command,
  1131. ref_object,
  1132. dom_object,
  1133. menu_var_or_value,
  1134. function_obj,
  1135. expression_element
  1136. );
  1137. });
  1138. }
  1139. }
  1140. function openInputToFunction (
  1141. command,
  1142. ref_object,
  1143. dom_object,
  1144. menu_var_or_value,
  1145. function_obj,
  1146. function_selected,
  1147. expression_element
  1148. ) {
  1149. ref_object.function_called = function_selected;
  1150. ref_object.parameters_list = [];
  1151. if (
  1152. function_selected.parameters_list != null &&
  1153. function_selected.parameters_list.length > 0
  1154. ) {
  1155. menu_var_or_value.find(".text").text(" ");
  1156. dom_object.find(".menu_var_or_value_dom").remove();
  1157. var parameters_menu;
  1158. if (function_selected.name) {
  1159. parameters_menu =
  1160. '<div class="parameters_function_called"> ' +
  1161. function_selected.name +
  1162. " <span> ( </span>";
  1163. } else {
  1164. parameters_menu =
  1165. '<div class="parameters_function_called"> <i>' +
  1166. LocalizedStrings.translateInternalFunction(
  1167. function_selected.identifier,
  1168. function_selected.category
  1169. ) +
  1170. "</i> <span> ( </span>";
  1171. }
  1172. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1173. parameters_menu +=
  1174. '<div class="render_style_param parameter_' + j + '"></div>';
  1175. if (j + 1 != function_selected.parameters_list.length) {
  1176. parameters_menu += " , ";
  1177. }
  1178. }
  1179. parameters_menu += "<span> ) </span></div>";
  1180. parameters_menu = $(parameters_menu);
  1181. dom_object.append(parameters_menu);
  1182. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1183. var temp;
  1184. if (function_selected.parameters_list[j].dimensions > 0) {
  1185. temp = new Models.VariableValueMenu(
  1186. VAR_OR_VALUE_TYPES.variable_and_function,
  1187. null,
  1188. null,
  1189. null,
  1190. true,
  1191. function_selected.parameters_list[j].dimensions
  1192. );
  1193. } else {
  1194. temp = new Models.VariableValueMenu(
  1195. VAR_OR_VALUE_TYPES.all,
  1196. null,
  1197. null,
  1198. null,
  1199. true
  1200. );
  1201. }
  1202. ref_object.parameters_list.push(temp);
  1203. renderMenu(
  1204. command,
  1205. temp,
  1206. parameters_menu.find(".parameter_" + j),
  1207. function_obj,
  1208. 2,
  1209. expression_element
  1210. );
  1211. }
  1212. var context_menu =
  1213. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1214. context_menu +=
  1215. '<div class="item" data-clear="true">' +
  1216. LocalizedStrings.getUI("btn_clear") +
  1217. "</div>";
  1218. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1219. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1220. context_menu += '<div class="menu">';
  1221. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1222. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1223. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1224. context_menu += '</div></div>';
  1225. }*/
  1226. context_menu += "</div></div>";
  1227. context_menu = $(context_menu);
  1228. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1229. context_menu.dropdown({
  1230. onChange: function (value, text, $selectedItem) {
  1231. console.log("S8");
  1232. if ($selectedItem.data("clear")) {
  1233. console.log("PP7");
  1234. dom_object.text("");
  1235. ref_object.content = null;
  1236. ref_object.row = null;
  1237. ref_object.column = null;
  1238. delete ref_object.function_called;
  1239. delete ref_object.parameters_list;
  1240. renderMenu(
  1241. command,
  1242. ref_object,
  1243. dom_object,
  1244. function_obj,
  1245. 2,
  1246. expression_element
  1247. );
  1248. }
  1249. if ($selectedItem.data("exp")) {
  1250. AttribuitionsManagement.manageExpressionElements(
  1251. command,
  1252. ref_object,
  1253. dom_object,
  1254. menu_var_or_value,
  1255. function_obj,
  1256. $selectedItem,
  1257. expression_element
  1258. );
  1259. }
  1260. },
  1261. selectOnKeydown: false,
  1262. });
  1263. } else {
  1264. menu_var_or_value.find(".text").text(" ");
  1265. dom_object.find(".menu_var_or_value_dom").remove();
  1266. var parameters_menu;
  1267. if (function_selected.name) {
  1268. parameters_menu =
  1269. '<div class="parameters_function_called"> ' +
  1270. function_selected.name +
  1271. " <span> ( </span>";
  1272. } else {
  1273. parameters_menu =
  1274. '<div class="parameters_function_called"> <i>' +
  1275. LocalizedStrings.translateInternalFunction(
  1276. function_selected.identifier,
  1277. function_selected.category
  1278. ) +
  1279. "</i> <span> ( </span>";
  1280. }
  1281. parameters_menu += "<span> ) </span></div>";
  1282. parameters_menu = $(parameters_menu);
  1283. dom_object.append(parameters_menu);
  1284. var context_menu =
  1285. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1286. context_menu +=
  1287. '<div class="item" data-clear="true">' +
  1288. LocalizedStrings.getUI("btn_clear") +
  1289. "</div>";
  1290. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1291. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1292. context_menu += '<div class="menu">';
  1293. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1294. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1295. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1296. context_menu += '</div></div>';
  1297. }*/
  1298. context_menu += "</div></div>";
  1299. context_menu = $(context_menu);
  1300. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1301. context_menu.dropdown({
  1302. onChange: function (value, text, $selectedItem) {
  1303. console.log("S9");
  1304. if ($selectedItem.data("clear")) {
  1305. console.log("PP8");
  1306. dom_object.text("");
  1307. ref_object.content = null;
  1308. ref_object.row = null;
  1309. ref_object.column = null;
  1310. delete ref_object.function_called;
  1311. delete ref_object.parameters_list;
  1312. renderMenu(
  1313. command,
  1314. ref_object,
  1315. dom_object,
  1316. function_obj,
  1317. 2,
  1318. expression_element
  1319. );
  1320. }
  1321. if ($selectedItem.data("exp")) {
  1322. AttribuitionsManagement.manageExpressionElements(
  1323. command,
  1324. ref_object,
  1325. dom_object,
  1326. menu_var_or_value,
  1327. function_obj,
  1328. $selectedItem,
  1329. expression_element
  1330. );
  1331. }
  1332. },
  1333. selectOnKeydown: false,
  1334. });
  1335. }
  1336. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1337. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1338. }*/
  1339. }
  1340. function openInputToVariable (
  1341. command,
  1342. ref_object,
  1343. dom_object,
  1344. menu_var_or_value,
  1345. function_obj,
  1346. variable_selected,
  1347. expression_element
  1348. ) {
  1349. ref_object.content = variable_selected;
  1350. menu_var_or_value.find(".text").text(" ");
  1351. dom_object.find(".menu_var_or_value_dom").remove();
  1352. let variable_render =
  1353. '<div class="variable_rendered"> <span class="var_name">' +
  1354. variable_selected.name +
  1355. "</span>";
  1356. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1357. variable_render +=
  1358. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1359. }
  1360. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1361. variable_render +=
  1362. ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  1363. variable_render +=
  1364. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1365. }
  1366. variable_render += "</div>";
  1367. variable_render = $(variable_render);
  1368. dom_object.append(variable_render);
  1369. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1370. ref_object.column = new Models.VariableValueMenu(
  1371. VAR_OR_VALUE_TYPES.all,
  1372. null,
  1373. null,
  1374. null,
  1375. true
  1376. );
  1377. renderMenu(
  1378. command,
  1379. ref_object.column,
  1380. variable_render.find(".column_container"),
  1381. function_obj,
  1382. 2,
  1383. expression_element
  1384. );
  1385. }
  1386. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1387. ref_object.row = new Models.VariableValueMenu(
  1388. VAR_OR_VALUE_TYPES.all,
  1389. null,
  1390. null,
  1391. null,
  1392. true
  1393. );
  1394. renderMenu(
  1395. command,
  1396. ref_object.row,
  1397. variable_render.find(".row_container"),
  1398. function_obj,
  1399. 2,
  1400. expression_element
  1401. );
  1402. ref_object.column = new Models.VariableValueMenu(
  1403. VAR_OR_VALUE_TYPES.all,
  1404. null,
  1405. null,
  1406. null,
  1407. true
  1408. );
  1409. renderMenu(
  1410. command,
  1411. ref_object.column,
  1412. variable_render.find(".column_container"),
  1413. function_obj,
  1414. 2,
  1415. expression_element
  1416. );
  1417. }
  1418. let context_menu =
  1419. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1420. context_menu +=
  1421. '<div class="item" data-clear="true">' +
  1422. LocalizedStrings.getUI("btn_clear") +
  1423. "</div>";
  1424. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  1425. console.log("dom_object 10: ");
  1426. console.log(dom_object);
  1427. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1428. context_menu += '<div class="menu">';
  1429. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1430. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1431. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1432. context_menu += '</div></div>';
  1433. }*/
  1434. context_menu += "</div></div>";
  1435. context_menu = $(context_menu);
  1436. context_menu.insertAfter(dom_object.find(".variable_rendered"));
  1437. context_menu.dropdown({
  1438. onChange: function (value, text, $selectedItem) {
  1439. console.log("S10");
  1440. if ($selectedItem.data("clear")) {
  1441. console.log("PP9");
  1442. dom_object.text("");
  1443. ref_object.content = null;
  1444. ref_object.row = null;
  1445. ref_object.column = null;
  1446. delete ref_object.function_called;
  1447. delete ref_object.parameters_list;
  1448. renderMenu(
  1449. command,
  1450. ref_object,
  1451. dom_object,
  1452. function_obj,
  1453. 2,
  1454. expression_element
  1455. );
  1456. }
  1457. if ($selectedItem.data("exp")) {
  1458. AttribuitionsManagement.manageExpressionElements(
  1459. command,
  1460. ref_object,
  1461. dom_object,
  1462. menu_var_or_value,
  1463. function_obj,
  1464. $selectedItem,
  1465. expression_element
  1466. );
  1467. }
  1468. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1469. RepeatNTimesManagement.manageClearExpressionElements(
  1470. command,
  1471. ref_object,
  1472. dom_object,
  1473. menu_var_or_value,
  1474. function_obj,
  1475. $selectedItem,
  1476. expression_element
  1477. );
  1478. }
  1479. },
  1480. selectOnKeydown: false,
  1481. });
  1482. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1483. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  1484. }*/
  1485. }
  1486. function openInputToValue (
  1487. command,
  1488. ref_object,
  1489. dom_object,
  1490. menu_var_or_value,
  1491. function_obj,
  1492. expression_element
  1493. ) {
  1494. if (ref_object.content == null) {
  1495. ref_object.content = "";
  1496. }
  1497. menu_var_or_value.find(".text").text(" ");
  1498. const field = $(
  1499. '<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'
  1500. );
  1501. field.insertBefore(dom_object.find(".menu_var_or_value_dom"));
  1502. const rendered = $('<div class="value_rendered"></div>');
  1503. rendered.insertBefore(field);
  1504. field.focus();
  1505. field.val(ref_object.content);
  1506. let context_menu =
  1507. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1508. context_menu +=
  1509. '<div class="item" data-clear="true">' +
  1510. LocalizedStrings.getUI("btn_clear") +
  1511. "</div>";
  1512. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1513. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1514. context_menu += '<div class="menu">';
  1515. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1516. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1517. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1518. context_menu += '</div></div>';
  1519. }*/
  1520. context_menu += "</div></div>";
  1521. context_menu = $(context_menu);
  1522. dom_object.find(".menu_var_or_value_dom").remove();
  1523. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1524. context_menu.insertAfter(field);
  1525. }
  1526. context_menu.dropdown({
  1527. onChange: function (value, text, $selectedItem) {
  1528. console.log("S11");
  1529. if ($selectedItem.data("clear")) {
  1530. console.log("PP10");
  1531. dom_object.text("");
  1532. dom_object.find(".value_rendered").remove();
  1533. dom_object.find(".context_menu_clear").remove();
  1534. dom_object.find(".width-dynamic-minus").remove();
  1535. ref_object.content = null;
  1536. ref_object.row = null;
  1537. ref_object.column = null;
  1538. delete ref_object.function_called;
  1539. delete ref_object.parameters_list;
  1540. renderMenu(
  1541. command,
  1542. ref_object,
  1543. dom_object,
  1544. function_obj,
  1545. 2,
  1546. expression_element
  1547. );
  1548. }
  1549. if ($selectedItem.data("exp")) {
  1550. AttribuitionsManagement.manageExpressionElements(
  1551. command,
  1552. ref_object,
  1553. dom_object,
  1554. menu_var_or_value,
  1555. function_obj,
  1556. $selectedItem,
  1557. expression_element
  1558. );
  1559. }
  1560. },
  1561. selectOnKeydown: false,
  1562. });
  1563. dom_object.find(".width-dynamic-minus").focusout(function () {
  1564. if (
  1565. $(this)
  1566. .val()
  1567. .trim()
  1568. ) {
  1569. ref_object.content = $(this)
  1570. .val()
  1571. .trim();
  1572. }
  1573. rendered.text(ref_object.content);
  1574. $(this).remove();
  1575. });
  1576. dom_object.find(".width-dynamic-minus").on("keydown", function (e) {
  1577. const code = e.keyCode || e.which;
  1578. if (code == 13) {
  1579. if (
  1580. $(this)
  1581. .val()
  1582. .trim()
  1583. ) {
  1584. ref_object.content = $(this)
  1585. .val()
  1586. .trim();
  1587. }
  1588. rendered.text(ref_object.content);
  1589. $(this).remove();
  1590. }
  1591. if (code == 27) {
  1592. rendered.text(ref_object.content);
  1593. $(this).remove();
  1594. }
  1595. });
  1596. if (command.type == Models.COMMAND_TYPES.comment) {
  1597. /*rendered.parent().on('click', function(e) {
  1598. rendered.parent().off();
  1599. console.log("TTT14");
  1600. rendered.remove();
  1601. rendered.empty();
  1602. rendered.remove();
  1603. dom_object.empty();
  1604. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1605. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  1606. });*/
  1607. }
  1608. rendered.on("click", function (e) {
  1609. console.log("TTT2");
  1610. rendered.empty();
  1611. rendered.remove();
  1612. dom_object.empty();
  1613. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1614. openInputToValue(
  1615. command,
  1616. ref_object,
  1617. dom_object,
  1618. menu_var_or_value,
  1619. function_obj,
  1620. expression_element
  1621. );
  1622. });
  1623. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1624. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1625. }*/
  1626. }
  1627. $.fn.textWidth = function (text, font) {
  1628. if (!$.fn.textWidth.fakeEl)
  1629. $.fn.textWidth.fakeEl = $("<span>")
  1630. .hide()
  1631. .appendTo(document.body);
  1632. $.fn.textWidth.fakeEl
  1633. .text(text || this.val() || this.text() || this.attr("placeholder"))
  1634. .css("font", font || this.css("font"));
  1635. return $.fn.textWidth.fakeEl.width();
  1636. };