variable_value_menu.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  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. variable_render =
  795. '<div class="variable_rendered"> <span class="var_name">';
  796. if (isNaN(variable_obj.content)) {
  797. variable_render += variable_obj.content.replaceAll(" ", "&nbsp;");
  798. } else {
  799. variable_render += variable_obj.content;
  800. }
  801. variable_render += "</span>";
  802. variable_render += "</div>";
  803. variable_render = $(variable_render);
  804. dom_object.append(variable_render);
  805. var context_menu =
  806. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  807. context_menu +=
  808. '<div class="item" data-clear="true">' +
  809. LocalizedStrings.getUI("btn_clear") +
  810. "</div>";
  811. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  812. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  813. context_menu += '<div class="menu">';
  814. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  815. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  816. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  817. context_menu += '</div></div>';
  818. }*/
  819. context_menu += "</div></div>";
  820. context_menu = $(context_menu);
  821. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  822. context_menu.insertAfter(variable_render);
  823. }
  824. context_menu.dropdown({
  825. onChange: function (value, text, $selectedItem) {
  826. console.log("S6");
  827. if ($selectedItem.data("clear")) {
  828. console.log("PP6");
  829. dom_object.text("");
  830. variable_obj.content = null;
  831. variable_obj.row = null;
  832. variable_obj.column = null;
  833. delete variable_obj.function_called;
  834. delete variable_obj.parameters_list;
  835. dom_object.find(".value_rendered").remove();
  836. dom_object.find(".context_menu_clear").remove();
  837. dom_object.find(".width-dynamic-minus").remove();
  838. renderMenu(
  839. command,
  840. variable_obj,
  841. dom_object,
  842. function_obj,
  843. 2,
  844. expression_element
  845. );
  846. }
  847. if ($selectedItem.data("exp")) {
  848. AttribuitionsManagement.manageExpressionElements(
  849. command,
  850. variable_obj,
  851. dom_object,
  852. menu_var_or_value,
  853. function_obj,
  854. $selectedItem,
  855. expression_element
  856. );
  857. }
  858. },
  859. selectOnKeydown: false,
  860. });
  861. variable_render.on("click", function (e) {
  862. variable_render.remove();
  863. variable_render.empty();
  864. variable_render.remove();
  865. dom_object.empty();
  866. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  867. openInputToValue(
  868. command,
  869. variable_obj,
  870. dom_object,
  871. menu_var_or_value,
  872. function_obj,
  873. expression_element
  874. );
  875. });
  876. }
  877. }
  878. function addIVProgFunctionsToMenu (
  879. function_obj,
  880. menu_var_or_value,
  881. ref_object,
  882. expression_element
  883. ) {
  884. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  885. sub_menu.append(
  886. '<div class="divider"></div><div class="header">' +
  887. LocalizedStrings.getUI("text_header_ivprog_functions") +
  888. "</div>"
  889. );
  890. sub_menu.append(
  891. '<div class="item"><i class="dropdown icon"></i>' +
  892. LocalizedStrings.getUI("text_menu_functions_math") +
  893. '<div class="menu menu_math_functions"></div></div>'
  894. );
  895. sub_menu.append(
  896. '<div class="item"><i class="dropdown icon"></i>' +
  897. LocalizedStrings.getUI("text_menu_functions_text") +
  898. '<div class="menu menu_text_functions"></div></div>'
  899. );
  900. sub_menu.append(
  901. '<div class="item"><i class="dropdown icon"></i>' +
  902. LocalizedStrings.getUI("text_menu_functions_array") +
  903. '<div class="menu menu_arrangement_functions"></div></div>'
  904. );
  905. sub_menu.append(
  906. '<div class="item"><i class="dropdown icon"></i>' +
  907. LocalizedStrings.getUI("text_menu_functions_conversion") +
  908. '<div class="menu menu_conversion_functions"></div></div>'
  909. );
  910. // Insert Math functions:
  911. for (let i = 0; i < window.system_functions.length; i++) {
  912. const t = $('<div class="item"></div>');
  913. t.data("function_reference", window.system_functions[i]);
  914. t.data("option", VAR_OR_VALUE_TYPES.only_function);
  915. t.text(
  916. LocalizedStrings.translateInternalFunction(
  917. window.system_functions[i].identifier
  918. )
  919. );
  920. switch (window.system_functions[i].category) {
  921. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  922. sub_menu.find(".menu_math_functions").append(t);
  923. break;
  924. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  925. sub_menu.find(".menu_text_functions").append(t);
  926. break;
  927. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  928. sub_menu.find(".menu_arrangement_functions").append(t);
  929. break;
  930. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  931. sub_menu.find(".menu_conversion_functions").append(t);
  932. break;
  933. }
  934. }
  935. }
  936. function addFunctionsToMenu (
  937. function_obj,
  938. menu_var_or_value,
  939. ref_object,
  940. expression_element
  941. ) {
  942. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  943. sub_menu.text("");
  944. for (let i = 0; i < window.program_obj.functions.length; i++) {
  945. const temp = $(
  946. '<div class="item" data-option="' +
  947. VAR_OR_VALUE_TYPES.only_function +
  948. '">' +
  949. window.program_obj.functions[i].name +
  950. " </div>"
  951. );
  952. temp.data("function_reference", window.program_obj.functions[i]);
  953. sub_menu.append(temp);
  954. }
  955. }
  956. function addVariablesToMenu (
  957. function_obj,
  958. menu_var_or_value,
  959. ref_object,
  960. expression_element
  961. ) {
  962. const sub_menu = menu_var_or_value.find(".menu_only_vars");
  963. sub_menu.text("");
  964. let is_there = false;
  965. if (window.program_obj.globals) {
  966. if (ref_object.include_constant) {
  967. for (var i = 0; i < window.program_obj.globals.length; i++) {
  968. var temp = $(
  969. '<div class="item" data-option="' +
  970. VAR_OR_VALUE_TYPES.only_variable +
  971. '">' +
  972. window.program_obj.globals[i].name +
  973. " </div>"
  974. );
  975. temp.data("variable_reference", window.program_obj.globals[i]);
  976. sub_menu.append(temp);
  977. is_there = true;
  978. }
  979. } else {
  980. for (var i = 0; i < window.program_obj.globals.length; i++) {
  981. if (!window.program_obj.globals[i].is_constant) {
  982. var temp = $(
  983. '<div class="item" data-option="' +
  984. VAR_OR_VALUE_TYPES.only_variable +
  985. '">' +
  986. window.program_obj.globals[i].name +
  987. " </div>"
  988. );
  989. temp.data("variable_reference", window.program_obj.globals[i]);
  990. sub_menu.append(temp);
  991. is_there = true;
  992. }
  993. }
  994. }
  995. }
  996. if (function_obj.parameters_list) {
  997. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  998. var temp = $(
  999. '<div class="item" data-option="' +
  1000. VAR_OR_VALUE_TYPES.only_variable +
  1001. '">' +
  1002. function_obj.parameters_list[i].name +
  1003. " </div>"
  1004. );
  1005. temp.data("variable_reference", function_obj.parameters_list[i]);
  1006. sub_menu.append(temp);
  1007. is_there = true;
  1008. }
  1009. }
  1010. if (function_obj.variables_list) {
  1011. for (var i = 0; i < function_obj.variables_list.length; i++) {
  1012. var temp = $(
  1013. '<div class="item" data-option="' +
  1014. VAR_OR_VALUE_TYPES.only_variable +
  1015. '">' +
  1016. function_obj.variables_list[i].name +
  1017. " </div>"
  1018. );
  1019. temp.data("variable_reference", function_obj.variables_list[i]);
  1020. sub_menu.append(temp);
  1021. is_there = true;
  1022. }
  1023. }
  1024. if (!is_there) {
  1025. sub_menu.append(
  1026. $(
  1027. '<div class="header">' +
  1028. LocalizedStrings.getUI("text_no_variable") +
  1029. "</div>"
  1030. )
  1031. );
  1032. sub_menu.append(
  1033. $(
  1034. '<div class="item disabled">' +
  1035. LocalizedStrings.getUI("text_no_variable_instruction") +
  1036. "</div>"
  1037. )
  1038. );
  1039. }
  1040. }
  1041. function addHandlers (
  1042. command,
  1043. ref_object,
  1044. dom_object,
  1045. menu_var_or_value,
  1046. function_obj,
  1047. expression_element
  1048. ) {
  1049. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1050. menu_var_or_value.dropdown({
  1051. onChange: function (value, text, $selectedItem) {
  1052. console.log("S7");
  1053. dom_object.find(".var_name").remove();
  1054. switch ($selectedItem.data("option")) {
  1055. case VAR_OR_VALUE_TYPES.only_function:
  1056. openInputToFunction(
  1057. command,
  1058. ref_object,
  1059. dom_object,
  1060. menu_var_or_value,
  1061. function_obj,
  1062. $($selectedItem).data("function_reference"),
  1063. expression_element
  1064. );
  1065. break;
  1066. case VAR_OR_VALUE_TYPES.only_value:
  1067. openInputToValue(
  1068. command,
  1069. ref_object,
  1070. dom_object,
  1071. menu_var_or_value,
  1072. function_obj,
  1073. expression_element
  1074. );
  1075. break;
  1076. case VAR_OR_VALUE_TYPES.only_variable:
  1077. openInputToVariable(
  1078. command,
  1079. ref_object,
  1080. dom_object,
  1081. menu_var_or_value,
  1082. function_obj,
  1083. $($selectedItem).data("variable_reference"),
  1084. expression_element
  1085. );
  1086. break;
  1087. }
  1088. if ($selectedItem.data("exp")) {
  1089. AttribuitionsManagement.manageExpressionElements(
  1090. command,
  1091. ref_object,
  1092. dom_object,
  1093. menu_var_or_value,
  1094. function_obj,
  1095. $selectedItem,
  1096. expression_element
  1097. );
  1098. }
  1099. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1100. RepeatNTimesManagement.manageExpressionElements(
  1101. command,
  1102. ref_object,
  1103. dom_object,
  1104. menu_var_or_value,
  1105. function_obj,
  1106. $selectedItem,
  1107. expression_element
  1108. );
  1109. }
  1110. },
  1111. selectOnKeydown: false,
  1112. });
  1113. }
  1114. dom_object
  1115. .find(".width-dynamic")
  1116. .on("input", function () {
  1117. const inputWidth = $(this).textWidth() + 10;
  1118. $(this).focus();
  1119. const tmpStr = $(this).val();
  1120. $(this).val("");
  1121. $(this).val(tmpStr);
  1122. $(this).css({
  1123. width: inputWidth,
  1124. });
  1125. })
  1126. .trigger("input");
  1127. if (command.type == Models.COMMAND_TYPES.comment) {
  1128. dom_object.parent().on("click", function (e) {
  1129. dom_object.find(".value_rendered").remove();
  1130. dom_object.find(".value_rendered").empty();
  1131. dom_object.find(".value_rendered").remove();
  1132. dom_object.empty();
  1133. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1134. openInputToValue(
  1135. command,
  1136. ref_object,
  1137. dom_object,
  1138. menu_var_or_value,
  1139. function_obj,
  1140. expression_element
  1141. );
  1142. });
  1143. }
  1144. }
  1145. function openInputToFunction (
  1146. command,
  1147. ref_object,
  1148. dom_object,
  1149. menu_var_or_value,
  1150. function_obj,
  1151. function_selected,
  1152. expression_element
  1153. ) {
  1154. ref_object.function_called = function_selected;
  1155. ref_object.parameters_list = [];
  1156. if (
  1157. function_selected.parameters_list != null &&
  1158. function_selected.parameters_list.length > 0
  1159. ) {
  1160. menu_var_or_value.find(".text").text(" ");
  1161. dom_object.find(".menu_var_or_value_dom").remove();
  1162. var parameters_menu;
  1163. if (function_selected.name) {
  1164. parameters_menu =
  1165. '<div class="parameters_function_called"> ' +
  1166. function_selected.name +
  1167. " <span> ( </span>";
  1168. } else {
  1169. parameters_menu =
  1170. '<div class="parameters_function_called"> <i>' +
  1171. LocalizedStrings.translateInternalFunction(
  1172. function_selected.identifier,
  1173. function_selected.category
  1174. ) +
  1175. "</i> <span> ( </span>";
  1176. }
  1177. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1178. parameters_menu +=
  1179. '<div class="render_style_param parameter_' + j + '"></div>';
  1180. if (j + 1 != function_selected.parameters_list.length) {
  1181. parameters_menu += " , ";
  1182. }
  1183. }
  1184. parameters_menu += "<span> ) </span></div>";
  1185. parameters_menu = $(parameters_menu);
  1186. dom_object.append(parameters_menu);
  1187. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1188. var temp;
  1189. if (function_selected.parameters_list[j].dimensions > 0) {
  1190. temp = new Models.VariableValueMenu(
  1191. VAR_OR_VALUE_TYPES.variable_and_function,
  1192. null,
  1193. null,
  1194. null,
  1195. true,
  1196. function_selected.parameters_list[j].dimensions
  1197. );
  1198. } else {
  1199. temp = new Models.VariableValueMenu(
  1200. VAR_OR_VALUE_TYPES.all,
  1201. null,
  1202. null,
  1203. null,
  1204. true
  1205. );
  1206. }
  1207. ref_object.parameters_list.push(temp);
  1208. renderMenu(
  1209. command,
  1210. temp,
  1211. parameters_menu.find(".parameter_" + j),
  1212. function_obj,
  1213. 2,
  1214. expression_element
  1215. );
  1216. }
  1217. var context_menu =
  1218. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1219. context_menu +=
  1220. '<div class="item" data-clear="true">' +
  1221. LocalizedStrings.getUI("btn_clear") +
  1222. "</div>";
  1223. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1224. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1225. context_menu += '<div class="menu">';
  1226. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1227. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1228. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1229. context_menu += '</div></div>';
  1230. }*/
  1231. context_menu += "</div></div>";
  1232. context_menu = $(context_menu);
  1233. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1234. context_menu.dropdown({
  1235. onChange: function (value, text, $selectedItem) {
  1236. console.log("S8");
  1237. if ($selectedItem.data("clear")) {
  1238. console.log("PP7");
  1239. dom_object.text("");
  1240. ref_object.content = null;
  1241. ref_object.row = null;
  1242. ref_object.column = null;
  1243. delete ref_object.function_called;
  1244. delete ref_object.parameters_list;
  1245. renderMenu(
  1246. command,
  1247. ref_object,
  1248. dom_object,
  1249. function_obj,
  1250. 2,
  1251. expression_element
  1252. );
  1253. }
  1254. if ($selectedItem.data("exp")) {
  1255. AttribuitionsManagement.manageExpressionElements(
  1256. command,
  1257. ref_object,
  1258. dom_object,
  1259. menu_var_or_value,
  1260. function_obj,
  1261. $selectedItem,
  1262. expression_element
  1263. );
  1264. }
  1265. },
  1266. selectOnKeydown: false,
  1267. });
  1268. } else {
  1269. menu_var_or_value.find(".text").text(" ");
  1270. dom_object.find(".menu_var_or_value_dom").remove();
  1271. var parameters_menu;
  1272. if (function_selected.name) {
  1273. parameters_menu =
  1274. '<div class="parameters_function_called"> ' +
  1275. function_selected.name +
  1276. " <span> ( </span>";
  1277. } else {
  1278. parameters_menu =
  1279. '<div class="parameters_function_called"> <i>' +
  1280. LocalizedStrings.translateInternalFunction(
  1281. function_selected.identifier,
  1282. function_selected.category
  1283. ) +
  1284. "</i> <span> ( </span>";
  1285. }
  1286. parameters_menu += "<span> ) </span></div>";
  1287. parameters_menu = $(parameters_menu);
  1288. dom_object.append(parameters_menu);
  1289. var context_menu =
  1290. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1291. context_menu +=
  1292. '<div class="item" data-clear="true">' +
  1293. LocalizedStrings.getUI("btn_clear") +
  1294. "</div>";
  1295. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1296. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1297. context_menu += '<div class="menu">';
  1298. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1299. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1300. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1301. context_menu += '</div></div>';
  1302. }*/
  1303. context_menu += "</div></div>";
  1304. context_menu = $(context_menu);
  1305. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1306. context_menu.dropdown({
  1307. onChange: function (value, text, $selectedItem) {
  1308. console.log("S9");
  1309. if ($selectedItem.data("clear")) {
  1310. console.log("PP8");
  1311. dom_object.text("");
  1312. ref_object.content = null;
  1313. ref_object.row = null;
  1314. ref_object.column = null;
  1315. delete ref_object.function_called;
  1316. delete ref_object.parameters_list;
  1317. renderMenu(
  1318. command,
  1319. ref_object,
  1320. dom_object,
  1321. function_obj,
  1322. 2,
  1323. expression_element
  1324. );
  1325. }
  1326. if ($selectedItem.data("exp")) {
  1327. AttribuitionsManagement.manageExpressionElements(
  1328. command,
  1329. ref_object,
  1330. dom_object,
  1331. menu_var_or_value,
  1332. function_obj,
  1333. $selectedItem,
  1334. expression_element
  1335. );
  1336. }
  1337. },
  1338. selectOnKeydown: false,
  1339. });
  1340. }
  1341. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1342. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1343. }*/
  1344. }
  1345. function openInputToVariable (
  1346. command,
  1347. ref_object,
  1348. dom_object,
  1349. menu_var_or_value,
  1350. function_obj,
  1351. variable_selected,
  1352. expression_element
  1353. ) {
  1354. ref_object.content = variable_selected;
  1355. menu_var_or_value.find(".text").text(" ");
  1356. dom_object.find(".menu_var_or_value_dom").remove();
  1357. let variable_render =
  1358. '<div class="variable_rendered"> <span class="var_name">' +
  1359. variable_selected.name +
  1360. "</span>";
  1361. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1362. variable_render +=
  1363. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1364. }
  1365. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1366. variable_render +=
  1367. ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  1368. variable_render +=
  1369. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1370. }
  1371. variable_render += "</div>";
  1372. variable_render = $(variable_render);
  1373. dom_object.append(variable_render);
  1374. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1375. ref_object.column = new Models.VariableValueMenu(
  1376. VAR_OR_VALUE_TYPES.all,
  1377. null,
  1378. null,
  1379. null,
  1380. true
  1381. );
  1382. renderMenu(
  1383. command,
  1384. ref_object.column,
  1385. variable_render.find(".column_container"),
  1386. function_obj,
  1387. 2,
  1388. expression_element
  1389. );
  1390. }
  1391. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1392. ref_object.row = new Models.VariableValueMenu(
  1393. VAR_OR_VALUE_TYPES.all,
  1394. null,
  1395. null,
  1396. null,
  1397. true
  1398. );
  1399. renderMenu(
  1400. command,
  1401. ref_object.row,
  1402. variable_render.find(".row_container"),
  1403. function_obj,
  1404. 2,
  1405. expression_element
  1406. );
  1407. ref_object.column = new Models.VariableValueMenu(
  1408. VAR_OR_VALUE_TYPES.all,
  1409. null,
  1410. null,
  1411. null,
  1412. true
  1413. );
  1414. renderMenu(
  1415. command,
  1416. ref_object.column,
  1417. variable_render.find(".column_container"),
  1418. function_obj,
  1419. 2,
  1420. expression_element
  1421. );
  1422. }
  1423. let context_menu =
  1424. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1425. context_menu +=
  1426. '<div class="item" data-clear="true">' +
  1427. LocalizedStrings.getUI("btn_clear") +
  1428. "</div>";
  1429. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  1430. console.log("dom_object 10: ");
  1431. console.log(dom_object);
  1432. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1433. context_menu += '<div class="menu">';
  1434. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1435. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1436. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1437. context_menu += '</div></div>';
  1438. }*/
  1439. context_menu += "</div></div>";
  1440. context_menu = $(context_menu);
  1441. context_menu.insertAfter(dom_object.find(".variable_rendered"));
  1442. context_menu.dropdown({
  1443. onChange: function (value, text, $selectedItem) {
  1444. console.log("S10");
  1445. if ($selectedItem.data("clear")) {
  1446. console.log("PP9");
  1447. dom_object.text("");
  1448. ref_object.content = null;
  1449. ref_object.row = null;
  1450. ref_object.column = null;
  1451. delete ref_object.function_called;
  1452. delete ref_object.parameters_list;
  1453. renderMenu(
  1454. command,
  1455. ref_object,
  1456. dom_object,
  1457. function_obj,
  1458. 2,
  1459. expression_element
  1460. );
  1461. }
  1462. if ($selectedItem.data("exp")) {
  1463. AttribuitionsManagement.manageExpressionElements(
  1464. command,
  1465. ref_object,
  1466. dom_object,
  1467. menu_var_or_value,
  1468. function_obj,
  1469. $selectedItem,
  1470. expression_element
  1471. );
  1472. }
  1473. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1474. RepeatNTimesManagement.manageClearExpressionElements(
  1475. command,
  1476. ref_object,
  1477. dom_object,
  1478. menu_var_or_value,
  1479. function_obj,
  1480. $selectedItem,
  1481. expression_element
  1482. );
  1483. }
  1484. },
  1485. selectOnKeydown: false,
  1486. });
  1487. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1488. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  1489. }*/
  1490. }
  1491. function openInputToValue (
  1492. command,
  1493. ref_object,
  1494. dom_object,
  1495. menu_var_or_value,
  1496. function_obj,
  1497. expression_element
  1498. ) {
  1499. if (ref_object.content == null) {
  1500. ref_object.content = "";
  1501. }
  1502. menu_var_or_value.find(".text").text(" ");
  1503. const field = $(
  1504. '<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'
  1505. );
  1506. field.insertBefore(dom_object.find(".menu_var_or_value_dom"));
  1507. const rendered = $('<div class="value_rendered"></div>');
  1508. rendered.insertBefore(field);
  1509. field.focus();
  1510. field.val(ref_object.content);
  1511. let context_menu =
  1512. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1513. context_menu +=
  1514. '<div class="item" data-clear="true">' +
  1515. LocalizedStrings.getUI("btn_clear") +
  1516. "</div>";
  1517. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1518. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1519. context_menu += '<div class="menu">';
  1520. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1521. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1522. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1523. context_menu += '</div></div>';
  1524. }*/
  1525. context_menu += "</div></div>";
  1526. context_menu = $(context_menu);
  1527. dom_object.find(".menu_var_or_value_dom").remove();
  1528. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1529. context_menu.insertAfter(field);
  1530. }
  1531. context_menu.dropdown({
  1532. onChange: function (value, text, $selectedItem) {
  1533. if ($selectedItem.data("clear")) {
  1534. dom_object.text("");
  1535. dom_object.find(".value_rendered").remove();
  1536. dom_object.find(".context_menu_clear").remove();
  1537. dom_object.find(".width-dynamic-minus").remove();
  1538. ref_object.content = null;
  1539. ref_object.row = null;
  1540. ref_object.column = null;
  1541. delete ref_object.function_called;
  1542. delete ref_object.parameters_list;
  1543. renderMenu(
  1544. command,
  1545. ref_object,
  1546. dom_object,
  1547. function_obj,
  1548. 2,
  1549. expression_element
  1550. );
  1551. }
  1552. if ($selectedItem.data("exp")) {
  1553. AttribuitionsManagement.manageExpressionElements(
  1554. command,
  1555. ref_object,
  1556. dom_object,
  1557. menu_var_or_value,
  1558. function_obj,
  1559. $selectedItem,
  1560. expression_element
  1561. );
  1562. }
  1563. },
  1564. selectOnKeydown: false,
  1565. });
  1566. dom_object.find(".width-dynamic-minus").focusout(function () {
  1567. /*if (
  1568. $(this)
  1569. .val()
  1570. .trim()
  1571. ) {
  1572. ref_object.content = $(this)
  1573. .val()
  1574. .trim();
  1575. }*/
  1576. ref_object.content = $(this)
  1577. .val();
  1578. if (isNaN(ref_object.content)) {
  1579. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1580. } else {
  1581. rendered.text(ref_object.content);
  1582. }
  1583. $(this).remove();
  1584. });
  1585. dom_object.find(".width-dynamic-minus").on("keydown", function (e) {
  1586. const code = e.keyCode || e.which;
  1587. if (code == 13) {
  1588. /*if (
  1589. $(this)
  1590. .val()
  1591. .trim()
  1592. ) {
  1593. ref_object.content = $(this)
  1594. .val()
  1595. .trim();
  1596. }*/
  1597. ref_object.content = $(this)
  1598. .val();
  1599. if (isNaN(ref_object.content)) {
  1600. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1601. } else {
  1602. rendered.text(ref_object.content);
  1603. }
  1604. $(this).remove();
  1605. }
  1606. if (code == 27) {
  1607. if (isNaN(ref_object.content)) {
  1608. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1609. } else {
  1610. rendered.text(ref_object.content);
  1611. }
  1612. $(this).remove();
  1613. }
  1614. });
  1615. if (command.type == Models.COMMAND_TYPES.comment) {
  1616. /*rendered.parent().on('click', function(e) {
  1617. rendered.parent().off();
  1618. console.log("TTT14");
  1619. rendered.remove();
  1620. rendered.empty();
  1621. rendered.remove();
  1622. dom_object.empty();
  1623. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1624. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  1625. });*/
  1626. }
  1627. rendered.on("click", function (e) {
  1628. console.log("TTT2");
  1629. rendered.empty();
  1630. rendered.remove();
  1631. dom_object.empty();
  1632. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1633. openInputToValue(
  1634. command,
  1635. ref_object,
  1636. dom_object,
  1637. menu_var_or_value,
  1638. function_obj,
  1639. expression_element
  1640. );
  1641. });
  1642. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1643. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1644. }*/
  1645. }
  1646. $.fn.textWidth = function (text, font) {
  1647. if (!$.fn.textWidth.fakeEl)
  1648. $.fn.textWidth.fakeEl = $("<span>")
  1649. .hide()
  1650. .appendTo(document.body);
  1651. $.fn.textWidth.fakeEl
  1652. .text(text || this.val() || this.text() || this.attr("placeholder"))
  1653. .css("font", font || this.css("font"));
  1654. return $.fn.textWidth.fakeEl.width();
  1655. };