variable_value_menu.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  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. console.log("S1");
  429. if ($selectedItem.data("clear")) {
  430. console.log("PP1");
  431. dom_object.text("");
  432. variable_obj.content = null;
  433. variable_obj.row = null;
  434. variable_obj.column = null;
  435. delete variable_obj.function_called;
  436. delete variable_obj.parameters_list;
  437. renderMenu(
  438. command,
  439. variable_obj,
  440. dom_object,
  441. function_obj,
  442. 2,
  443. expression_element
  444. );
  445. }
  446. if ($selectedItem.data("exp")) {
  447. AttribuitionsManagement.manageExpressionElements(
  448. command,
  449. variable_obj,
  450. dom_object,
  451. menu_var_or_value,
  452. function_obj,
  453. $selectedItem,
  454. expression_element
  455. );
  456. }
  457. },
  458. selectOnKeydown: false,
  459. });
  460. } else {
  461. menu_var_or_value.find(".text").text(" ");
  462. dom_object.find(".menu_var_or_value_dom").remove();
  463. var parameters_menu;
  464. if (variable_obj.function_called.name) {
  465. parameters_menu =
  466. '<div class="parameters_function_called"> ' +
  467. variable_obj.function_called.name +
  468. " <span> ( </span>";
  469. } else {
  470. parameters_menu =
  471. '<div class="parameters_function_called"> <i>' +
  472. LocalizedStrings.translateInternalFunction(
  473. variable_obj.function_called.identifier,
  474. variable_obj.function_called.category
  475. ) +
  476. "</i> <span> ( </span>";
  477. }
  478. for (
  479. let j = 0;
  480. j < variable_obj.function_called.parameters_list.length;
  481. j++
  482. ) {
  483. parameters_menu +=
  484. '<div class="render_style_param parameter_' + j + '"></div>';
  485. if (j + 1 != variable_obj.function_called.parameters_list.length) {
  486. parameters_menu += " , ";
  487. }
  488. }
  489. parameters_menu += "<span> ) </span></div>";
  490. parameters_menu = $(parameters_menu);
  491. dom_object.append(parameters_menu);
  492. for (
  493. let j = 0;
  494. j < variable_obj.function_called.parameters_list.length;
  495. j++
  496. ) {
  497. renderMenu(
  498. command,
  499. variable_obj.parameters_list[j],
  500. parameters_menu.find(".parameter_" + j),
  501. function_obj,
  502. 2,
  503. expression_element
  504. );
  505. }
  506. let context_menu =
  507. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  508. context_menu +=
  509. '<div class="item" data-clear="true">' +
  510. LocalizedStrings.getUI("btn_clear") +
  511. "</div>";
  512. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  513. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  514. context_menu += '<div class="menu">';
  515. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  516. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  517. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  518. context_menu += '</div></div>';
  519. }*/
  520. context_menu += "</div></div>";
  521. context_menu = $(context_menu);
  522. context_menu.insertAfter(parameters_menu);
  523. context_menu.dropdown({
  524. onChange: function (value, text, $selectedItem) {
  525. console.log("S2");
  526. if ($selectedItem.data("clear")) {
  527. console.log("PP2");
  528. dom_object.text("");
  529. variable_obj.content = null;
  530. variable_obj.row = null;
  531. variable_obj.column = null;
  532. delete variable_obj.function_called;
  533. delete variable_obj.parameters_list;
  534. renderMenu(
  535. command,
  536. variable_obj,
  537. dom_object,
  538. function_obj,
  539. 2,
  540. expression_element
  541. );
  542. }
  543. if ($selectedItem.data("exp")) {
  544. AttribuitionsManagement.manageExpressionElements(
  545. command,
  546. variable_obj,
  547. dom_object,
  548. menu_var_or_value,
  549. function_obj,
  550. $selectedItem,
  551. expression_element
  552. );
  553. }
  554. },
  555. selectOnKeydown: false,
  556. });
  557. }
  558. } else if (variable_obj.content.type) {
  559. let variable_render = "";
  560. if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
  561. variable_render =
  562. '<div class="variable_rendered"> <span class="var_name">' +
  563. variable_obj.content.name +
  564. "</span>";
  565. variable_render +=
  566. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  567. variable_render += "</div>";
  568. variable_render = $(variable_render);
  569. dom_object.append(variable_render);
  570. let context_menu =
  571. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  572. context_menu +=
  573. '<div class="item" data-clear="true">' +
  574. LocalizedStrings.getUI("btn_clear") +
  575. "</div>";
  576. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  577. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  578. context_menu += '<div class="menu">';
  579. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  580. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  581. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  582. context_menu += '</div></div>';
  583. }*/
  584. context_menu += "</div></div>";
  585. context_menu = $(context_menu);
  586. variable_render.append(context_menu);
  587. context_menu.dropdown({
  588. onChange: function (value, text, $selectedItem) {
  589. console.log("S3");
  590. if ($selectedItem.data("clear")) {
  591. console.log("PP3");
  592. dom_object.text("");
  593. variable_obj.content = null;
  594. variable_obj.row = null;
  595. variable_obj.column = null;
  596. delete variable_obj.function_called;
  597. delete variable_obj.parameters_list;
  598. renderMenu(
  599. command,
  600. variable_obj,
  601. dom_object,
  602. function_obj,
  603. 2,
  604. expression_element
  605. );
  606. }
  607. if ($selectedItem.data("exp")) {
  608. AttribuitionsManagement.manageExpressionElements(
  609. command,
  610. variable_obj,
  611. dom_object,
  612. menu_var_or_value,
  613. function_obj,
  614. $selectedItem,
  615. expression_element
  616. );
  617. }
  618. },
  619. selectOnKeydown: false,
  620. });
  621. if (!variable_obj.column) {
  622. variable_obj.column = new Models.VariableValueMenu(
  623. VAR_OR_VALUE_TYPES.all,
  624. null,
  625. null,
  626. null,
  627. true
  628. );
  629. }
  630. variableValueMenuCode(
  631. command,
  632. variable_obj.column,
  633. $(variable_render.find(".column_container")),
  634. function_obj,
  635. menu_var_or_value,
  636. expression_element
  637. );
  638. } else if (
  639. variable_obj.content.dimensions == 2 &&
  640. variable_obj.dimensions != 2
  641. ) {
  642. variable_render =
  643. '<div class="variable_rendered"> <span class="var_name">' +
  644. variable_obj.content.name +
  645. "</span>";
  646. variable_render +=
  647. ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  648. variable_render +=
  649. ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  650. variable_render += "</div>";
  651. variable_render = $(variable_render);
  652. dom_object.append(variable_render);
  653. let context_menu =
  654. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  655. context_menu +=
  656. '<div class="item" data-clear="true">' +
  657. LocalizedStrings.getUI("btn_clear") +
  658. "</div>";
  659. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  660. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  661. context_menu += '<div class="menu">';
  662. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  663. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  664. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  665. context_menu += '</div></div>';
  666. }*/
  667. context_menu += "</div></div>";
  668. context_menu = $(context_menu);
  669. variable_render.append(context_menu);
  670. context_menu.dropdown({
  671. onChange: function (value, text, $selectedItem) {
  672. console.log("S4");
  673. if ($selectedItem.data("clear")) {
  674. console.log("PP4");
  675. dom_object.text("");
  676. variable_obj.content = null;
  677. variable_obj.row = null;
  678. variable_obj.column = null;
  679. delete variable_obj.function_called;
  680. delete variable_obj.parameters_list;
  681. renderMenu(
  682. command,
  683. variable_obj,
  684. dom_object,
  685. function_obj,
  686. 2,
  687. expression_element
  688. );
  689. }
  690. if ($selectedItem.data("exp")) {
  691. AttribuitionsManagement.manageExpressionElements(
  692. command,
  693. variable_obj,
  694. dom_object,
  695. menu_var_or_value,
  696. function_obj,
  697. $selectedItem,
  698. expression_element
  699. );
  700. }
  701. },
  702. selectOnKeydown: false,
  703. });
  704. if (!variable_obj.column) {
  705. variable_obj.column = new Models.VariableValueMenu(
  706. VAR_OR_VALUE_TYPES.all,
  707. null,
  708. null,
  709. null,
  710. true
  711. );
  712. }
  713. if (!variable_obj.row) {
  714. variable_obj.row = new Models.VariableValueMenu(
  715. VAR_OR_VALUE_TYPES.all,
  716. null,
  717. null,
  718. null,
  719. true
  720. );
  721. }
  722. variableValueMenuCode(
  723. command,
  724. variable_obj.row,
  725. $(variable_render.find(".row_container")),
  726. function_obj,
  727. menu_var_or_value,
  728. expression_element
  729. );
  730. variableValueMenuCode(
  731. command,
  732. variable_obj.column,
  733. $(variable_render.find(".column_container")),
  734. function_obj,
  735. menu_var_or_value,
  736. expression_element
  737. );
  738. } else {
  739. variable_render =
  740. '<div class="variable_rendered"> <span class="var_name">' +
  741. variable_obj.content.name +
  742. "</span>";
  743. variable_render += "</div>";
  744. variable_render = $(variable_render);
  745. dom_object.append(variable_render);
  746. let context_menu =
  747. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  748. context_menu +=
  749. '<div class="item" data-clear="true">' +
  750. LocalizedStrings.getUI("btn_clear") +
  751. "</div>";
  752. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  753. console.log('dom_object6');
  754. console.log(dom_object);
  755. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  756. context_menu += '<div class="menu">';
  757. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  758. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  759. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  760. context_menu += '</div></div>';
  761. }*/
  762. context_menu += "</div></div>";
  763. context_menu = $(context_menu);
  764. variable_render.append(context_menu);
  765. context_menu.dropdown({
  766. onChange: function (value, text, $selectedItem) {
  767. console.log("S5");
  768. if ($selectedItem.data("clear")) {
  769. console.log("PP5");
  770. dom_object.text("");
  771. variable_obj.content = null;
  772. variable_obj.row = null;
  773. variable_obj.column = null;
  774. delete variable_obj.function_called;
  775. delete variable_obj.parameters_list;
  776. renderMenu(
  777. command,
  778. variable_obj,
  779. dom_object,
  780. function_obj,
  781. 2,
  782. expression_element
  783. );
  784. }
  785. if ($selectedItem.data("exp")) {
  786. AttribuitionsManagement.manageExpressionElements(
  787. command,
  788. variable_obj,
  789. dom_object,
  790. menu_var_or_value,
  791. function_obj,
  792. $selectedItem,
  793. expression_element
  794. );
  795. }
  796. },
  797. selectOnKeydown: false,
  798. });
  799. }
  800. } else {
  801. let variable_render;
  802. variable_render =
  803. '<div class="variable_rendered"> <span class="var_name">';
  804. if (isNaN(variable_obj.content)) {
  805. variable_render += variable_obj.content.replaceAll(" ", "&nbsp;");
  806. } else {
  807. variable_render += variable_obj.content;
  808. }
  809. variable_render += "</span>";
  810. variable_render += "</div>";
  811. variable_render = $(variable_render);
  812. dom_object.append(variable_render);
  813. var context_menu =
  814. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  815. context_menu +=
  816. '<div class="item" data-clear="true">' +
  817. LocalizedStrings.getUI("btn_clear") +
  818. "</div>";
  819. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  820. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  821. context_menu += '<div class="menu">';
  822. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  823. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  824. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  825. context_menu += '</div></div>';
  826. }*/
  827. context_menu += "</div></div>";
  828. context_menu = $(context_menu);
  829. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  830. context_menu.insertAfter(variable_render);
  831. }
  832. context_menu.dropdown({
  833. onChange: function (value, text, $selectedItem) {
  834. console.log("S6");
  835. if ($selectedItem.data("clear")) {
  836. console.log("PP6");
  837. dom_object.text("");
  838. variable_obj.content = null;
  839. variable_obj.row = null;
  840. variable_obj.column = null;
  841. delete variable_obj.function_called;
  842. delete variable_obj.parameters_list;
  843. dom_object.find(".value_rendered").remove();
  844. dom_object.find(".context_menu_clear").remove();
  845. dom_object.find(".width-dynamic-minus").remove();
  846. renderMenu(
  847. command,
  848. variable_obj,
  849. dom_object,
  850. function_obj,
  851. 2,
  852. expression_element
  853. );
  854. }
  855. if ($selectedItem.data("exp")) {
  856. AttribuitionsManagement.manageExpressionElements(
  857. command,
  858. variable_obj,
  859. dom_object,
  860. menu_var_or_value,
  861. function_obj,
  862. $selectedItem,
  863. expression_element
  864. );
  865. }
  866. },
  867. selectOnKeydown: false,
  868. });
  869. variable_render.on("click", function (e) {
  870. variable_render.remove();
  871. variable_render.empty();
  872. variable_render.remove();
  873. dom_object.empty();
  874. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  875. openInputToValue(
  876. command,
  877. variable_obj,
  878. dom_object,
  879. menu_var_or_value,
  880. function_obj,
  881. expression_element
  882. );
  883. });
  884. }
  885. }
  886. function addIVProgFunctionsToMenu (
  887. function_obj,
  888. menu_var_or_value,
  889. ref_object,
  890. expression_element
  891. ) {
  892. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  893. sub_menu.append(
  894. '<div class="divider"></div><div class="header">' +
  895. LocalizedStrings.getUI("text_header_ivprog_functions") +
  896. "</div>"
  897. );
  898. sub_menu.append(
  899. '<div class="item"><i class="dropdown icon"></i>' +
  900. LocalizedStrings.getUI("text_menu_functions_math") +
  901. '<div class="menu menu_math_functions"></div></div>'
  902. );
  903. sub_menu.append(
  904. '<div class="item"><i class="dropdown icon"></i>' +
  905. LocalizedStrings.getUI("text_menu_functions_text") +
  906. '<div class="menu menu_text_functions"></div></div>'
  907. );
  908. sub_menu.append(
  909. '<div class="item"><i class="dropdown icon"></i>' +
  910. LocalizedStrings.getUI("text_menu_functions_array") +
  911. '<div class="menu menu_arrangement_functions"></div></div>'
  912. );
  913. sub_menu.append(
  914. '<div class="item"><i class="dropdown icon"></i>' +
  915. LocalizedStrings.getUI("text_menu_functions_conversion") +
  916. '<div class="menu menu_conversion_functions"></div></div>'
  917. );
  918. // Insert Math functions:
  919. for (let i = 0; i < window.system_functions.length; i++) {
  920. const t = $('<div class="item"></div>');
  921. t.data("function_reference", window.system_functions[i]);
  922. t.data("option", VAR_OR_VALUE_TYPES.only_function);
  923. t.text(
  924. LocalizedStrings.translateInternalFunction(
  925. window.system_functions[i].identifier
  926. )
  927. );
  928. switch (window.system_functions[i].category) {
  929. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  930. sub_menu.find(".menu_math_functions").append(t);
  931. break;
  932. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  933. sub_menu.find(".menu_text_functions").append(t);
  934. break;
  935. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  936. sub_menu.find(".menu_arrangement_functions").append(t);
  937. break;
  938. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  939. sub_menu.find(".menu_conversion_functions").append(t);
  940. break;
  941. }
  942. }
  943. }
  944. function addFunctionsToMenu (
  945. function_obj,
  946. menu_var_or_value,
  947. ref_object,
  948. expression_element
  949. ) {
  950. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  951. sub_menu.text("");
  952. for (let i = 0; i < window.program_obj.functions.length; i++) {
  953. const temp = $(
  954. '<div class="item" data-option="' +
  955. VAR_OR_VALUE_TYPES.only_function +
  956. '">' +
  957. window.program_obj.functions[i].name +
  958. " </div>"
  959. );
  960. temp.data("function_reference", window.program_obj.functions[i]);
  961. sub_menu.append(temp);
  962. }
  963. }
  964. function addVariablesToMenu (
  965. function_obj,
  966. menu_var_or_value,
  967. ref_object,
  968. expression_element
  969. ) {
  970. const sub_menu = menu_var_or_value.find(".menu_only_vars");
  971. sub_menu.text("");
  972. let is_there = false;
  973. if (window.program_obj.globals) {
  974. if (ref_object.include_constant) {
  975. for (var i = 0; i < window.program_obj.globals.length; i++) {
  976. var temp = $(
  977. '<div class="item" data-option="' +
  978. VAR_OR_VALUE_TYPES.only_variable +
  979. '">' +
  980. window.program_obj.globals[i].name +
  981. " </div>"
  982. );
  983. temp.data("variable_reference", window.program_obj.globals[i]);
  984. sub_menu.append(temp);
  985. is_there = true;
  986. }
  987. } else {
  988. for (var i = 0; i < window.program_obj.globals.length; i++) {
  989. if (!window.program_obj.globals[i].is_constant) {
  990. var temp = $(
  991. '<div class="item" data-option="' +
  992. VAR_OR_VALUE_TYPES.only_variable +
  993. '">' +
  994. window.program_obj.globals[i].name +
  995. " </div>"
  996. );
  997. temp.data("variable_reference", window.program_obj.globals[i]);
  998. sub_menu.append(temp);
  999. is_there = true;
  1000. }
  1001. }
  1002. }
  1003. }
  1004. if (function_obj.parameters_list) {
  1005. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  1006. var temp = $(
  1007. '<div class="item" data-option="' +
  1008. VAR_OR_VALUE_TYPES.only_variable +
  1009. '">' +
  1010. function_obj.parameters_list[i].name +
  1011. " </div>"
  1012. );
  1013. temp.data("variable_reference", function_obj.parameters_list[i]);
  1014. sub_menu.append(temp);
  1015. is_there = true;
  1016. }
  1017. }
  1018. if (function_obj.variables_list) {
  1019. for (var i = 0; i < function_obj.variables_list.length; i++) {
  1020. var temp = $(
  1021. '<div class="item" data-option="' +
  1022. VAR_OR_VALUE_TYPES.only_variable +
  1023. '">' +
  1024. function_obj.variables_list[i].name +
  1025. " </div>"
  1026. );
  1027. temp.data("variable_reference", function_obj.variables_list[i]);
  1028. sub_menu.append(temp);
  1029. is_there = true;
  1030. }
  1031. }
  1032. if (!is_there) {
  1033. sub_menu.append(
  1034. $(
  1035. '<div class="header">' +
  1036. LocalizedStrings.getUI("text_no_variable") +
  1037. "</div>"
  1038. )
  1039. );
  1040. sub_menu.append(
  1041. $(
  1042. '<div class="item disabled">' +
  1043. LocalizedStrings.getUI("text_no_variable_instruction") +
  1044. "</div>"
  1045. )
  1046. );
  1047. }
  1048. }
  1049. function addHandlers (
  1050. command,
  1051. ref_object,
  1052. dom_object,
  1053. menu_var_or_value,
  1054. function_obj,
  1055. expression_element
  1056. ) {
  1057. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1058. menu_var_or_value.dropdown({
  1059. onChange: function (value, text, $selectedItem) {
  1060. console.log("S7");
  1061. dom_object.find(".var_name").remove();
  1062. switch ($selectedItem.data("option")) {
  1063. case VAR_OR_VALUE_TYPES.only_function:
  1064. openInputToFunction(
  1065. command,
  1066. ref_object,
  1067. dom_object,
  1068. menu_var_or_value,
  1069. function_obj,
  1070. $($selectedItem).data("function_reference"),
  1071. expression_element
  1072. );
  1073. break;
  1074. case VAR_OR_VALUE_TYPES.only_value:
  1075. openInputToValue(
  1076. command,
  1077. ref_object,
  1078. dom_object,
  1079. menu_var_or_value,
  1080. function_obj,
  1081. expression_element
  1082. );
  1083. break;
  1084. case VAR_OR_VALUE_TYPES.only_variable:
  1085. openInputToVariable(
  1086. command,
  1087. ref_object,
  1088. dom_object,
  1089. menu_var_or_value,
  1090. function_obj,
  1091. $($selectedItem).data("variable_reference"),
  1092. expression_element
  1093. );
  1094. break;
  1095. }
  1096. if ($selectedItem.data("exp")) {
  1097. AttribuitionsManagement.manageExpressionElements(
  1098. command,
  1099. ref_object,
  1100. dom_object,
  1101. menu_var_or_value,
  1102. function_obj,
  1103. $selectedItem,
  1104. expression_element
  1105. );
  1106. }
  1107. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1108. RepeatNTimesManagement.manageExpressionElements(
  1109. command,
  1110. ref_object,
  1111. dom_object,
  1112. menu_var_or_value,
  1113. function_obj,
  1114. $selectedItem,
  1115. expression_element
  1116. );
  1117. }
  1118. },
  1119. selectOnKeydown: false,
  1120. });
  1121. }
  1122. dom_object
  1123. .find(".width-dynamic")
  1124. .on("input", function () {
  1125. const inputWidth = $(this).textWidth() + 10;
  1126. $(this).focus();
  1127. const tmpStr = $(this).val();
  1128. $(this).val("");
  1129. $(this).val(tmpStr);
  1130. $(this).css({
  1131. width: inputWidth,
  1132. });
  1133. })
  1134. .trigger("input");
  1135. if (command.type == Models.COMMAND_TYPES.comment) {
  1136. dom_object.parent().on("click", function (e) {
  1137. dom_object.find(".value_rendered").remove();
  1138. dom_object.find(".value_rendered").empty();
  1139. dom_object.find(".value_rendered").remove();
  1140. dom_object.empty();
  1141. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1142. openInputToValue(
  1143. command,
  1144. ref_object,
  1145. dom_object,
  1146. menu_var_or_value,
  1147. function_obj,
  1148. expression_element
  1149. );
  1150. });
  1151. }
  1152. }
  1153. function openInputToFunction (
  1154. command,
  1155. ref_object,
  1156. dom_object,
  1157. menu_var_or_value,
  1158. function_obj,
  1159. function_selected,
  1160. expression_element
  1161. ) {
  1162. ref_object.function_called = function_selected;
  1163. ref_object.parameters_list = [];
  1164. if (
  1165. function_selected.parameters_list != null &&
  1166. function_selected.parameters_list.length > 0
  1167. ) {
  1168. menu_var_or_value.find(".text").text(" ");
  1169. dom_object.find(".menu_var_or_value_dom").remove();
  1170. var parameters_menu;
  1171. if (function_selected.name) {
  1172. parameters_menu =
  1173. '<div class="parameters_function_called"> ' +
  1174. function_selected.name +
  1175. " <span> ( </span>";
  1176. } else {
  1177. parameters_menu =
  1178. '<div class="parameters_function_called"> <i>' +
  1179. LocalizedStrings.translateInternalFunction(
  1180. function_selected.identifier,
  1181. function_selected.category
  1182. ) +
  1183. "</i> <span> ( </span>";
  1184. }
  1185. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1186. parameters_menu +=
  1187. '<div class="render_style_param parameter_' + j + '"></div>';
  1188. if (j + 1 != function_selected.parameters_list.length) {
  1189. parameters_menu += " , ";
  1190. }
  1191. }
  1192. parameters_menu += "<span> ) </span></div>";
  1193. parameters_menu = $(parameters_menu);
  1194. dom_object.append(parameters_menu);
  1195. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  1196. var temp;
  1197. if (function_selected.parameters_list[j].dimensions > 0) {
  1198. temp = new Models.VariableValueMenu(
  1199. VAR_OR_VALUE_TYPES.variable_and_function,
  1200. null,
  1201. null,
  1202. null,
  1203. true,
  1204. function_selected.parameters_list[j].dimensions
  1205. );
  1206. } else {
  1207. temp = new Models.VariableValueMenu(
  1208. VAR_OR_VALUE_TYPES.all,
  1209. null,
  1210. null,
  1211. null,
  1212. true
  1213. );
  1214. }
  1215. ref_object.parameters_list.push(temp);
  1216. renderMenu(
  1217. command,
  1218. temp,
  1219. parameters_menu.find(".parameter_" + j),
  1220. function_obj,
  1221. 2,
  1222. expression_element
  1223. );
  1224. }
  1225. var context_menu =
  1226. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1227. context_menu +=
  1228. '<div class="item" data-clear="true">' +
  1229. LocalizedStrings.getUI("btn_clear") +
  1230. "</div>";
  1231. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1232. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1233. context_menu += '<div class="menu">';
  1234. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1235. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1236. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1237. context_menu += '</div></div>';
  1238. }*/
  1239. context_menu += "</div></div>";
  1240. context_menu = $(context_menu);
  1241. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1242. context_menu.dropdown({
  1243. onChange: function (value, text, $selectedItem) {
  1244. console.log("S8");
  1245. if ($selectedItem.data("clear")) {
  1246. console.log("PP7");
  1247. dom_object.text("");
  1248. ref_object.content = null;
  1249. ref_object.row = null;
  1250. ref_object.column = null;
  1251. delete ref_object.function_called;
  1252. delete ref_object.parameters_list;
  1253. renderMenu(
  1254. command,
  1255. ref_object,
  1256. dom_object,
  1257. function_obj,
  1258. 2,
  1259. expression_element
  1260. );
  1261. }
  1262. if ($selectedItem.data("exp")) {
  1263. AttribuitionsManagement.manageExpressionElements(
  1264. command,
  1265. ref_object,
  1266. dom_object,
  1267. menu_var_or_value,
  1268. function_obj,
  1269. $selectedItem,
  1270. expression_element
  1271. );
  1272. }
  1273. },
  1274. selectOnKeydown: false,
  1275. });
  1276. } else {
  1277. menu_var_or_value.find(".text").text(" ");
  1278. dom_object.find(".menu_var_or_value_dom").remove();
  1279. var parameters_menu;
  1280. if (function_selected.name) {
  1281. parameters_menu =
  1282. '<div class="parameters_function_called"> ' +
  1283. function_selected.name +
  1284. " <span> ( </span>";
  1285. } else {
  1286. parameters_menu =
  1287. '<div class="parameters_function_called"> <i>' +
  1288. LocalizedStrings.translateInternalFunction(
  1289. function_selected.identifier,
  1290. function_selected.category
  1291. ) +
  1292. "</i> <span> ( </span>";
  1293. }
  1294. parameters_menu += "<span> ) </span></div>";
  1295. parameters_menu = $(parameters_menu);
  1296. dom_object.append(parameters_menu);
  1297. var context_menu =
  1298. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1299. context_menu +=
  1300. '<div class="item" data-clear="true">' +
  1301. LocalizedStrings.getUI("btn_clear") +
  1302. "</div>";
  1303. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1304. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1305. context_menu += '<div class="menu">';
  1306. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1307. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1308. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1309. context_menu += '</div></div>';
  1310. }*/
  1311. context_menu += "</div></div>";
  1312. context_menu = $(context_menu);
  1313. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1314. context_menu.dropdown({
  1315. onChange: function (value, text, $selectedItem) {
  1316. console.log("S9");
  1317. if ($selectedItem.data("clear")) {
  1318. console.log("PP8");
  1319. dom_object.text("");
  1320. ref_object.content = null;
  1321. ref_object.row = null;
  1322. ref_object.column = null;
  1323. delete ref_object.function_called;
  1324. delete ref_object.parameters_list;
  1325. renderMenu(
  1326. command,
  1327. ref_object,
  1328. dom_object,
  1329. function_obj,
  1330. 2,
  1331. expression_element
  1332. );
  1333. }
  1334. if ($selectedItem.data("exp")) {
  1335. AttribuitionsManagement.manageExpressionElements(
  1336. command,
  1337. ref_object,
  1338. dom_object,
  1339. menu_var_or_value,
  1340. function_obj,
  1341. $selectedItem,
  1342. expression_element
  1343. );
  1344. }
  1345. },
  1346. selectOnKeydown: false,
  1347. });
  1348. }
  1349. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1350. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1351. }*/
  1352. }
  1353. function openInputToVariable (
  1354. command,
  1355. ref_object,
  1356. dom_object,
  1357. menu_var_or_value,
  1358. function_obj,
  1359. variable_selected,
  1360. expression_element
  1361. ) {
  1362. ref_object.content = variable_selected;
  1363. menu_var_or_value.find(".text").text(" ");
  1364. dom_object.find(".menu_var_or_value_dom").remove();
  1365. let variable_render =
  1366. '<div class="variable_rendered"> <span class="var_name">' +
  1367. variable_selected.name +
  1368. "</span>";
  1369. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1370. variable_render +=
  1371. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1372. }
  1373. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1374. variable_render +=
  1375. ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  1376. variable_render +=
  1377. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1378. }
  1379. variable_render += "</div>";
  1380. variable_render = $(variable_render);
  1381. dom_object.append(variable_render);
  1382. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1383. ref_object.column = 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.column,
  1393. variable_render.find(".column_container"),
  1394. function_obj,
  1395. 2,
  1396. expression_element
  1397. );
  1398. }
  1399. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1400. ref_object.row = new Models.VariableValueMenu(
  1401. VAR_OR_VALUE_TYPES.all,
  1402. null,
  1403. null,
  1404. null,
  1405. true
  1406. );
  1407. renderMenu(
  1408. command,
  1409. ref_object.row,
  1410. variable_render.find(".row_container"),
  1411. function_obj,
  1412. 2,
  1413. expression_element
  1414. );
  1415. ref_object.column = new Models.VariableValueMenu(
  1416. VAR_OR_VALUE_TYPES.all,
  1417. null,
  1418. null,
  1419. null,
  1420. true
  1421. );
  1422. renderMenu(
  1423. command,
  1424. ref_object.column,
  1425. variable_render.find(".column_container"),
  1426. function_obj,
  1427. 2,
  1428. expression_element
  1429. );
  1430. }
  1431. let context_menu =
  1432. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1433. context_menu +=
  1434. '<div class="item" data-clear="true">' +
  1435. LocalizedStrings.getUI("btn_clear") +
  1436. "</div>";
  1437. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  1438. console.log("dom_object 10: ");
  1439. console.log(dom_object);
  1440. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1441. context_menu += '<div class="menu">';
  1442. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1443. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1444. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1445. context_menu += '</div></div>';
  1446. }*/
  1447. context_menu += "</div></div>";
  1448. context_menu = $(context_menu);
  1449. context_menu.insertAfter(dom_object.find(".variable_rendered"));
  1450. context_menu.dropdown({
  1451. onChange: function (value, text, $selectedItem) {
  1452. console.log("S10");
  1453. if ($selectedItem.data("clear")) {
  1454. console.log("PP9");
  1455. dom_object.text("");
  1456. ref_object.content = null;
  1457. ref_object.row = null;
  1458. ref_object.column = null;
  1459. delete ref_object.function_called;
  1460. delete ref_object.parameters_list;
  1461. renderMenu(
  1462. command,
  1463. ref_object,
  1464. dom_object,
  1465. function_obj,
  1466. 2,
  1467. expression_element
  1468. );
  1469. }
  1470. if ($selectedItem.data("exp")) {
  1471. AttribuitionsManagement.manageExpressionElements(
  1472. command,
  1473. ref_object,
  1474. dom_object,
  1475. menu_var_or_value,
  1476. function_obj,
  1477. $selectedItem,
  1478. expression_element
  1479. );
  1480. }
  1481. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1482. RepeatNTimesManagement.manageClearExpressionElements(
  1483. command,
  1484. ref_object,
  1485. dom_object,
  1486. menu_var_or_value,
  1487. function_obj,
  1488. $selectedItem,
  1489. expression_element
  1490. );
  1491. }
  1492. },
  1493. selectOnKeydown: false,
  1494. });
  1495. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1496. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  1497. }*/
  1498. }
  1499. function openInputToValue (
  1500. command,
  1501. ref_object,
  1502. dom_object,
  1503. menu_var_or_value,
  1504. function_obj,
  1505. expression_element
  1506. ) {
  1507. if (ref_object.content == null) {
  1508. ref_object.content = "";
  1509. }
  1510. menu_var_or_value.find(".text").text(" ");
  1511. const field = $(
  1512. '<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'
  1513. );
  1514. field.insertBefore(dom_object.find(".menu_var_or_value_dom"));
  1515. field.on('input', function() {
  1516. var input_field = $(this);
  1517. var inputWidth = input_field.textWidth()+10;
  1518. inputWidth = inputWidth<50?50:inputWidth;
  1519. input_field.css({
  1520. width: inputWidth
  1521. })
  1522. }).trigger('input');
  1523. const rendered = $('<div class="value_rendered"></div>');
  1524. rendered.insertBefore(field);
  1525. field.focus();
  1526. field.val(ref_object.content);
  1527. let context_menu =
  1528. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1529. context_menu +=
  1530. '<div class="item" data-clear="true">' +
  1531. LocalizedStrings.getUI("btn_clear") +
  1532. "</div>";
  1533. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1534. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1535. context_menu += '<div class="menu">';
  1536. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1537. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1538. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1539. context_menu += '</div></div>';
  1540. }*/
  1541. context_menu += "</div></div>";
  1542. context_menu = $(context_menu);
  1543. dom_object.find(".menu_var_or_value_dom").remove();
  1544. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1545. context_menu.insertAfter(field);
  1546. }
  1547. context_menu.dropdown({
  1548. onChange: function (value, text, $selectedItem) {
  1549. if ($selectedItem.data("clear")) {
  1550. dom_object.text("");
  1551. dom_object.find(".value_rendered").remove();
  1552. dom_object.find(".context_menu_clear").remove();
  1553. dom_object.find(".width-dynamic-minus").remove();
  1554. ref_object.content = null;
  1555. ref_object.row = null;
  1556. ref_object.column = null;
  1557. delete ref_object.function_called;
  1558. delete ref_object.parameters_list;
  1559. renderMenu(
  1560. command,
  1561. ref_object,
  1562. dom_object,
  1563. function_obj,
  1564. 2,
  1565. expression_element
  1566. );
  1567. }
  1568. if ($selectedItem.data("exp")) {
  1569. AttribuitionsManagement.manageExpressionElements(
  1570. command,
  1571. ref_object,
  1572. dom_object,
  1573. menu_var_or_value,
  1574. function_obj,
  1575. $selectedItem,
  1576. expression_element
  1577. );
  1578. }
  1579. },
  1580. selectOnKeydown: false,
  1581. });
  1582. dom_object.find(".width-dynamic-minus").focusout(function () {
  1583. /*if (
  1584. $(this)
  1585. .val()
  1586. .trim()
  1587. ) {
  1588. ref_object.content = $(this)
  1589. .val()
  1590. .trim();
  1591. }*/
  1592. ref_object.content = $(this)
  1593. .val();
  1594. if (isNaN(ref_object.content)) {
  1595. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1596. } else {
  1597. rendered.text(ref_object.content);
  1598. }
  1599. $(this).remove();
  1600. });
  1601. dom_object.find(".width-dynamic-minus").on("keydown", function (e) {
  1602. const code = e.keyCode || e.which;
  1603. if (code == 13) {
  1604. /*if (
  1605. $(this)
  1606. .val()
  1607. .trim()
  1608. ) {
  1609. ref_object.content = $(this)
  1610. .val()
  1611. .trim();
  1612. }*/
  1613. ref_object.content = $(this)
  1614. .val();
  1615. if (isNaN(ref_object.content)) {
  1616. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1617. } else {
  1618. rendered.text(ref_object.content);
  1619. }
  1620. $(this).remove();
  1621. }
  1622. if (code == 27) {
  1623. if (isNaN(ref_object.content)) {
  1624. rendered.html(ref_object.content.replaceAll(" ", "&nbsp;"));
  1625. } else {
  1626. rendered.text(ref_object.content);
  1627. }
  1628. $(this).remove();
  1629. }
  1630. });
  1631. if (command.type == Models.COMMAND_TYPES.comment) {
  1632. /*rendered.parent().on('click', function(e) {
  1633. rendered.parent().off();
  1634. console.log("TTT14");
  1635. rendered.remove();
  1636. rendered.empty();
  1637. rendered.remove();
  1638. dom_object.empty();
  1639. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1640. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  1641. });*/
  1642. }
  1643. rendered.on("click", function (e) {
  1644. console.log("TTT2");
  1645. rendered.empty();
  1646. rendered.remove();
  1647. dom_object.empty();
  1648. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1649. openInputToValue(
  1650. command,
  1651. ref_object,
  1652. dom_object,
  1653. menu_var_or_value,
  1654. function_obj,
  1655. expression_element
  1656. );
  1657. });
  1658. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1659. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1660. }*/
  1661. }
  1662. $.fn.textWidth = function (text, font) {
  1663. if (!$.fn.textWidth.fakeEl)
  1664. $.fn.textWidth.fakeEl = $("<span>")
  1665. .hide()
  1666. .appendTo(document.body);
  1667. $.fn.textWidth.fakeEl
  1668. .text(text || this.val() || this.text() || this.attr("placeholder"))
  1669. .css("font", font || this.css("font"));
  1670. return $.fn.textWidth.fakeEl.width();
  1671. };