variable_value_menu.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. // iVProg - www.usp.br/line/ivprog
  2. // LInE - Free Education, Private Data
  3. import * as Models from "../ivprog_elements";
  4. import { LocalizedStrings } from "../../services/localizedStringsService";
  5. import * as AttribuitionsManagement from "./attribution";
  6. import * as RepeatNTimesManagement from "./repeatNtimes";
  7. export const VAR_OR_VALUE_TYPES = Object.freeze({
  8. only_variable: 1,
  9. only_value: 2,
  10. only_function: 3,
  11. variable_and_function: 4,
  12. variable_and_value_opt: 5,
  13. value_and_function: 6,
  14. all: 7,
  15. });
  16. export function renderMenu (command, ref_object, dom_object, function_obj, size_field = 2, expression_element) {
  17. // Verificar se o objeto atual trata-se de uma chamada de funcao e conferir se possui a quantidade correta de parametros
  18. // Caso nao possua, tem que adicionar as variaveis que servirao de parametros:
  19. if (ref_object.function_called) {
  20. if (ref_object.function_called.parameters_list) {
  21. while (ref_object.function_called.parameters_list.length != ref_object.parameters_list.length) {
  22. if (ref_object.parameters_list.length > ref_object.function_called.parameters_list.length) {
  23. ref_object.parameters_list.pop();
  24. } else {
  25. ref_object.parameters_list.push(new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true));
  26. }
  27. }
  28. }
  29. }
  30. // Verificar agora, quando trata-se de chamada de funcao, se a passagem de parametro e'
  31. // por referencia ou por copia:
  32. var index_references = [];
  33. if (ref_object.function_called) {
  34. if (ref_object.function_called.parameters_list) {
  35. for (var i = 0; i < ref_object.function_called.parameters_list.length; i++) {
  36. if (ref_object.function_called.parameters_list[i].reference) {
  37. index_references.push(i)
  38. ref_object.parameters_list[i].reference = true
  39. ref_object.parameters_list[i].variable_and_value = VAR_OR_VALUE_TYPES.only_variable;
  40. if (ref_object.parameters_list[i].column)
  41. ref_object.parameters_list[i].column.reference_parent = true
  42. if (ref_object.parameters_list[i].row)
  43. ref_object.parameters_list[i].row.reference_parent = true
  44. }
  45. else {
  46. ref_object.parameters_list[i].reference = false;
  47. ref_object.parameters_list[i].variable_and_value = VAR_OR_VALUE_TYPES.all;
  48. if (ref_object.parameters_list[i].column)
  49. ref_object.parameters_list[i].column.reference_parent = false
  50. if (ref_object.parameters_list[i].row)
  51. ref_object.parameters_list[i].row.reference_parent = false
  52. }
  53. ref_object.parameters_list[i].reference_dimensions = ref_object.function_called.parameters_list[i].dimensions
  54. }
  55. }
  56. }
  57. let menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom" data-varmenu="true"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  58. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_variable) {
  59. menu_var_or_value = '<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">';
  60. menu_var_or_value += "</div>";
  61. }
  62. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function ||
  63. ref_object.variable_and_value ==
  64. VAR_OR_VALUE_TYPES.variable_and_value_opt ||
  65. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all) {
  66. menu_var_or_value +=
  67. '<div class="item" data-option="' +
  68. VAR_OR_VALUE_TYPES.only_variable +
  69. '"><i class="dropdown icon"></i>' +
  70. LocalizedStrings.getUI("variable");
  71. menu_var_or_value += '<div class="menu menu_only_vars">';
  72. menu_var_or_value += "</div></div>";
  73. }
  74. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_value) {
  75. menu_var_or_value =
  76. '<input type="text" class="width-dynamic" size="' +
  77. size_field +
  78. '" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />';
  79. }
  80. if (ref_object.variable_and_value ==VAR_OR_VALUE_TYPES.variable_and_value_opt ||
  81. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function ||
  82. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all) {
  83. menu_var_or_value +=
  84. '<div class="item" data-option="' +
  85. VAR_OR_VALUE_TYPES.only_value +
  86. '">' +
  87. LocalizedStrings.getUI("text_value") +
  88. "</div>";
  89. }
  90. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_function) {
  91. menu_var_or_value = '<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 (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function ||
  95. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function ||
  96. ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all) {
  97. menu_var_or_value +=
  98. '<div class="item" data-option="' +
  99. VAR_OR_VALUE_TYPES.only_function +
  100. '"><i class="dropdown icon"></i>' +
  101. LocalizedStrings.getUI("btn_function");
  102. menu_var_or_value += '<div class="menu menu_only_functions">';
  103. menu_var_or_value += "</div></div>";
  104. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  105. menu_var_or_value += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  106. menu_var_or_value += '<div class="menu">';
  107. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  108. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  109. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  110. menu_var_or_value += '</div></div>';
  111. }*/
  112. }
  113. menu_var_or_value += "</div></div>";
  114. menu_var_or_value = $(menu_var_or_value);
  115. menu_var_or_value.find('.width-dynamic').on('input', function() {
  116. var input_field = $(this);
  117. var inputWidth = input_field.textWidth()+10;
  118. inputWidth = inputWidth<50?50:inputWidth;
  119. input_field.css({width: inputWidth})
  120. }).trigger('input');
  121. dom_object.append(menu_var_or_value);
  122. ref_object.dom_object = menu_var_or_value;
  123. addHandlers(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  124. addVariablesToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  125. addFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  126. addIVProgFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  127. //D console.log("./ivprog/js/visualUI/commands/variable_value_menu.js: renderMenu(.): ref_object.content=" + ref_object.content);
  128. //leo ATTENTION: if constant with value 0 does not pass in "if ((ref_object.content)"
  129. if (ref_object.content || ref_object.content==0 || ref_object.function_called) {
  130. if (ref_object.content || ref_object.content==0) { //leo
  131. // Verificar se a variavel ainda existe:
  132. const variable_fun = isVarInProgram(ref_object.content, function_obj);
  133. if (variable_fun) {
  134. ref_object.content = variable_fun;
  135. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  136. } else {
  137. if ((ref_object.content || ref_object.content==0) && ref_object.content.type) { //leo
  138. ref_object.content = null;
  139. appendSelectText(ref_object, menu_var_or_value);
  140. } else {
  141. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  142. }
  143. }
  144. } else if (ref_object.function_called) {
  145. // Verificar se a funcao ainda existe:
  146. const ret_function = isFunctionInProgram(ref_object.function_called);
  147. if (ret_function) {
  148. ref_object.function_called = ret_function;
  149. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  150. } else {
  151. ref_object.content = null;
  152. ref_object.row = null;
  153. ref_object.column = null;
  154. delete ref_object.function_called;
  155. delete ref_object.parameters_list;
  156. appendSelectText(ref_object, menu_var_or_value);
  157. }
  158. }
  159. } // if (ref_object.content || ref_object.content==0)
  160. else {
  161. appendSelectText(ref_object, menu_var_or_value);
  162. }
  163. }
  164. function appendSelectText (ref_object, menu_var_or_value) {
  165. // if (ref_object.reference_parent) { menu_var_or_value.find(".text").append("<i>Opcional</i>"); return; }
  166. switch (ref_object.variable_and_value) {
  167. case VAR_OR_VALUE_TYPES.only_variable:
  168. menu_var_or_value.find(".text").append("<i>" + LocalizedStrings.getUI("var_menu_select_var") + "</i>");
  169. break;
  170. case VAR_OR_VALUE_TYPES.all:
  171. menu_var_or_value.find(".text").append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  172. break;
  173. case VAR_OR_VALUE_TYPES.variable_and_function:
  174. menu_var_or_value.find(".text").append("<i>" + LocalizedStrings.getUI("var_menu_select_all") + "</i>");
  175. break;
  176. case VAR_OR_VALUE_TYPES.only_function:
  177. menu_var_or_value.find(".text").append("<i>" + LocalizedStrings.getUI("var_menu_select_function") + "</i>");
  178. break;
  179. }
  180. } // function appendSelectText(ref_object, menu_var_or_value)
  181. function isFunctionInProgram (function_called_obj) {
  182. if (function_called_obj.name) {
  183. if (window.program_obj.functions) {
  184. for (var i = 0; i < window.program_obj.functions.length; i++) {
  185. if (window.program_obj.functions[i] == function_called_obj) {
  186. return window.program_obj.functions[i];
  187. }
  188. }
  189. for (var i = 0; i < window.program_obj.functions.length; i++) {
  190. if (window.program_obj.functions[i].name == function_called_obj.name) {
  191. return window.program_obj.functions[i];
  192. }
  193. }
  194. }
  195. } else if (function_called_obj.identifier) {
  196. for (var i = 0; i < window.system_functions.length; i++) {
  197. if (window.system_functions[i].identifier == function_called_obj.identifier) {
  198. return window.system_functions[i];
  199. }
  200. }
  201. }
  202. return null;
  203. } // function isFunctionInProgram(function_called_obj)
  204. function isVarInProgram (var_obj, function_obj) {
  205. // Verify in locals:
  206. if (function_obj.variables_list) {
  207. for (var i = 0; i < function_obj.variables_list.length; i++) {
  208. if (function_obj.variables_list[i] == var_obj) {
  209. return function_obj.variables_list[i];
  210. }
  211. }
  212. }
  213. // Verify in parameters:
  214. if (function_obj.parameters_list) {
  215. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  216. if (function_obj.parameters_list[i] == var_obj) {
  217. return function_obj.parameters_list[i];
  218. }
  219. }
  220. }
  221. // Verify in globals:
  222. if (window.program_obj.globals) {
  223. for (var i = 0; i < window.program_obj.globals.length; i++) {
  224. if (window.program_obj.globals[i] == var_obj) {
  225. return window.program_obj.globals[i];
  226. }
  227. }
  228. }
  229. // If not found, verify if the reference was lost
  230. if (var_obj) {
  231. if (function_obj.variables_list) {
  232. for (var i = 0; i < function_obj.variables_list.length; i++) {
  233. if (function_obj.variables_list[i].name == var_obj.name) {
  234. return function_obj.variables_list[i];
  235. }
  236. }
  237. }
  238. if (function_obj.parameters_list) {
  239. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  240. if (function_obj.parameters_list[i].name == var_obj.name) {
  241. return function_obj.parameters_list[i];
  242. }
  243. }
  244. }
  245. if (window.program_obj.globals) {
  246. for (var i = 0; i < window.program_obj.globals.length; i++) {
  247. if (window.program_obj.globals[i].name == var_obj.name) {
  248. return window.program_obj.globals[i];
  249. }
  250. }
  251. }
  252. }
  253. return null;
  254. }
  255. function renderPreviousContent (function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element) {
  256. if (ref_object.function_called) {
  257. menu_var_or_value.remove();
  258. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  259. } else if (ref_object.content.type) {
  260. menu_var_or_value.remove();
  261. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  262. } else {
  263. menu_var_or_value.remove();
  264. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  265. }
  266. }
  267. function variableValueMenuCode (command, variable_obj, dom_object, function_obj, menu_var_or_value, expression_element) {
  268. if (variable_obj.content || variable_obj.function_called) {
  269. // Verificar se a variavel ainda existe:
  270. const var_fun = isVarInProgram(variable_obj.content, function_obj);
  271. if (var_fun) {
  272. variable_obj.content = var_fun;
  273. } else {
  274. if (variable_obj.content && variable_obj.content.type) {
  275. variable_obj.content = null;
  276. appendSelectText(variable_obj, menu_var_or_value);
  277. }
  278. }
  279. } else {
  280. appendSelectText(variable_obj, menu_var_or_value);
  281. }
  282. if (variable_obj.content == null && variable_obj.function_called == null) {
  283. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  284. return;
  285. }
  286. const ret = "";
  287. if (variable_obj.function_called) {
  288. if (variable_obj.function_called.parameters_list == null || variable_obj.function_called.length == 0) {
  289. menu_var_or_value.find(".text").text(" ");
  290. dom_object.find(".menu_var_or_value_dom").remove();
  291. var parameters_menu;
  292. if (variable_obj.function_called.name) {
  293. parameters_menu =
  294. '<div class="parameters_function_called"> ' +
  295. variable_obj.function_called.name +
  296. " <span> ( </span>";
  297. } else {
  298. parameters_menu =
  299. '<div class="parameters_function_called"> <i>' +
  300. LocalizedStrings.translateInternalFunction(variable_obj.function_called.identifier, variable_obj.function_called.category) +
  301. "</i> <span> ( </span>";
  302. }
  303. parameters_menu += "<span> ) </span></div>";
  304. parameters_menu = $(parameters_menu);
  305. dom_object.append(parameters_menu);
  306. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  307. context_menu += '<div class="item" data-clear="true">' + LocalizedStrings.getUI("btn_clear") + "</div>"; // Clear
  308. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  309. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  310. context_menu += '<div class="menu">';
  311. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  312. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  313. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  314. context_menu += '</div></div>';
  315. }*/
  316. context_menu += "</div></div>";
  317. context_menu = $(context_menu);
  318. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  319. context_menu.dropdown({
  320. onChange: function (value, text, $selectedItem) {
  321. if ($selectedItem.data("clear")) {
  322. dom_object.text("");
  323. variable_obj.content = null;
  324. variable_obj.row = null;
  325. variable_obj.column = null;
  326. delete variable_obj.function_called;
  327. delete variable_obj.parameters_list;
  328. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  329. }
  330. if ($selectedItem.data("exp")) {
  331. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  332. }
  333. },
  334. selectOnKeydown: false,
  335. });
  336. } else {
  337. menu_var_or_value.find(".text").text(" ");
  338. dom_object.find(".menu_var_or_value_dom").remove();
  339. var parameters_menu;
  340. if (variable_obj.function_called.name) {
  341. parameters_menu =
  342. '<div class="parameters_function_called"> ' +
  343. variable_obj.function_called.name +
  344. " <span> ( </span>";
  345. } else {
  346. parameters_menu =
  347. '<div class="parameters_function_called"> <i>' +
  348. LocalizedStrings.translateInternalFunction(variable_obj.function_called.identifier, variable_obj.function_called.category) +
  349. "</i> <span> ( </span>";
  350. }
  351. for (let j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  352. parameters_menu += '<div class="render_style_param parameter_' + j + '"></div>';
  353. if (j + 1 != variable_obj.function_called.parameters_list.length) {
  354. parameters_menu += " , ";
  355. }
  356. }
  357. parameters_menu += "<span> ) </span></div>";
  358. parameters_menu = $(parameters_menu);
  359. dom_object.append(parameters_menu);
  360. for (let j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  361. renderMenu(command, variable_obj.parameters_list[j], parameters_menu.find(".parameter_" + j), function_obj, 2, expression_element);
  362. }
  363. let context_menu =
  364. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  365. context_menu +=
  366. '<div class="item" data-clear="true">' +
  367. LocalizedStrings.getUI("btn_clear") +
  368. "</div>";
  369. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  370. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  371. context_menu += '<div class="menu">';
  372. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  373. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  374. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  375. context_menu += '</div></div>';
  376. }*/
  377. context_menu += "</div></div>";
  378. context_menu = $(context_menu);
  379. context_menu.insertAfter(parameters_menu);
  380. context_menu.dropdown({
  381. onChange: function (value, text, $selectedItem) {
  382. if ($selectedItem.data("clear")) {
  383. dom_object.text("");
  384. variable_obj.content = null;
  385. variable_obj.row = null;
  386. variable_obj.column = null;
  387. delete variable_obj.function_called;
  388. delete variable_obj.parameters_list;
  389. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  390. }
  391. if ($selectedItem.data("exp")) {
  392. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  393. }
  394. },
  395. selectOnKeydown: false,
  396. });
  397. }
  398. } else if (variable_obj.content.type) {
  399. let variable_render = "";
  400. if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
  401. variable_render =
  402. '<div class="variable_rendered"> <span class="var_name">' +
  403. variable_obj.content.name +
  404. "</span>";
  405. if (variable_obj.reference_dimensions >= 1)
  406. variable_render += '';
  407. else
  408. variable_render +=
  409. ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  410. variable_render += "</div>";
  411. variable_render = $(variable_render);
  412. dom_object.append(variable_render);
  413. let context_menu =
  414. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  415. context_menu +=
  416. '<div class="item" data-clear="true">' +
  417. LocalizedStrings.getUI("btn_clear") +
  418. "</div>";
  419. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  420. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  421. context_menu += '<div class="menu">';
  422. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  423. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  424. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  425. context_menu += '</div></div>';
  426. }*/
  427. context_menu += "</div></div>";
  428. context_menu = $(context_menu);
  429. variable_render.append(context_menu);
  430. context_menu.dropdown({
  431. onChange: function (value, text, $selectedItem) {
  432. if ($selectedItem.data("clear")) {
  433. dom_object.text("");
  434. variable_obj.content = null;
  435. variable_obj.row = null;
  436. variable_obj.column = null;
  437. delete variable_obj.function_called;
  438. delete variable_obj.parameters_list;
  439. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  440. }
  441. if ($selectedItem.data("exp")) {
  442. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  443. }
  444. },
  445. selectOnKeydown: false,
  446. });
  447. if (!variable_obj.column) {
  448. var temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  449. if (variable_obj.reference)
  450. temp.reference_parent = true
  451. variable_obj.column = temp;
  452. }
  453. variableValueMenuCode(command, variable_obj.column, $(variable_render.find(".column_container")), function_obj, menu_var_or_value, expression_element);
  454. } else if (
  455. variable_obj.content.dimensions == 2 &&
  456. variable_obj.dimensions != 2
  457. ) {
  458. variable_render =
  459. '<div class="variable_rendered"> <span class="var_name">' +
  460. variable_obj.content.name +
  461. "</span>";
  462. variable_render +=
  463. ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  464. if (variable_obj.reference_dimensions == 0)
  465. variable_render +=
  466. ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  467. variable_render += "</div>";
  468. variable_render = $(variable_render);
  469. dom_object.append(variable_render);
  470. let context_menu =
  471. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  472. context_menu +=
  473. '<div class="item" data-clear="true">' +
  474. LocalizedStrings.getUI("btn_clear") +
  475. "</div>";
  476. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  477. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  478. context_menu += '<div class="menu">';
  479. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  480. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  481. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  482. context_menu += '</div></div>';
  483. }*/
  484. context_menu += "</div></div>";
  485. context_menu = $(context_menu);
  486. variable_render.append(context_menu);
  487. context_menu.dropdown({
  488. onChange: function (value, text, $selectedItem) {
  489. if ($selectedItem.data("clear")) {
  490. dom_object.text("");
  491. variable_obj.content = null;
  492. variable_obj.row = null;
  493. variable_obj.column = null;
  494. delete variable_obj.function_called;
  495. delete variable_obj.parameters_list;
  496. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  497. }
  498. if ($selectedItem.data("exp")) {
  499. AttribuitionsManagement.manageExpressionElements(
  500. command,
  501. variable_obj,
  502. dom_object,
  503. menu_var_or_value,
  504. function_obj,
  505. $selectedItem,
  506. expression_element
  507. );
  508. }
  509. },
  510. selectOnKeydown: false,
  511. });
  512. if (!variable_obj.column) {
  513. var temp = new Models.VariableValueMenu(
  514. VAR_OR_VALUE_TYPES.all,
  515. null,
  516. null,
  517. null,
  518. true
  519. );
  520. if (variable_obj.reference)
  521. temp.reference_parent = true
  522. variable_obj.column = temp
  523. }
  524. if (!variable_obj.row) {
  525. var temp = new Models.VariableValueMenu(
  526. VAR_OR_VALUE_TYPES.all,
  527. null,
  528. null,
  529. null,
  530. true
  531. );
  532. if (variable_obj.reference)
  533. temp.reference_parent = true
  534. variable_obj.row = temp
  535. }
  536. variableValueMenuCode(
  537. command,
  538. variable_obj.row,
  539. $(variable_render.find(".row_container")),
  540. function_obj,
  541. menu_var_or_value,
  542. expression_element
  543. );
  544. if (variable_obj.reference_dimensions == 1) {
  545. variable_obj.column = null
  546. } else {
  547. variableValueMenuCode(
  548. command,
  549. variable_obj.column,
  550. $(variable_render.find(".column_container")),
  551. function_obj,
  552. menu_var_or_value,
  553. expression_element
  554. );
  555. }
  556. } else {
  557. variable_render =
  558. '<div class="variable_rendered"> <span class="var_name">' +
  559. variable_obj.content.name +
  560. "</span>";
  561. variable_render += "</div>";
  562. variable_render = $(variable_render);
  563. dom_object.append(variable_render);
  564. let context_menu =
  565. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  566. context_menu +=
  567. '<div class="item" data-clear="true">' +
  568. LocalizedStrings.getUI("btn_clear") +
  569. "</div>";
  570. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  571. console.log('dom_object6');
  572. console.log(dom_object);
  573. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  574. context_menu += '<div class="menu">';
  575. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  576. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  577. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  578. context_menu += '</div></div>';
  579. }*/
  580. context_menu += "</div></div>";
  581. context_menu = $(context_menu);
  582. variable_render.append(context_menu);
  583. context_menu.dropdown({
  584. onChange: function (value, text, $selectedItem) {
  585. if ($selectedItem.data("clear")) {
  586. dom_object.text("");
  587. variable_obj.content = null;
  588. variable_obj.row = null;
  589. variable_obj.column = null;
  590. delete variable_obj.function_called;
  591. delete variable_obj.parameters_list;
  592. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  593. }
  594. if ($selectedItem.data("exp")) {
  595. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  596. }
  597. },
  598. selectOnKeydown: false,
  599. });
  600. }
  601. } else {
  602. let variable_render;
  603. variable_render =
  604. '<div class="variable_rendered"> <span class="var_name">';
  605. if (isNaN(variable_obj.content)) {
  606. variable_render += variable_obj.content.split(" ").join("&nbsp;");
  607. } else {
  608. variable_render += variable_obj.content;
  609. }
  610. variable_render += "</span>";
  611. variable_render += "</div>";
  612. variable_render = $(variable_render);
  613. dom_object.append(variable_render);
  614. var context_menu =
  615. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  616. context_menu +=
  617. '<div class="item" data-clear="true">' +
  618. LocalizedStrings.getUI("btn_clear") +
  619. "</div>";
  620. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  621. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  622. context_menu += '<div class="menu">';
  623. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  624. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  625. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  626. context_menu += '</div></div>';
  627. }*/
  628. context_menu += "</div></div>";
  629. context_menu = $(context_menu);
  630. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  631. context_menu.insertAfter(variable_render);
  632. }
  633. context_menu.dropdown({
  634. onChange: function (value, text, $selectedItem) {
  635. if ($selectedItem.data("clear")) {
  636. dom_object.text("");
  637. variable_obj.content = null;
  638. variable_obj.row = null;
  639. variable_obj.column = null;
  640. delete variable_obj.function_called;
  641. delete variable_obj.parameters_list;
  642. dom_object.find(".value_rendered").remove();
  643. dom_object.find(".context_menu_clear").remove();
  644. dom_object.find(".width-dynamic-minus").remove();
  645. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  646. }
  647. if ($selectedItem.data("exp")) {
  648. AttribuitionsManagement.manageExpressionElements(
  649. command,
  650. variable_obj,
  651. dom_object,
  652. menu_var_or_value,
  653. function_obj,
  654. $selectedItem,
  655. expression_element
  656. );
  657. }
  658. },
  659. selectOnKeydown: false,
  660. });
  661. variable_render.on("click", function (e) {
  662. variable_render.remove();
  663. variable_render.empty();
  664. variable_render.remove();
  665. dom_object.empty();
  666. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  667. openInputToValue(
  668. command,
  669. variable_obj,
  670. dom_object,
  671. menu_var_or_value,
  672. function_obj,
  673. expression_element
  674. );
  675. });
  676. }
  677. }
  678. function addIVProgFunctionsToMenu (
  679. function_obj,
  680. menu_var_or_value,
  681. ref_object,
  682. expression_element
  683. ) {
  684. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  685. sub_menu.append(
  686. '<div class="divider"></div><div class="header">' +
  687. LocalizedStrings.getUI("text_header_ivprog_functions") +
  688. "</div>"
  689. );
  690. sub_menu.append(
  691. '<div class="item"><i class="dropdown icon"></i>' +
  692. LocalizedStrings.getUI("text_menu_functions_math") +
  693. '<div class="menu menu_math_functions"></div></div>'
  694. );
  695. sub_menu.append(
  696. '<div class="item"><i class="dropdown icon"></i>' +
  697. LocalizedStrings.getUI("text_menu_functions_text") +
  698. '<div class="menu menu_text_functions"></div></div>'
  699. );
  700. sub_menu.append(
  701. '<div class="item"><i class="dropdown icon"></i>' +
  702. LocalizedStrings.getUI("text_menu_functions_array") +
  703. '<div class="menu menu_arrangement_functions"></div></div>'
  704. );
  705. sub_menu.append(
  706. '<div class="item"><i class="dropdown icon"></i>' +
  707. LocalizedStrings.getUI("text_menu_functions_conversion") +
  708. '<div class="menu menu_conversion_functions"></div></div>'
  709. );
  710. // Insert Math functions:
  711. for (let i = 0; i < window.system_functions.length; i++) {
  712. const t = $('<div class="item"></div>');
  713. t.data("function_reference", window.system_functions[i]);
  714. t.data("option", VAR_OR_VALUE_TYPES.only_function);
  715. t.text(LocalizedStrings.translateInternalFunction(window.system_functions[i].identifier));
  716. switch (window.system_functions[i].category) {
  717. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  718. sub_menu.find(".menu_math_functions").append(t);
  719. break;
  720. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  721. sub_menu.find(".menu_text_functions").append(t);
  722. break;
  723. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  724. sub_menu.find(".menu_arrangement_functions").append(t);
  725. break;
  726. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  727. sub_menu.find(".menu_conversion_functions").append(t);
  728. break;
  729. }
  730. }
  731. }
  732. function addFunctionsToMenu (
  733. function_obj,
  734. menu_var_or_value,
  735. ref_object,
  736. expression_element
  737. ) {
  738. const sub_menu = menu_var_or_value.find(".menu_only_functions");
  739. sub_menu.text("");
  740. for (let i = 0; i < window.program_obj.functions.length; i++) {
  741. const temp = $(
  742. '<div class="item" data-option="' +
  743. VAR_OR_VALUE_TYPES.only_function +
  744. '">' +
  745. window.program_obj.functions[i].name +
  746. " </div>"
  747. );
  748. temp.data("function_reference", window.program_obj.functions[i]);
  749. sub_menu.append(temp);
  750. }
  751. }
  752. function addVariablesToMenu (
  753. function_obj,
  754. menu_var_or_value,
  755. ref_object,
  756. expression_element
  757. ) {
  758. const sub_menu = menu_var_or_value.find(".menu_only_vars");
  759. sub_menu.text("");
  760. let is_there = false;
  761. if (window.program_obj.globals) {
  762. if (ref_object.include_constant) {
  763. for (var i = 0; i < window.program_obj.globals.length; i++) {
  764. var temp = $(
  765. '<div class="item" data-option="' +
  766. VAR_OR_VALUE_TYPES.only_variable +
  767. '">' +
  768. window.program_obj.globals[i].name +
  769. " </div>"
  770. );
  771. temp.data("variable_reference", window.program_obj.globals[i]);
  772. sub_menu.append(temp);
  773. is_there = true;
  774. }
  775. } else {
  776. for (var i = 0; i < window.program_obj.globals.length; i++) {
  777. if (!window.program_obj.globals[i].is_constant) {
  778. var temp = $(
  779. '<div class="item" data-option="' +
  780. VAR_OR_VALUE_TYPES.only_variable +
  781. '">' +
  782. window.program_obj.globals[i].name +
  783. " </div>"
  784. );
  785. temp.data("variable_reference", window.program_obj.globals[i]);
  786. sub_menu.append(temp);
  787. is_there = true;
  788. }
  789. }
  790. }
  791. }
  792. if (function_obj.parameters_list) {
  793. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  794. var temp = $(
  795. '<div class="item" data-option="' +
  796. VAR_OR_VALUE_TYPES.only_variable +
  797. '">' +
  798. function_obj.parameters_list[i].name +
  799. " </div>"
  800. );
  801. temp.data("variable_reference", function_obj.parameters_list[i]);
  802. sub_menu.append(temp);
  803. is_there = true;
  804. }
  805. }
  806. if (function_obj.variables_list) {
  807. for (var i = 0; i < function_obj.variables_list.length; i++) {
  808. var temp = $(
  809. '<div class="item" data-option="' +
  810. VAR_OR_VALUE_TYPES.only_variable +
  811. '">' +
  812. function_obj.variables_list[i].name +
  813. " </div>"
  814. );
  815. temp.data("variable_reference", function_obj.variables_list[i]);
  816. sub_menu.append(temp);
  817. is_there = true;
  818. }
  819. }
  820. if (!is_there) {
  821. sub_menu.append(
  822. $(
  823. '<div class="header">' +
  824. LocalizedStrings.getUI("text_no_variable") +
  825. "</div>"
  826. )
  827. );
  828. sub_menu.append(
  829. $(
  830. '<div class="item disabled">' +
  831. LocalizedStrings.getUI("text_no_variable_instruction") +
  832. "</div>"
  833. )
  834. );
  835. }
  836. }
  837. function addHandlers (
  838. command,
  839. ref_object,
  840. dom_object,
  841. menu_var_or_value,
  842. function_obj,
  843. expression_element
  844. ) {
  845. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  846. menu_var_or_value.dropdown({
  847. onChange: function (value, text, $selectedItem) {
  848. dom_object.find(".var_name").remove();
  849. switch ($selectedItem.data("option")) {
  850. case VAR_OR_VALUE_TYPES.only_function:
  851. openInputToFunction(
  852. command,
  853. ref_object,
  854. dom_object,
  855. menu_var_or_value,
  856. function_obj,
  857. $($selectedItem).data("function_reference"),
  858. expression_element
  859. );
  860. break;
  861. case VAR_OR_VALUE_TYPES.only_value:
  862. openInputToValue(
  863. command,
  864. ref_object,
  865. dom_object,
  866. menu_var_or_value,
  867. function_obj,
  868. expression_element
  869. );
  870. break;
  871. case VAR_OR_VALUE_TYPES.only_variable:
  872. openInputToVariable(
  873. command,
  874. ref_object,
  875. dom_object,
  876. menu_var_or_value,
  877. function_obj,
  878. $($selectedItem).data("variable_reference"),
  879. expression_element
  880. );
  881. break;
  882. }
  883. if ($selectedItem.data("exp")) {
  884. AttribuitionsManagement.manageExpressionElements(
  885. command,
  886. ref_object,
  887. dom_object,
  888. menu_var_or_value,
  889. function_obj,
  890. $selectedItem,
  891. expression_element
  892. );
  893. }
  894. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  895. RepeatNTimesManagement.manageExpressionElements(
  896. command,
  897. ref_object,
  898. dom_object,
  899. menu_var_or_value,
  900. function_obj,
  901. $selectedItem,
  902. expression_element
  903. );
  904. }
  905. },
  906. selectOnKeydown: false,
  907. });
  908. }
  909. dom_object
  910. .find(".width-dynamic")
  911. .on("input", function () {
  912. const inputWidth = $(this).textWidth() + 10;
  913. $(this).focus();
  914. const tmpStr = $(this).val();
  915. $(this).val("");
  916. $(this).val(tmpStr);
  917. $(this).css({
  918. width: inputWidth,
  919. });
  920. })
  921. .trigger("input");
  922. if (command.type == Models.COMMAND_TYPES.comment) {
  923. dom_object.parent().on("click", function (e) {
  924. dom_object.find(".value_rendered").remove();
  925. dom_object.find(".value_rendered").empty();
  926. dom_object.find(".value_rendered").remove();
  927. dom_object.empty();
  928. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  929. openInputToValue(
  930. command,
  931. ref_object,
  932. dom_object,
  933. menu_var_or_value,
  934. function_obj,
  935. expression_element
  936. );
  937. });
  938. }
  939. }
  940. function openInputToFunction (
  941. command,
  942. ref_object,
  943. dom_object,
  944. menu_var_or_value,
  945. function_obj,
  946. function_selected,
  947. expression_element
  948. ) {
  949. ref_object.function_called = function_selected;
  950. ref_object.parameters_list = [];
  951. if (
  952. function_selected.parameters_list != null &&
  953. function_selected.parameters_list.length > 0
  954. ) {
  955. menu_var_or_value.find(".text").text(" ");
  956. dom_object.find(".menu_var_or_value_dom").remove();
  957. var parameters_menu;
  958. if (function_selected.name) {
  959. parameters_menu =
  960. '<div class="parameters_function_called"> ' +
  961. function_selected.name +
  962. " <span> ( </span>";
  963. } else {
  964. parameters_menu =
  965. '<div class="parameters_function_called"> <i>' +
  966. LocalizedStrings.translateInternalFunction(function_selected.identifier, function_selected.category) +
  967. "</i> <span> ( </span>\n";
  968. }
  969. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  970. parameters_menu += '<div class="render_style_param parameter_' + j + '"></div>';
  971. if (j + 1 != function_selected.parameters_list.length) {
  972. parameters_menu += " , ";
  973. }
  974. }
  975. parameters_menu += "<span> ) </span></div>\n";
  976. parameters_menu = $(parameters_menu);
  977. dom_object.append(parameters_menu);
  978. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  979. var temp;
  980. if (function_selected.parameters_list[j].dimensions > 0) {
  981. temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.variable_and_function, null, null, null, true, function_selected.parameters_list[j].dimensions);
  982. } else {
  983. temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  984. }
  985. if (function_selected.parameters_list[j].reference == true) {
  986. temp.reference = true;
  987. temp.variable_and_value = VAR_OR_VALUE_TYPES.only_variable;
  988. } else {
  989. temp.reference = false;
  990. temp.variable_and_value = VAR_OR_VALUE_TYPES.all;
  991. }
  992. temp.reference_dimensions = function_selected.parameters_list[j].dimensions
  993. ref_object.parameters_list.push(temp);
  994. renderMenu(command, temp, parameters_menu.find(".parameter_" + j), function_obj, 2, expression_element);
  995. }
  996. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  997. context_menu +=
  998. '<div class="item" data-clear="true">' +
  999. LocalizedStrings.getUI("btn_clear") +
  1000. "</div>";
  1001. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1002. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1003. context_menu += '<div class="menu">';
  1004. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1005. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1006. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1007. context_menu += '</div></div>';
  1008. }*/
  1009. context_menu += "</div></div>\n";
  1010. context_menu = $(context_menu);
  1011. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1012. context_menu.dropdown({
  1013. onChange: function (value, text, $selectedItem) {
  1014. if ($selectedItem.data("clear")) {
  1015. dom_object.text("");
  1016. ref_object.content = null;
  1017. ref_object.row = null;
  1018. ref_object.column = null;
  1019. delete ref_object.function_called;
  1020. delete ref_object.parameters_list;
  1021. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  1022. }
  1023. if ($selectedItem.data("exp")) {
  1024. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  1025. }
  1026. },
  1027. selectOnKeydown: false,
  1028. });
  1029. } else {
  1030. menu_var_or_value.find(".text").text(" ");
  1031. dom_object.find(".menu_var_or_value_dom").remove();
  1032. var parameters_menu;
  1033. if (function_selected.name) {
  1034. parameters_menu =
  1035. '<div class="parameters_function_called"> ' +
  1036. function_selected.name +
  1037. " <span> ( </span>";
  1038. } else {
  1039. parameters_menu =
  1040. '<div class="parameters_function_called"> <i>' +
  1041. LocalizedStrings.translateInternalFunction(function_selected.identifier, function_selected.category) +
  1042. "</i> <span> ( </span>";
  1043. }
  1044. parameters_menu += "<span> ) </span></div>";
  1045. parameters_menu = $(parameters_menu);
  1046. dom_object.append(parameters_menu);
  1047. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1048. context_menu +=
  1049. '<div class="item" data-clear="true">' +
  1050. LocalizedStrings.getUI("btn_clear") +
  1051. "</div>";
  1052. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1053. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1054. context_menu += '<div class="menu">';
  1055. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1056. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1057. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1058. context_menu += '</div></div>';
  1059. }*/
  1060. context_menu += "</div></div>";
  1061. context_menu = $(context_menu);
  1062. context_menu.insertAfter(dom_object.find(".parameters_function_called"));
  1063. context_menu.dropdown({
  1064. onChange: function (value, text, $selectedItem) {
  1065. if ($selectedItem.data("clear")) {
  1066. dom_object.text("");
  1067. ref_object.content = null;
  1068. ref_object.row = null;
  1069. ref_object.column = null;
  1070. delete ref_object.function_called;
  1071. delete ref_object.parameters_list;
  1072. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  1073. }
  1074. if ($selectedItem.data("exp")) {
  1075. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  1076. }
  1077. },
  1078. selectOnKeydown: false,
  1079. });
  1080. }
  1081. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1082. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1083. }*/
  1084. }
  1085. function openInputToVariable (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected, expression_element) {
  1086. ref_object.content = variable_selected;
  1087. menu_var_or_value.find(".text").text(" ");
  1088. dom_object.find(".menu_var_or_value_dom").remove();
  1089. let variable_render =
  1090. '<div class="variable_rendered"> <span class="var_name">' +
  1091. variable_selected.name +
  1092. "</span>";
  1093. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1094. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1095. }
  1096. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1097. variable_render += ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  1098. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  1099. }
  1100. variable_render += "</div>";
  1101. variable_render = $(variable_render);
  1102. dom_object.append(variable_render);
  1103. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  1104. var temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  1105. if (ref_object.reference)
  1106. temp.reference_parent = true
  1107. ref_object.column = temp
  1108. renderMenu(command, ref_object.column, variable_render.find(".column_container"), function_obj, 2, expression_element);
  1109. }
  1110. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  1111. var temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  1112. if (ref_object.reference)
  1113. temp.reference_parent = true
  1114. ref_object.row = temp
  1115. renderMenu(command, ref_object.row, variable_render.find(".row_container"), function_obj, 2, expression_element);
  1116. var temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  1117. if (ref_object.reference)
  1118. temp.reference_parent = true
  1119. ref_object.column = temp
  1120. renderMenu(command, ref_object.column, variable_render.find(".column_container"), function_obj, 2, expression_element);
  1121. }
  1122. let context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1123. context_menu +=
  1124. '<div class="item" data-clear="true">' +
  1125. LocalizedStrings.getUI("btn_clear") +
  1126. "</div>";
  1127. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  1128. console.log("dom_object 10: ");
  1129. console.log(dom_object);
  1130. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1131. context_menu += '<div class="menu">';
  1132. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1133. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1134. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1135. context_menu += '</div></div>';
  1136. }*/
  1137. context_menu += "</div></div>";
  1138. context_menu = $(context_menu);
  1139. context_menu.insertAfter(dom_object.find(".variable_rendered"));
  1140. context_menu.dropdown({
  1141. onChange: function (value, text, $selectedItem) {
  1142. if ($selectedItem.data("clear")) {
  1143. dom_object.text("");
  1144. ref_object.content = null;
  1145. ref_object.row = null;
  1146. ref_object.column = null;
  1147. delete ref_object.function_called;
  1148. delete ref_object.parameters_list;
  1149. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  1150. }
  1151. if ($selectedItem.data("exp")) {
  1152. AttribuitionsManagement.manageExpressionElements( command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  1153. }
  1154. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  1155. RepeatNTimesManagement.manageClearExpressionElements( command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  1156. }
  1157. },
  1158. selectOnKeydown: false,
  1159. });
  1160. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1161. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  1162. }*/
  1163. }
  1164. function openInputToValue (
  1165. command,
  1166. ref_object,
  1167. dom_object,
  1168. menu_var_or_value,
  1169. function_obj,
  1170. expression_element
  1171. ) {
  1172. if (ref_object.content == null) {
  1173. ref_object.content = "";
  1174. }
  1175. menu_var_or_value.find(".text").text(" ");
  1176. const field = $(
  1177. '<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'
  1178. );
  1179. field.insertBefore(dom_object.find(".menu_var_or_value_dom"));
  1180. field.on('input', function() {
  1181. var input_field = $(this);
  1182. var inputWidth = input_field.textWidth()+10;
  1183. inputWidth = inputWidth<50?50:inputWidth;
  1184. input_field.css({ width: inputWidth
  1185. })
  1186. }).trigger('input');
  1187. const rendered = $('<div class="value_rendered"></div>');
  1188. rendered.insertBefore(field);
  1189. field.focus();
  1190. field.val(ref_object.content);
  1191. let context_menu =
  1192. '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  1193. context_menu +=
  1194. '<div class="item" data-clear="true">' +
  1195. LocalizedStrings.getUI("btn_clear") +
  1196. "</div>";
  1197. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1198. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  1199. context_menu += '<div class="menu">';
  1200. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  1201. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  1202. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  1203. context_menu += '</div></div>';
  1204. }*/
  1205. context_menu += "</div></div>";
  1206. context_menu = $(context_menu);
  1207. dom_object.find(".menu_var_or_value_dom").remove();
  1208. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  1209. context_menu.insertAfter(field);
  1210. }
  1211. context_menu.dropdown({
  1212. onChange: function (value, text, $selectedItem) {
  1213. if ($selectedItem.data("clear")) {
  1214. dom_object.text("");
  1215. dom_object.find(".value_rendered").remove();
  1216. dom_object.find(".context_menu_clear").remove();
  1217. dom_object.find(".width-dynamic-minus").remove();
  1218. ref_object.content = null;
  1219. ref_object.row = null;
  1220. ref_object.column = null;
  1221. delete ref_object.function_called;
  1222. delete ref_object.parameters_list;
  1223. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  1224. }
  1225. if ($selectedItem.data("exp")) {
  1226. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element
  1227. );
  1228. }
  1229. },
  1230. selectOnKeydown: false,
  1231. });
  1232. dom_object.find(".width-dynamic-minus").focusout(function () {
  1233. //if ($(this).val().trim()) { ref_object.content = $(this).val().trim();}
  1234. ref_object.content = $(this)
  1235. .val();
  1236. if (isNaN(ref_object.content)) {
  1237. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1238. } else {
  1239. rendered.text(ref_object.content);
  1240. }
  1241. $(this).remove();
  1242. });
  1243. dom_object.find(".width-dynamic-minus").on("keydown", function (e) {
  1244. const code = e.keyCode || e.which;
  1245. if (code == 13) {
  1246. //if ($(this).val().trim()) { ref_object.content = $(this).val().trim();}
  1247. ref_object.content = $(this).val();
  1248. if (isNaN(ref_object.content)) {
  1249. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1250. } else {
  1251. rendered.text(ref_object.content);
  1252. }
  1253. $(this).remove();
  1254. }
  1255. if (code == 27) {
  1256. if (isNaN(ref_object.content)) {
  1257. rendered.html(ref_object.content.split(" ").join("&nbsp;"));
  1258. } else {
  1259. rendered.text(ref_object.content);
  1260. }
  1261. $(this).remove();
  1262. }
  1263. });
  1264. if (command.type == Models.COMMAND_TYPES.comment) {
  1265. /*rendered.parent().on('click', function(e) {
  1266. rendered.parent().off();
  1267. console.log("TTT14");
  1268. rendered.remove();
  1269. rendered.empty();
  1270. rendered.remove();
  1271. dom_object.empty();
  1272. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1273. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  1274. });*/
  1275. }
  1276. rendered.on("click", function (e) {
  1277. rendered.empty();
  1278. rendered.remove();
  1279. dom_object.empty();
  1280. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  1281. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  1282. });
  1283. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  1284. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  1285. }*/
  1286. }
  1287. $.fn.textWidth = function (text, font) {
  1288. if (!$.fn.textWidth.fakeEl)
  1289. $.fn.textWidth.fakeEl = $("<span>").hide().appendTo(document.body);
  1290. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr("placeholder")).css("font", font || this.css("font"));
  1291. return $.fn.textWidth.fakeEl.width();
  1292. };