variable_value_menu.js 59 KB

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