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. menu_var_or_value.find('.width-dynamic').on('input', function() {
  118. var input_field = $(this);
  119. var inputWidth = input_field.textWidth()+10;
  120. inputWidth = inputWidth<50?50:inputWidth;
  121. input_field.css({
  122. width: inputWidth
  123. })
  124. }).trigger('input');
  125. dom_object.append(menu_var_or_value);
  126. ref_object.dom_object = menu_var_or_value;
  127. addHandlers(
  128. command,
  129. ref_object,
  130. dom_object,
  131. menu_var_or_value,
  132. function_obj,
  133. expression_element
  134. );
  135. addVariablesToMenu(
  136. function_obj,
  137. menu_var_or_value,
  138. ref_object,
  139. expression_element
  140. );
  141. addFunctionsToMenu(
  142. function_obj,
  143. menu_var_or_value,
  144. ref_object,
  145. expression_element
  146. );
  147. addIVProgFunctionsToMenu(
  148. function_obj,
  149. menu_var_or_value,
  150. ref_object,
  151. expression_element
  152. );
  153. if (ref_object.content || ref_object.function_called) {
  154. if (ref_object.content) {
  155. // Verificar se a variável ainda existe:
  156. const variable_fun = isVarInProgram(ref_object.content, function_obj);
  157. if (variable_fun) {
  158. ref_object.content = variable_fun;
  159. renderPreviousContent(
  160. function_obj,
  161. menu_var_or_value,
  162. ref_object,
  163. dom_object,
  164. command,
  165. expression_element
  166. );
  167. } else {
  168. if (ref_object.content && ref_object.content.type) {
  169. ref_object.content = null;
  170. appendSelectText(ref_object, menu_var_or_value);
  171. } else {
  172. renderPreviousContent(
  173. function_obj,
  174. menu_var_or_value,
  175. ref_object,
  176. dom_object,
  177. command,
  178. expression_element
  179. );
  180. }
  181. }
  182. } else if (ref_object.function_called) {
  183. // Verificar se a função ainda existe:
  184. const ret_function = isFunctionInProgram(ref_object.function_called);
  185. if (ret_function) {
  186. ref_object.function_called = ret_function;
  187. renderPreviousContent(
  188. function_obj,
  189. menu_var_or_value,
  190. ref_object,
  191. dom_object,
  192. command,
  193. expression_element
  194. );
  195. } else {
  196. ref_object.content = null;
  197. ref_object.row = null;
  198. ref_object.column = null;
  199. delete ref_object.function_called;
  200. delete ref_object.parameters_list;
  201. appendSelectText(ref_object, menu_var_or_value);
  202. }
  203. }
  204. } else {
  205. appendSelectText(ref_object, menu_var_or_value);
  206. }
  207. }
  208. function appendSelectText (ref_object, menu_var_or_value) {
  209. switch (ref_object.variable_and_value) {
  210. case VAR_OR_VALUE_TYPES.only_variable:
  211. menu_var_or_value
  212. .find(".text")
  213. .append("<i>" + LocalizedStrings.getUI("var_menu_select_var") + "</i>");
  214. break;
  215. case VAR_OR_VALUE_TYPES.all:
  216. menu_var_or_value
  217. .find(".text")
  218. .append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  219. break;
  220. case VAR_OR_VALUE_TYPES.variable_and_function:
  221. menu_var_or_value
  222. .find(".text")
  223. .append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  224. break;
  225. case VAR_OR_VALUE_TYPES.only_function:
  226. menu_var_or_value
  227. .find(".text")
  228. .append(
  229. "<i>" + LocalizedStrings.getUI("var_menu_select_function") + "</i>"
  230. );
  231. break;
  232. }
  233. }
  234. function isFunctionInProgram (function_called_obj) {
  235. if (function_called_obj.name) {
  236. if (window.program_obj.functions) {
  237. for (var i = 0; i < window.program_obj.functions.length; i++) {
  238. if (window.program_obj.functions[i] == function_called_obj) {
  239. return window.program_obj.functions[i];
  240. }
  241. }
  242. for (var i = 0; i < window.program_obj.functions.length; i++) {
  243. if (window.program_obj.functions[i].name == function_called_obj.name) {
  244. return window.program_obj.functions[i];
  245. }
  246. }
  247. }
  248. } else if (function_called_obj.identifier) {
  249. for (var i = 0; i < window.system_functions.length; i++) {
  250. if (
  251. window.system_functions[i].identifier == function_called_obj.identifier
  252. ) {
  253. return window.system_functions[i];
  254. }
  255. }
  256. }
  257. return null;
  258. }
  259. function isVarInProgram (var_obj, function_obj) {
  260. // Verify in locals:
  261. if (function_obj.variables_list) {
  262. for (var i = 0; i < function_obj.variables_list.length; i++) {
  263. if (function_obj.variables_list[i] == var_obj) {
  264. return function_obj.variables_list[i];
  265. }
  266. }
  267. }
  268. // Verify in parameters:
  269. if (function_obj.parameters_list) {
  270. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  271. if (function_obj.parameters_list[i] == var_obj) {
  272. return function_obj.parameters_list[i];
  273. }
  274. }
  275. }
  276. // Verify in globals:
  277. if (window.program_obj.globals) {
  278. for (var i = 0; i < window.program_obj.globals.length; i++) {
  279. if (window.program_obj.globals[i] == var_obj) {
  280. return window.program_obj.globals[i];
  281. }
  282. }
  283. }
  284. // If not found, verify if the reference was lost
  285. if (var_obj) {
  286. if (function_obj.variables_list) {
  287. for (var i = 0; i < function_obj.variables_list.length; i++) {
  288. if (function_obj.variables_list[i].name == var_obj.name) {
  289. return function_obj.variables_list[i];
  290. }
  291. }
  292. }
  293. if (function_obj.parameters_list) {
  294. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  295. if (function_obj.parameters_list[i].name == var_obj.name) {
  296. return function_obj.parameters_list[i];
  297. }
  298. }
  299. }
  300. if (window.program_obj.globals) {
  301. for (var i = 0; i < window.program_obj.globals.length; i++) {
  302. if (window.program_obj.globals[i].name == var_obj.name) {
  303. return window.program_obj.globals[i];
  304. }
  305. }
  306. }
  307. }
  308. return null;
  309. }
  310. function renderPreviousContent (
  311. function_obj,
  312. menu_var_or_value,
  313. ref_object,
  314. dom_object,
  315. command,
  316. expression_element
  317. ) {
  318. if (ref_object.function_called) {
  319. menu_var_or_value.remove();
  320. variableValueMenuCode(
  321. command,
  322. ref_object,
  323. dom_object,
  324. function_obj,
  325. menu_var_or_value,
  326. expression_element
  327. );
  328. } else if (ref_object.content.type) {
  329. menu_var_or_value.remove();
  330. variableValueMenuCode(
  331. command,
  332. ref_object,
  333. dom_object,
  334. function_obj,
  335. menu_var_or_value,
  336. expression_element
  337. );
  338. } else {
  339. menu_var_or_value.remove();
  340. variableValueMenuCode(
  341. command,
  342. ref_object,
  343. dom_object,
  344. function_obj,
  345. menu_var_or_value,
  346. expression_element
  347. );
  348. }
  349. }
  350. function variableValueMenuCode (
  351. command,
  352. variable_obj,
  353. dom_object,
  354. function_obj,
  355. menu_var_or_value,
  356. expression_element
  357. ) {
  358. if (variable_obj.content || variable_obj.function_called) {
  359. // Verificar se a variável ainda existe:
  360. const var_fun = isVarInProgram(variable_obj.content, function_obj);
  361. if (var_fun) {
  362. variable_obj.content = var_fun;
  363. } else {
  364. if (variable_obj.content && variable_obj.content.type) {
  365. variable_obj.content = null;
  366. appendSelectText(variable_obj, menu_var_or_value);
  367. }
  368. }
  369. } else {
  370. appendSelectText(variable_obj, menu_var_or_value);
  371. }
  372. if (variable_obj.content == null && variable_obj.function_called == null) {
  373. renderMenu(
  374. command,
  375. variable_obj,
  376. dom_object,
  377. function_obj,
  378. 2,
  379. expression_element
  380. );
  381. return;
  382. }
  383. const ret = "";
  384. if (variable_obj.function_called) {
  385. if (
  386. variable_obj.function_called.parameters_list == null ||
  387. variable_obj.function_called.length == 0
  388. ) {
  389. menu_var_or_value.find(".text").text(" ");
  390. dom_object.find(".menu_var_or_value_dom").remove();
  391. var parameters_menu;
  392. if (variable_obj.function_called.name) {
  393. parameters_menu =
  394. '<div class="parameters_function_called"> ' +
  395. variable_obj.function_called.name +
  396. " <span> ( </span>";
  397. } else {
  398. parameters_menu =
  399. '<div class="parameters_function_called"> <i>' +
  400. LocalizedStrings.translateInternalFunction(
  401. variable_obj.function_called.identifier,
  402. variable_obj.function_called.category
  403. ) +
  404. "</i> <span> ( </span>";
  405. }
  406. parameters_menu += "<span> ) </span></div>";
  407. parameters_menu = $(parameters_menu);
  408. dom_object.append(parameters_menu);
  409. var context_menu =
  410. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  411. context_menu +=
  412. '<div class="item" data-clear="true">' +
  413. LocalizedStrings.getUI("btn_clear") +
  414. "</div>";
  415. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  416. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  417. context_menu += '<div class="menu">';
  418. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  419. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  420. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  421. context_menu += '</div></div>';
  422. }*/
  423. context_menu += "</div></div>";
  424. context_menu = $(context_menu);
  425. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  426. context_menu.dropdown({
  427. onChange: function (value, text, $selectedItem) {
  428. if ($selectedItem.data("clear")) {
  429. dom_object.text("");
  430. variable_obj.content = null;
  431. variable_obj.row = null;
  432. variable_obj.column = null;
  433. delete variable_obj.function_called;
  434. delete variable_obj.parameters_list;
  435. renderMenu(
  436. command,
  437. variable_obj,
  438. dom_object,
  439. function_obj,
  440. 2,
  441. expression_element
  442. );
  443. }
  444. if ($selectedItem.data("exp")) {
  445. AttribuitionsManagement.manageExpressionElements(
  446. command,
  447. variable_obj,
  448. dom_object,
  449. menu_var_or_value,
  450. function_obj,
  451. $selectedItem,
  452. expression_element
  453. );
  454. }
  455. },
  456. selectOnKeydown: false,
  457. });
  458. } else {
  459. menu_var_or_value.find(".text").text(" ");
  460. dom_object.find(".menu_var_or_value_dom").remove();
  461. var parameters_menu;
  462. if (variable_obj.function_called.name) {
  463. parameters_menu =
  464. '<div class="parameters_function_called"> ' +
  465. variable_obj.function_called.name +
  466. " <span> ( </span>";
  467. } else {
  468. parameters_menu =
  469. '<div class="parameters_function_called"> <i>' +
  470. LocalizedStrings.translateInternalFunction(
  471. variable_obj.function_called.identifier,
  472. variable_obj.function_called.category
  473. ) +
  474. "</i> <span> ( </span>";
  475. }
  476. for (
  477. let j = 0;
  478. j < variable_obj.function_called.parameters_list.length;
  479. j++
  480. ) {
  481. parameters_menu +=
  482. '<div class="render_style_param parameter_' + j + '"></div>';
  483. if (j + 1 != variable_obj.function_called.parameters_list.length) {
  484. parameters_menu += " , ";
  485. }
  486. }
  487. parameters_menu += "<span> ) </span></div>";
  488. parameters_menu = $(parameters_menu);
  489. dom_object.append(parameters_menu);
  490. for (
  491. let j = 0;
  492. j < variable_obj.function_called.parameters_list.length;
  493. j++
  494. ) {
  495. renderMenu(
  496. command,
  497. variable_obj.parameters_list[j],
  498. parameters_menu.find(".parameter_" + j),
  499. function_obj,
  500. 2,
  501. expression_element
  502. );
  503. }
  504. let context_menu =
  505. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  506. context_menu +=
  507. '<div class="item" data-clear="true">' +
  508. LocalizedStrings.getUI("btn_clear") +
  509. "</div>";
  510. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  511. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  512. context_menu += '<div class="menu">';
  513. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  514. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  515. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  516. context_menu += '</div></div>';
  517. }*/
  518. context_menu += "</div></div>";
  519. context_menu = $(context_menu);
  520. context_menu.insertAfter(parameters_menu);
  521. context_menu.dropdown({
  522. onChange: function (value, text, $selectedItem) {
  523. if ($selectedItem.data("clear")) {
  524. dom_object.text("");
  525. variable_obj.content = null;
  526. variable_obj.row = null;
  527. variable_obj.column = null;
  528. delete variable_obj.function_called;
  529. delete variable_obj.parameters_list;
  530. renderMenu(
  531. command,
  532. variable_obj,
  533. dom_object,
  534. function_obj,
  535. 2,
  536. expression_element
  537. );
  538. }
  539. if ($selectedItem.data("exp")) {
  540. AttribuitionsManagement.manageExpressionElements(
  541. command,
  542. variable_obj,
  543. dom_object,
  544. menu_var_or_value,
  545. function_obj,
  546. $selectedItem,
  547. expression_element
  548. );
  549. }
  550. },
  551. selectOnKeydown: false,
  552. });
  553. }
  554. } else if (variable_obj.content.type) {
  555. let variable_render = "";
  556. if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
  557. variable_render =
  558. '<div class="variable_rendered"> <span class="var_name">' +
  559. variable_obj.content.name +
  560. "</span>";
  561. variable_render +=
  562. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  563. variable_render += "</div>";
  564. variable_render = $(variable_render);
  565. dom_object.append(variable_render);
  566. let context_menu =
  567. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  568. context_menu +=
  569. '<div class="item" data-clear="true">' +
  570. LocalizedStrings.getUI("btn_clear") +
  571. "</div>";
  572. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  573. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  574. context_menu += '<div class="menu">';
  575. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  576. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  577. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  578. context_menu += '</div></div>';
  579. }*/
  580. context_menu += "</div></div>";
  581. context_menu = $(context_menu);
  582. variable_render.append(context_menu);
  583. context_menu.dropdown({
  584. onChange: function (value, text, $selectedItem) {
  585. if ($selectedItem.data("clear")) {
  586. dom_object.text("");
  587. variable_obj.content = null;
  588. variable_obj.row = null;
  589. variable_obj.column = null;
  590. delete variable_obj.function_called;
  591. delete variable_obj.parameters_list;
  592. renderMenu(
  593. command,
  594. variable_obj,
  595. dom_object,
  596. function_obj,
  597. 2,
  598. expression_element
  599. );
  600. }
  601. if ($selectedItem.data("exp")) {
  602. AttribuitionsManagement.manageExpressionElements(
  603. command,
  604. variable_obj,
  605. dom_object,
  606. menu_var_or_value,
  607. function_obj,
  608. $selectedItem,
  609. expression_element
  610. );
  611. }
  612. },
  613. selectOnKeydown: false,
  614. });
  615. if (!variable_obj.column) {
  616. variable_obj.column = new Models.VariableValueMenu(
  617. VAR_OR_VALUE_TYPES.all,
  618. null,
  619. null,
  620. null,
  621. true
  622. );
  623. }
  624. variableValueMenuCode(
  625. command,
  626. variable_obj.column,
  627. $(variable_render.find(".column_container")),
  628. function_obj,
  629. menu_var_or_value,
  630. expression_element
  631. );
  632. } else if (
  633. variable_obj.content.dimensions == 2 &&
  634. variable_obj.dimensions != 2
  635. ) {
  636. variable_render =
  637. '<div class="variable_rendered"> <span class="var_name">' +
  638. variable_obj.content.name +
  639. "</span>";
  640. variable_render +=
  641. ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  642. variable_render +=
  643. ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  644. variable_render += "</div>";
  645. variable_render = $(variable_render);
  646. dom_object.append(variable_render);
  647. let context_menu =
  648. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  649. context_menu +=
  650. '<div class="item" data-clear="true">' +
  651. LocalizedStrings.getUI("btn_clear") +
  652. "</div>";
  653. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  654. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  655. context_menu += '<div class="menu">';
  656. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  657. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  658. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  659. context_menu += '</div></div>';
  660. }*/
  661. context_menu += "</div></div>";
  662. context_menu = $(context_menu);
  663. variable_render.append(context_menu);
  664. context_menu.dropdown({
  665. onChange: function (value, text, $selectedItem) {
  666. if ($selectedItem.data("clear")) {
  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. if ($selectedItem.data("clear")) {
  760. dom_object.text("");
  761. variable_obj.content = null;
  762. variable_obj.row = null;
  763. variable_obj.column = null;
  764. delete variable_obj.function_called;
  765. delete variable_obj.parameters_list;
  766. renderMenu(
  767. command,
  768. variable_obj,
  769. dom_object,
  770. function_obj,
  771. 2,
  772. expression_element
  773. );
  774. }
  775. if ($selectedItem.data("exp")) {
  776. AttribuitionsManagement.manageExpressionElements(
  777. command,
  778. variable_obj,
  779. dom_object,
  780. menu_var_or_value,
  781. function_obj,
  782. $selectedItem,
  783. expression_element
  784. );
  785. }
  786. },
  787. selectOnKeydown: false,
  788. });
  789. }
  790. } else {
  791. let variable_render;
  792. variable_render =
  793. '<div class="variable_rendered"> <span class="var_name">';
  794. if (isNaN(variable_obj.content)) {
  795. variable_render += variable_obj.content.split(" ").join("&nbsp;");
  796. } else {
  797. variable_render += variable_obj.content;
  798. }
  799. variable_render += "</span>";
  800. variable_render += "</div>";
  801. variable_render = $(variable_render);
  802. dom_object.append(variable_render);
  803. var context_menu =
  804. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  805. context_menu +=
  806. '<div class="item" data-clear="true">' +
  807. LocalizedStrings.getUI("btn_clear") +
  808. "</div>";
  809. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  810. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  811. context_menu += '<div class="menu">';
  812. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  813. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  814. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  815. context_menu += '</div></div>';
  816. }*/
  817. context_menu += "</div></div>";
  818. context_menu = $(context_menu);
  819. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  820. context_menu.insertAfter(variable_render);
  821. }
  822. context_menu.dropdown({
  823. onChange: function (value, text, $selectedItem) {
  824. if ($selectedItem.data("clear")) {
  825. dom_object.text("");
  826. variable_obj.content = null;
  827. variable_obj.row = null;
  828. variable_obj.column = null;
  829. delete variable_obj.function_called;
  830. delete variable_obj.parameters_list;
  831. dom_object.find(".value_rendered").remove();
  832. dom_object.find(".context_menu_clear").remove();
  833. dom_object.find(".width-dynamic-minus").remove();
  834. renderMenu(
  835. command,
  836. variable_obj,
  837. dom_object,
  838. function_obj,
  839. 2,
  840. expression_element
  841. );
  842. }
  843. if ($selectedItem.data("exp")) {
  844. AttribuitionsManagement.manageExpressionElements(
  845. command,
  846. variable_obj,
  847. dom_object,
  848. menu_var_or_value,
  849. function_obj,
  850. $selectedItem,
  851. expression_element
  852. );
  853. }
  854. },
  855. selectOnKeydown: false,
  856. });
  857. variable_render.on("click", function (e) {
  858. variable_render.remove();
  859. variable_render.empty();
  860. variable_render.remove();
  861. dom_object.empty();
  862. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  863. openInputToValue(
  864. command,
  865. variable_obj,
  866. dom_object,
  867. menu_var_or_value,
  868. function_obj,
  869. expression_element
  870. );
  871. });
  872. }
  873. }
  874. function addIVProgFunctionsToMenu (
  875. function_obj,
  876. menu_var_or_value,
  877. ref_object,
  878. expression_element
  879. ) {
  880. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  881. sub_menu.append(
  882. '<div class="divider"></div><div class="header">' +
  883. LocalizedStrings.getUI("text_header_ivprog_functions") +
  884. "</div>"
  885. );
  886. sub_menu.append(
  887. '<div class="item"><i class="dropdown icon"></i>' +
  888. LocalizedStrings.getUI("text_menu_functions_math") +
  889. '<div class="menu menu_math_functions"></div></div>'
  890. );
  891. sub_menu.append(
  892. '<div class="item"><i class="dropdown icon"></i>' +
  893. LocalizedStrings.getUI("text_menu_functions_text") +
  894. '<div class="menu menu_text_functions"></div></div>'
  895. );
  896. sub_menu.append(
  897. '<div class="item"><i class="dropdown icon"></i>' +
  898. LocalizedStrings.getUI("text_menu_functions_array") +
  899. '<div class="menu menu_arrangement_functions"></div></div>'
  900. );
  901. sub_menu.append(
  902. '<div class="item"><i class="dropdown icon"></i>' +
  903. LocalizedStrings.getUI("text_menu_functions_conversion") +
  904. '<div class="menu menu_conversion_functions"></div></div>'
  905. );
  906. // Insert Math functions:
  907. for (let i = 0; i < window.system_functions.length; i++) {
  908. const t = $('<div class="item"></div>');
  909. t.data("function_reference", window.system_functions[i]);
  910. t.data("option", VAR_OR_VALUE_TYPES.only_function);
  911. t.text(
  912. LocalizedStrings.translateInternalFunction(
  913. window.system_functions[i].identifier
  914. )
  915. );
  916. switch (window.system_functions[i].category) {
  917. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  918. sub_menu.find(".menu_math_functions").append(t);
  919. break;
  920. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  921. sub_menu.find(".menu_text_functions").append(t);
  922. break;
  923. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  924. sub_menu.find(".menu_arrangement_functions").append(t);
  925. break;
  926. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  927. sub_menu.find(".menu_conversion_functions").append(t);
  928. break;
  929. }
  930. }
  931. }
  932. function addFunctionsToMenu (
  933. function_obj,
  934. menu_var_or_value,
  935. ref_object,
  936. expression_element
  937. ) {
  938. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  939. sub_menu.text("");
  940. for (let i = 0; i < window.program_obj.functions.length; i++) {
  941. const temp = $(
  942. '<div class="item" data-option="' +
  943. VAR_OR_VALUE_TYPES.only_function +
  944. '">' +
  945. window.program_obj.functions[i].name +
  946. " </div>"
  947. );
  948. temp.data("function_reference", window.program_obj.functions[i]);
  949. sub_menu.append(temp);
  950. }
  951. }
  952. function addVariablesToMenu (
  953. function_obj,
  954. menu_var_or_value,
  955. ref_object,
  956. expression_element
  957. ) {
  958. const sub_menu = menu_var_or_value.find(".menu_only_vars");
  959. sub_menu.text("");
  960. let is_there = false;
  961. if (window.program_obj.globals) {
  962. if (ref_object.include_constant) {
  963. for (var i = 0; i < window.program_obj.globals.length; i++) {
  964. var temp = $(
  965. '<div class="item" data-option="' +
  966. VAR_OR_VALUE_TYPES.only_variable +
  967. '">' +
  968. window.program_obj.globals[i].name +
  969. " </div>"
  970. );
  971. temp.data("variable_reference", window.program_obj.globals[i]);
  972. sub_menu.append(temp);
  973. is_there = true;
  974. }
  975. } else {
  976. for (var i = 0; i < window.program_obj.globals.length; i++) {
  977. if (!window.program_obj.globals[i].is_constant) {
  978. var temp = $(
  979. '<div class="item" data-option="' +
  980. VAR_OR_VALUE_TYPES.only_variable +
  981. '">' +
  982. window.program_obj.globals[i].name +
  983. " </div>"
  984. );
  985. temp.data("variable_reference", window.program_obj.globals[i]);
  986. sub_menu.append(temp);
  987. is_there = true;
  988. }
  989. }
  990. }
  991. }
  992. if (function_obj.parameters_list) {
  993. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  994. var temp = $(
  995. '<div class="item" data-option="' +
  996. VAR_OR_VALUE_TYPES.only_variable +
  997. '">' +
  998. function_obj.parameters_list[i].name +
  999. " </div>"
  1000. );
  1001. temp.data("variable_reference", function_obj.parameters_list[i]);
  1002. sub_menu.append(temp);
  1003. is_there = true;
  1004. }
  1005. }
  1006. if (function_obj.variables_list) {
  1007. for (var i = 0; i < function_obj.variables_list.length; i++) {
  1008. var temp = $(
  1009. '<div class="item" data-option="' +
  1010. VAR_OR_VALUE_TYPES.only_variable +
  1011. '">' +
  1012. function_obj.variables_list[i].name +
  1013. " </div>"
  1014. );
  1015. temp.data("variable_reference", function_obj.variables_list[i]);
  1016. sub_menu.append(temp);
  1017. is_there = true;
  1018. }
  1019. }
  1020. if (!is_there) {
  1021. sub_menu.append(
  1022. $(
  1023. '<div class="header">' +
  1024. LocalizedStrings.getUI("text_no_variable") +
  1025. "</div>"
  1026. )
  1027. );
  1028. sub_menu.append(
  1029. $(
  1030. '<div class="item disabled">' +
  1031. LocalizedStrings.getUI("text_no_variable_instruction") +
  1032. "</div>"
  1033. )
  1034. );
  1035. }
  1036. }
  1037. function addHandlers (
  1038. command,
  1039. ref_object,
  1040. dom_object,
  1041. menu_var_or_value,
  1042. function_obj,
  1043. expression_element
  1044. ) {
  1045. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1046. menu_var_or_value.dropdown({
  1047. onChange: function (value, text, $selectedItem) {
  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. if ($selectedItem.data("clear")) {
  1232. dom_object.text("");
  1233. ref_object.content = null;
  1234. ref_object.row = null;
  1235. ref_object.column = null;
  1236. delete ref_object.function_called;
  1237. delete ref_object.parameters_list;
  1238. renderMenu(
  1239. command,
  1240. ref_object,
  1241. dom_object,
  1242. function_obj,
  1243. 2,
  1244. expression_element
  1245. );
  1246. }
  1247. if ($selectedItem.data("exp")) {
  1248. AttribuitionsManagement.manageExpressionElements(
  1249. command,
  1250. ref_object,
  1251. dom_object,
  1252. menu_var_or_value,
  1253. function_obj,
  1254. $selectedItem,
  1255. expression_element
  1256. );
  1257. }
  1258. },
  1259. selectOnKeydown: false,
  1260. });
  1261. } else {
  1262. menu_var_or_value.find(".text").text(" ");
  1263. dom_object.find(".menu_var_or_value_dom").remove();
  1264. var parameters_menu;
  1265. if (function_selected.name) {
  1266. parameters_menu =
  1267. '<div class="parameters_function_called"> ' +
  1268. function_selected.name +
  1269. " <span> ( </span>";
  1270. } else {
  1271. parameters_menu =
  1272. '<div class="parameters_function_called"> <i>' +
  1273. LocalizedStrings.translateInternalFunction(
  1274. function_selected.identifier,
  1275. function_selected.category
  1276. ) +
  1277. "</i> <span> ( </span>";
  1278. }
  1279. parameters_menu += "<span> ) </span></div>";
  1280. parameters_menu = $(parameters_menu);
  1281. dom_object.append(parameters_menu);
  1282. var context_menu =
  1283. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1284. context_menu +=
  1285. '<div class="item" data-clear="true">' +
  1286. LocalizedStrings.getUI("btn_clear") +
  1287. "</div>";
  1288. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1289. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1290. context_menu += '<div class="menu">';
  1291. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1292. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1293. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1294. context_menu += '</div></div>';
  1295. }*/
  1296. context_menu += "</div></div>";
  1297. context_menu = $(context_menu);
  1298. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1299. context_menu.dropdown({
  1300. onChange: function (value, text, $selectedItem) {
  1301. if ($selectedItem.data("clear")) {
  1302. dom_object.text("");
  1303. ref_object.content = null;
  1304. ref_object.row = null;
  1305. ref_object.column = null;
  1306. delete ref_object.function_called;
  1307. delete ref_object.parameters_list;
  1308. renderMenu(
  1309. command,
  1310. ref_object,
  1311. dom_object,
  1312. function_obj,
  1313. 2,
  1314. expression_element
  1315. );
  1316. }
  1317. if ($selectedItem.data("exp")) {
  1318. AttribuitionsManagement.manageExpressionElements(
  1319. command,
  1320. ref_object,
  1321. dom_object,
  1322. menu_var_or_value,
  1323. function_obj,
  1324. $selectedItem,
  1325. expression_element
  1326. );
  1327. }
  1328. },
  1329. selectOnKeydown: false,
  1330. });
  1331. }
  1332. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1333. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1334. }*/
  1335. }
  1336. function openInputToVariable (
  1337. command,
  1338. ref_object,
  1339. dom_object,
  1340. menu_var_or_value,
  1341. function_obj,
  1342. variable_selected,
  1343. expression_element
  1344. ) {
  1345. ref_object.content = variable_selected;
  1346. menu_var_or_value.find(".text").text(" ");
  1347. dom_object.find(".menu_var_or_value_dom").remove();
  1348. let variable_render =
  1349. '<div class="variable_rendered"> <span class="var_name">' +
  1350. variable_selected.name +
  1351. "</span>";
  1352. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1353. variable_render +=
  1354. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1355. }
  1356. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1357. variable_render +=
  1358. ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  1359. variable_render +=
  1360. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1361. }
  1362. variable_render += "</div>";
  1363. variable_render = $(variable_render);
  1364. dom_object.append(variable_render);
  1365. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1366. ref_object.column = new Models.VariableValueMenu(
  1367. VAR_OR_VALUE_TYPES.all,
  1368. null,
  1369. null,
  1370. null,
  1371. true
  1372. );
  1373. renderMenu(
  1374. command,
  1375. ref_object.column,
  1376. variable_render.find(".column_container"),
  1377. function_obj,
  1378. 2,
  1379. expression_element
  1380. );
  1381. }
  1382. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1383. ref_object.row = new Models.VariableValueMenu(
  1384. VAR_OR_VALUE_TYPES.all,
  1385. null,
  1386. null,
  1387. null,
  1388. true
  1389. );
  1390. renderMenu(
  1391. command,
  1392. ref_object.row,
  1393. variable_render.find(".row_container"),
  1394. function_obj,
  1395. 2,
  1396. expression_element
  1397. );
  1398. ref_object.column = new Models.VariableValueMenu(
  1399. VAR_OR_VALUE_TYPES.all,
  1400. null,
  1401. null,
  1402. null,
  1403. true
  1404. );
  1405. renderMenu(
  1406. command,
  1407. ref_object.column,
  1408. variable_render.find(".column_container"),
  1409. function_obj,
  1410. 2,
  1411. expression_element
  1412. );
  1413. }
  1414. let context_menu =
  1415. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1416. context_menu +=
  1417. '<div class="item" data-clear="true">' +
  1418. LocalizedStrings.getUI("btn_clear") +
  1419. "</div>";
  1420. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  1421. console.log("dom_object 10: ");
  1422. console.log(dom_object);
  1423. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1424. context_menu += '<div class="menu">';
  1425. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1426. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1427. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1428. context_menu += '</div></div>';
  1429. }*/
  1430. context_menu += "</div></div>";
  1431. context_menu = $(context_menu);
  1432. context_menu.insertAfter(dom_object.find(".variable_rendered"));
  1433. context_menu.dropdown({
  1434. onChange: function (value, text, $selectedItem) {
  1435. if ($selectedItem.data("clear")) {
  1436. dom_object.text("");
  1437. ref_object.content = null;
  1438. ref_object.row = null;
  1439. ref_object.column = null;
  1440. delete ref_object.function_called;
  1441. delete ref_object.parameters_list;
  1442. renderMenu(
  1443. command,
  1444. ref_object,
  1445. dom_object,
  1446. function_obj,
  1447. 2,
  1448. expression_element
  1449. );
  1450. }
  1451. if ($selectedItem.data("exp")) {
  1452. AttribuitionsManagement.manageExpressionElements(
  1453. command,
  1454. ref_object,
  1455. dom_object,
  1456. menu_var_or_value,
  1457. function_obj,
  1458. $selectedItem,
  1459. expression_element
  1460. );
  1461. }
  1462. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1463. RepeatNTimesManagement.manageClearExpressionElements(
  1464. command,
  1465. ref_object,
  1466. dom_object,
  1467. menu_var_or_value,
  1468. function_obj,
  1469. $selectedItem,
  1470. expression_element
  1471. );
  1472. }
  1473. },
  1474. selectOnKeydown: false,
  1475. });
  1476. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1477. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  1478. }*/
  1479. }
  1480. function openInputToValue (
  1481. command,
  1482. ref_object,
  1483. dom_object,
  1484. menu_var_or_value,
  1485. function_obj,
  1486. expression_element
  1487. ) {
  1488. if (ref_object.content == null) {
  1489. ref_object.content = "";
  1490. }
  1491. menu_var_or_value.find(".text").text(" ");
  1492. const field = $(
  1493. '<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'
  1494. );
  1495. field.insertBefore(dom_object.find(".menu_var_or_value_dom"));
  1496. field.on('input', function() {
  1497. var input_field = $(this);
  1498. var inputWidth = input_field.textWidth()+10;
  1499. inputWidth = inputWidth<50?50:inputWidth;
  1500. input_field.css({
  1501. width: inputWidth
  1502. })
  1503. }).trigger('input');
  1504. const rendered = $('<div class="value_rendered"></div>');
  1505. rendered.insertBefore(field);
  1506. field.focus();
  1507. field.val(ref_object.content);
  1508. let context_menu =
  1509. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1510. context_menu +=
  1511. '<div class="item" data-clear="true">' +
  1512. LocalizedStrings.getUI("btn_clear") +
  1513. "</div>";
  1514. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1515. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1516. context_menu += '<div class="menu">';
  1517. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1518. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1519. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1520. context_menu += '</div></div>';
  1521. }*/
  1522. context_menu += "</div></div>";
  1523. context_menu = $(context_menu);
  1524. dom_object.find(".menu_var_or_value_dom").remove();
  1525. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1526. context_menu.insertAfter(field);
  1527. }
  1528. context_menu.dropdown({
  1529. onChange: function (value, text, $selectedItem) {
  1530. if ($selectedItem.data("clear")) {
  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. ref_object.content = $(this)
  1574. .val();
  1575. if (isNaN(ref_object.content)) {
  1576. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1577. } else {
  1578. rendered.text(ref_object.content);
  1579. }
  1580. $(this).remove();
  1581. });
  1582. dom_object.find(".width-dynamic-minus").on("keydown", function (e) {
  1583. const code = e.keyCode || e.which;
  1584. if (code == 13) {
  1585. /*if (
  1586. $(this)
  1587. .val()
  1588. .trim()
  1589. ) {
  1590. ref_object.content = $(this)
  1591. .val()
  1592. .trim();
  1593. }*/
  1594. ref_object.content = $(this)
  1595. .val();
  1596. if (isNaN(ref_object.content)) {
  1597. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1598. } else {
  1599. rendered.text(ref_object.content);
  1600. }
  1601. $(this).remove();
  1602. }
  1603. if (code == 27) {
  1604. if (isNaN(ref_object.content)) {
  1605. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1606. } else {
  1607. rendered.text(ref_object.content);
  1608. }
  1609. $(this).remove();
  1610. }
  1611. });
  1612. if (command.type == Models.COMMAND_TYPES.comment) {
  1613. /*rendered.parent().on('click', function(e) {
  1614. rendered.parent().off();
  1615. console.log("TTT14");
  1616. rendered.remove();
  1617. rendered.empty();
  1618. rendered.remove();
  1619. dom_object.empty();
  1620. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1621. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  1622. });*/
  1623. }
  1624. rendered.on("click", function (e) {
  1625. rendered.empty();
  1626. rendered.remove();
  1627. dom_object.empty();
  1628. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1629. openInputToValue(
  1630. command,
  1631. ref_object,
  1632. dom_object,
  1633. menu_var_or_value,
  1634. function_obj,
  1635. expression_element
  1636. );
  1637. });
  1638. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1639. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1640. }*/
  1641. }
  1642. $.fn.textWidth = function (text, font) {
  1643. if (!$.fn.textWidth.fakeEl)
  1644. $.fn.textWidth.fakeEl = $("<span>")
  1645. .hide()
  1646. .appendTo(document.body);
  1647. $.fn.textWidth.fakeEl
  1648. .text(text || this.val() || this.text() || this.attr("placeholder"))
  1649. .css("font", font || this.css("font"));
  1650. return $.fn.textWidth.fakeEl.width();
  1651. };