variable_value_menu.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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({only_variable: 1, only_value: 2, only_function: 3, variable_and_function: 4, variable_and_value_opt: 5,
  6. value_and_function: 6, all: 7});
  7. export function renderMenu (command, ref_object, dom_object, function_obj, size_field = 2, expression_element) {
  8. // Verificar se o objeto atual trata-se de uma chamada de função e conferir se possui a quantidade correta de parâmetros
  9. // Caso não possua, tem que adicionar as variáveis que servirão de parâmetros:
  10. if (ref_object.function_called) {
  11. if (ref_object.function_called.parameters_list) {
  12. while (ref_object.function_called.parameters_list.length != ref_object.parameters_list.length) {
  13. if (ref_object.parameters_list.length > ref_object.function_called.parameters_list.length) {
  14. ref_object.parameters_list.pop();
  15. } else {
  16. ref_object.parameters_list.push(new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true));
  17. }
  18. }
  19. }
  20. }
  21. var 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">';
  22. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_variable) {
  23. 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">';
  24. menu_var_or_value += '</div>';
  25. }
  26. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_value_opt) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  27. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('variable');
  28. menu_var_or_value += '<div class="menu menu_only_vars">';
  29. menu_var_or_value += '</div></div>';
  30. }
  31. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_value) {
  32. menu_var_or_value = '<input type="text" class="width-dynamic" size="'+size_field+'" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />';
  33. }
  34. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_value_opt)
  35. || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  36. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_value+'">'+LocalizedStrings.getUI('text_value')+'</div>';
  37. }
  38. if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_function) {
  39. 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">';
  40. menu_var_or_value += '</div>';
  41. }
  42. if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function)
  43. || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.value_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
  44. menu_var_or_value += '<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_function+'"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('btn_function');
  45. menu_var_or_value += '<div class="menu menu_only_functions">';
  46. menu_var_or_value += '</div></div>';
  47. /* if (command.type == Models.COMMAND_TYPES.attribution) {
  48. menu_var_or_value += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  49. menu_var_or_value += '<div class="menu">';
  50. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  51. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  52. menu_var_or_value += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  53. menu_var_or_value += '</div></div>';
  54. }*/
  55. }
  56. menu_var_or_value += '</div></div>';
  57. menu_var_or_value = $(menu_var_or_value);
  58. dom_object.append(menu_var_or_value);
  59. ref_object.dom_object = menu_var_or_value;
  60. addHandlers(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  61. addVariablesToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  62. addFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  63. addIVProgFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
  64. if (ref_object.content || ref_object.function_called) {
  65. if (ref_object.content) {
  66. // Verificar se a variável ainda existe:
  67. var variable_fun = isVarInProgram(ref_object.content, function_obj);
  68. if (variable_fun) {
  69. ref_object.content = variable_fun;
  70. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  71. } else {
  72. if (ref_object.content && ref_object.content.type) {
  73. ref_object.content = null;
  74. appendSelectText(ref_object, menu_var_or_value);
  75. } else {
  76. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  77. }
  78. }
  79. } else if (ref_object.function_called) {
  80. // Verificar se a função ainda existe:
  81. var ret_function = isFunctionInProgram(ref_object.function_called);
  82. if (ret_function) {
  83. ref_object.function_called = ret_function;
  84. renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
  85. } else {
  86. ref_object.content = null;
  87. ref_object.row = null;
  88. ref_object.column = null;
  89. delete ref_object.function_called;
  90. delete ref_object.parameters_list;
  91. appendSelectText(ref_object, menu_var_or_value);
  92. }
  93. }
  94. } else {
  95. appendSelectText(ref_object, menu_var_or_value);
  96. }
  97. }
  98. function appendSelectText (ref_object, menu_var_or_value) {
  99. switch(ref_object.variable_and_value) {
  100. case VAR_OR_VALUE_TYPES.only_variable:
  101. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_var')+'</i>');
  102. break;
  103. case VAR_OR_VALUE_TYPES.all:
  104. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_all')+'</i>');
  105. break;
  106. case VAR_OR_VALUE_TYPES.variable_and_function:
  107. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_all')+'</i>');
  108. break;
  109. case VAR_OR_VALUE_TYPES.only_function:
  110. menu_var_or_value.find('.text').append('<i>'+LocalizedStrings.getUI('var_menu_select_function')+'</i>');
  111. break;
  112. }
  113. }
  114. function isFunctionInProgram (function_called_obj) {
  115. if (function_called_obj.name) {
  116. if (window.program_obj.functions) {
  117. for (var i = 0; i < window.program_obj.functions.length; i++) {
  118. if (window.program_obj.functions[i] == function_called_obj) {
  119. return window.program_obj.functions[i];
  120. }
  121. }
  122. for (var i = 0; i < window.program_obj.functions.length; i++) {
  123. if (window.program_obj.functions[i].name == function_called_obj.name) {
  124. return window.program_obj.functions[i];
  125. }
  126. }
  127. }
  128. } else if (function_called_obj.identifier) {
  129. for (var i = 0; i < window.system_functions.length; i++) {
  130. if (window.system_functions[i].identifier == function_called_obj.identifier) {
  131. return window.system_functions[i];
  132. }
  133. }
  134. }
  135. return null;
  136. }
  137. function isVarInProgram (var_obj, function_obj) {
  138. // Verify in locals:
  139. if (function_obj.variables_list) {
  140. for (var i = 0; i < function_obj.variables_list.length; i++) {
  141. if (function_obj.variables_list[i] == var_obj) {
  142. return function_obj.variables_list[i];
  143. }
  144. }
  145. }
  146. // Verify in parameters:
  147. if (function_obj.parameters_list) {
  148. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  149. if (function_obj.parameters_list[i] == var_obj) {
  150. return function_obj.parameters_list[i];
  151. }
  152. }
  153. }
  154. // Verify in globals:
  155. if (window.program_obj.globals) {
  156. for (var i = 0; i < window.program_obj.globals.length; i++) {
  157. if (window.program_obj.globals[i] == var_obj) {
  158. return window.program_obj.globals[i];
  159. }
  160. }
  161. }
  162. // If not found, verify if the reference was lost
  163. if (var_obj) {
  164. if (function_obj.variables_list) {
  165. for (var i = 0; i < function_obj.variables_list.length; i++) {
  166. if (function_obj.variables_list[i].name == var_obj.name) {
  167. return function_obj.variables_list[i];
  168. }
  169. }
  170. }
  171. if (function_obj.parameters_list) {
  172. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  173. if (function_obj.parameters_list[i].name == var_obj.name) {
  174. return function_obj.parameters_list[i];
  175. }
  176. }
  177. }
  178. if (window.program_obj.globals) {
  179. for (var i = 0; i < window.program_obj.globals.length; i++) {
  180. if (window.program_obj.globals[i].name == var_obj.name) {
  181. return window.program_obj.globals[i];
  182. }
  183. }
  184. }
  185. }
  186. return null;
  187. }
  188. function renderPreviousContent (function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element) {
  189. if (ref_object.function_called) {
  190. menu_var_or_value.remove();
  191. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  192. } else if (ref_object.content.type) {
  193. menu_var_or_value.remove();
  194. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  195. } else {
  196. menu_var_or_value.remove();
  197. variableValueMenuCode(command, ref_object, dom_object, function_obj, menu_var_or_value, expression_element);
  198. }
  199. }
  200. function variableValueMenuCode (command, variable_obj, dom_object, function_obj, menu_var_or_value, expression_element) {
  201. if (variable_obj.content || variable_obj.function_called) {
  202. // Verificar se a variável ainda existe:
  203. var var_fun = isVarInProgram(variable_obj.content, function_obj);
  204. if (var_fun) {
  205. variable_obj.content = var_fun;
  206. } else {
  207. if (variable_obj.content && variable_obj.content.type) {
  208. variable_obj.content = null;
  209. appendSelectText(variable_obj, menu_var_or_value);
  210. }
  211. }
  212. } else {
  213. appendSelectText(variable_obj, menu_var_or_value);
  214. }
  215. if (variable_obj.content == null && variable_obj.function_called == null) {
  216. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  217. return;
  218. }
  219. var ret = '';
  220. if (variable_obj.function_called) {
  221. if (variable_obj.function_called.parameters_list == null || variable_obj.function_called.length == 0) {
  222. menu_var_or_value.find('.text').text(' ');
  223. dom_object.find('.menu_var_or_value_dom').remove();
  224. var parameters_menu;
  225. if (variable_obj.function_called.name) {
  226. parameters_menu = '<div class="parameters_function_called"> '+variable_obj.function_called.name+' <span> ( </span>';
  227. } else {
  228. parameters_menu = '<div class="parameters_function_called"> <i>'+ LocalizedStrings.translateInternalFunction(variable_obj.function_called.identifier, variable_obj.function_called.category)+'</i> <span> ( </span>';
  229. }
  230. parameters_menu += '<span> ) </span></div>';
  231. parameters_menu = $(parameters_menu);
  232. dom_object.append(parameters_menu);
  233. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  234. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  235. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  236. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  237. context_menu += '<div class="menu">';
  238. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  239. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  240. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  241. context_menu += '</div></div>';
  242. }*/
  243. context_menu += '</div></div>';
  244. context_menu = $(context_menu);
  245. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  246. context_menu.dropdown({
  247. onChange: function(value, text, $selectedItem) {
  248. console.log('S1');
  249. if ($selectedItem.data('clear')) {
  250. console.log('PP1');
  251. dom_object.text('');
  252. variable_obj.content = null;
  253. variable_obj.row = null;
  254. variable_obj.column = null;
  255. delete variable_obj.function_called;
  256. delete variable_obj.parameters_list;
  257. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  258. }
  259. if ($selectedItem.data('exp')) {
  260. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  261. }
  262. },
  263. selectOnKeydown: false
  264. });
  265. } else {
  266. menu_var_or_value.find('.text').text(' ');
  267. dom_object.find('.menu_var_or_value_dom').remove();
  268. var parameters_menu;
  269. if (variable_obj.function_called.name) {
  270. parameters_menu = '<div class="parameters_function_called"> '+variable_obj.function_called.name+' <span> ( </span>';
  271. } else {
  272. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.translateInternalFunction(variable_obj.function_called.identifier, variable_obj.function_called.category)+'</i> <span> ( </span>';
  273. }
  274. for (var j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  275. parameters_menu += '<div class="render_style_param parameter_'+j+'"></div>';
  276. if ((j + 1) != variable_obj.function_called.parameters_list.length) {
  277. parameters_menu += ' , ';
  278. }
  279. }
  280. parameters_menu += '<span> ) </span></div>';
  281. parameters_menu = $(parameters_menu);
  282. dom_object.append(parameters_menu);
  283. for (var j = 0; j < variable_obj.function_called.parameters_list.length; j++) {
  284. renderMenu(command, variable_obj.parameters_list[j], parameters_menu.find('.parameter_'+j), function_obj, 2, expression_element);
  285. }
  286. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  287. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  288. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  289. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  290. context_menu += '<div class="menu">';
  291. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  292. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  293. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  294. context_menu += '</div></div>';
  295. }*/
  296. context_menu += '</div></div>';
  297. context_menu = $(context_menu);
  298. context_menu.insertAfter( parameters_menu );
  299. context_menu.dropdown({
  300. onChange: function(value, text, $selectedItem) {
  301. console.log('S2');
  302. if ($selectedItem.data('clear')) {
  303. console.log('PP2');
  304. dom_object.text('');
  305. variable_obj.content = null;
  306. variable_obj.row = null;
  307. variable_obj.column = null;
  308. delete variable_obj.function_called;
  309. delete variable_obj.parameters_list;
  310. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  311. }
  312. if ($selectedItem.data('exp')) {
  313. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  314. }
  315. },
  316. selectOnKeydown: false
  317. });
  318. }
  319. } else if (variable_obj.content.type) {
  320. var variable_render = "";
  321. if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
  322. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  323. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  324. variable_render += '</div>';
  325. variable_render = $(variable_render);
  326. dom_object.append(variable_render);
  327. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  328. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  329. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  330. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  331. context_menu += '<div class="menu">';
  332. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  333. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  334. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  335. context_menu += '</div></div>';
  336. }*/
  337. context_menu += '</div></div>';
  338. context_menu = $(context_menu);
  339. variable_render.append(context_menu);
  340. context_menu.dropdown({
  341. onChange: function(value, text, $selectedItem) {
  342. console.log('S3');
  343. if ($selectedItem.data('clear')) {
  344. console.log('PP3');
  345. dom_object.text('');
  346. variable_obj.content = null;
  347. variable_obj.row = null;
  348. variable_obj.column = null;
  349. delete variable_obj.function_called;
  350. delete variable_obj.parameters_list;
  351. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  352. }
  353. if ($selectedItem.data('exp')) {
  354. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  355. }
  356. },
  357. selectOnKeydown: false
  358. });
  359. if (!variable_obj.column) {
  360. variable_obj.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  361. }
  362. variableValueMenuCode(command, variable_obj.column, $(variable_render.find('.column_container')), function_obj, menu_var_or_value, expression_element);
  363. } else if (variable_obj.content.dimensions == 2 && variable_obj.dimensions != 2) {
  364. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  365. variable_render += ' <span>[ </span> <div class="row_container"></div> <span> ]</span>';
  366. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ] </span>';
  367. variable_render += '</div>';
  368. variable_render = $(variable_render);
  369. dom_object.append(variable_render);
  370. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  371. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  372. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  373. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  374. context_menu += '<div class="menu">';
  375. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  376. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  377. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  378. context_menu += '</div></div>';
  379. }*/
  380. context_menu += '</div></div>';
  381. context_menu = $(context_menu);
  382. variable_render.append(context_menu);
  383. context_menu.dropdown({
  384. onChange: function(value, text, $selectedItem) {
  385. console.log('S4');
  386. if ($selectedItem.data('clear')) {
  387. console.log('PP4');
  388. dom_object.text('');
  389. variable_obj.content = null;
  390. variable_obj.row = null;
  391. variable_obj.column = null;
  392. delete variable_obj.function_called;
  393. delete variable_obj.parameters_list;
  394. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  395. }
  396. if ($selectedItem.data('exp')) {
  397. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  398. }
  399. },
  400. selectOnKeydown: false
  401. });
  402. if (!variable_obj.column) {
  403. variable_obj.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  404. }
  405. if (!variable_obj.row) {
  406. variable_obj.row = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  407. }
  408. variableValueMenuCode(command, variable_obj.row, $(variable_render.find('.row_container')), function_obj, menu_var_or_value, expression_element);
  409. variableValueMenuCode(command, variable_obj.column, $(variable_render.find('.column_container')), function_obj, menu_var_or_value, expression_element);
  410. } else {
  411. variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content.name+'</span>';
  412. variable_render += '</div>';
  413. variable_render = $(variable_render);
  414. dom_object.append(variable_render);
  415. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  416. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  417. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  418. console.log('dom_object6');
  419. console.log(dom_object);
  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. console.log('S5');
  433. if ($selectedItem.data('clear')) {
  434. console.log('PP5');
  435. dom_object.text('');
  436. variable_obj.content = null;
  437. variable_obj.row = null;
  438. variable_obj.column = null;
  439. delete variable_obj.function_called;
  440. delete variable_obj.parameters_list;
  441. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  442. }
  443. if ($selectedItem.data('exp')) {
  444. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  445. }
  446. },
  447. selectOnKeydown: false
  448. });
  449. }
  450. } else {
  451. var variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_obj.content+'</span>';
  452. variable_render += '</div>';
  453. variable_render = $(variable_render);
  454. dom_object.append(variable_render);
  455. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  456. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  457. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  458. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  459. context_menu += '<div class="menu">';
  460. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  461. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  462. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  463. context_menu += '</div></div>';
  464. }*/
  465. context_menu += '</div></div>';
  466. context_menu = $(context_menu);
  467. if (variable_obj.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  468. context_menu.insertAfter( variable_render );
  469. }
  470. context_menu.dropdown({
  471. onChange: function(value, text, $selectedItem) {
  472. console.log('S6');
  473. if ($selectedItem.data('clear')) {
  474. console.log('PP6');
  475. dom_object.text('');
  476. variable_obj.content = null;
  477. variable_obj.row = null;
  478. variable_obj.column = null;
  479. delete variable_obj.function_called;
  480. delete variable_obj.parameters_list;
  481. dom_object.find('.value_rendered').remove();
  482. dom_object.find('.context_menu_clear').remove();
  483. dom_object.find('.width-dynamic-minus').remove();
  484. renderMenu(command, variable_obj, dom_object, function_obj, 2, expression_element);
  485. }
  486. if ($selectedItem.data('exp')) {
  487. AttribuitionsManagement.manageExpressionElements(command, variable_obj, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  488. }
  489. },
  490. selectOnKeydown: false
  491. });
  492. variable_render.on('click', function(e) {
  493. variable_render.remove();
  494. variable_render.empty();
  495. variable_render.remove();
  496. dom_object.empty();
  497. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  498. openInputToValue(command, variable_obj, dom_object, menu_var_or_value, function_obj, expression_element);
  499. });
  500. }
  501. }
  502. function addIVProgFunctionsToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  503. var sub_menu = menu_var_or_value.find('.menu_only_functions');
  504. sub_menu.append('<div class="divider"></div><div class="header">'+LocalizedStrings.getUI('text_header_ivprog_functions')+'</div>');
  505. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_math')+'<div class="menu menu_math_functions"></div></div>');
  506. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_text')+'<div class="menu menu_text_functions"></div></div>');
  507. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_array')+'<div class="menu menu_arrangement_functions"></div></div>');
  508. sub_menu.append('<div class="item"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_menu_functions_conversion')+'<div class="menu menu_conversion_functions"></div></div>');
  509. // Insert Math functions:
  510. for (var i = 0; i < window.system_functions.length; i++) {
  511. var t = $('<div class="item"></div>');
  512. t.data('function_reference', window.system_functions[i]);
  513. t.data('option', VAR_OR_VALUE_TYPES.only_function);
  514. t.text(LocalizedStrings.translateInternalFunction(window.system_functions[i].identifier));
  515. switch(window.system_functions[i].category) {
  516. case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
  517. sub_menu.find('.menu_math_functions').append(t);
  518. break;
  519. case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
  520. sub_menu.find('.menu_text_functions').append(t);
  521. break;
  522. case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
  523. sub_menu.find('.menu_arrangement_functions').append(t);
  524. break;
  525. case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
  526. sub_menu.find('.menu_conversion_functions').append(t);
  527. break;
  528. }
  529. }
  530. }
  531. function addFunctionsToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  532. var sub_menu = menu_var_or_value.find('.menu_only_functions');
  533. sub_menu.text('');
  534. for (var i = 0; i < window.program_obj.functions.length; i++) {
  535. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_function+'">' + window.program_obj.functions[i].name + ' </div>');
  536. temp.data('function_reference', window.program_obj.functions[i]);
  537. sub_menu.append(temp);
  538. }
  539. }
  540. function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expression_element) {
  541. var sub_menu = menu_var_or_value.find('.menu_only_vars');
  542. sub_menu.text('');
  543. var is_there = false;
  544. if (window.program_obj.globals) {
  545. if (ref_object.include_constant) {
  546. for (var i = 0; i < window.program_obj.globals.length; i++) {
  547. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
  548. temp.data('variable_reference', window.program_obj.globals[i]);
  549. sub_menu.append(temp);
  550. is_there = true;
  551. }
  552. } else {
  553. for (var i = 0; i < window.program_obj.globals.length; i++) {
  554. if (!window.program_obj.globals[i].is_constant) {
  555. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
  556. temp.data('variable_reference', window.program_obj.globals[i]);
  557. sub_menu.append(temp);
  558. is_there = true;
  559. }
  560. }
  561. }
  562. }
  563. if (function_obj.parameters_list) {
  564. for (var i = 0; i < function_obj.parameters_list.length; i++) {
  565. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.parameters_list[i].name + ' </div>');
  566. temp.data('variable_reference', function_obj.parameters_list[i]);
  567. sub_menu.append(temp);
  568. is_there = true;
  569. }
  570. }
  571. if (function_obj.variables_list) {
  572. for (var i = 0; i < function_obj.variables_list.length; i++) {
  573. var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.variables_list[i].name + ' </div>');
  574. temp.data('variable_reference', function_obj.variables_list[i]);
  575. sub_menu.append(temp);
  576. is_there = true;
  577. }
  578. }
  579. if (!is_there) {
  580. sub_menu.append($('<div class="header">'+LocalizedStrings.getUI('text_no_variable')+'</div>'));
  581. sub_menu.append($('<div class="item disabled">'+LocalizedStrings.getUI('text_no_variable_instruction')+'</div>'));
  582. }
  583. }
  584. function addHandlers (command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element) {
  585. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  586. menu_var_or_value.dropdown({
  587. onChange: function(value, text, $selectedItem) {
  588. console.log('S7');
  589. dom_object.find('.var_name').remove();
  590. switch ($selectedItem.data('option')) {
  591. case VAR_OR_VALUE_TYPES.only_function:
  592. openInputToFunction(command, ref_object, dom_object, menu_var_or_value, function_obj, $($selectedItem).data('function_reference'), expression_element);
  593. break;
  594. case VAR_OR_VALUE_TYPES.only_value:
  595. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element);
  596. break;
  597. case VAR_OR_VALUE_TYPES.only_variable:
  598. openInputToVariable(command, ref_object, dom_object, menu_var_or_value, function_obj, $($selectedItem).data('variable_reference'), expression_element);
  599. break;
  600. }
  601. if ($selectedItem.data('exp')) {
  602. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  603. }
  604. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  605. RepeatNTimesManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  606. }
  607. },
  608. selectOnKeydown: false
  609. });
  610. }
  611. dom_object.find('.width-dynamic').on('input', function() {
  612. var inputWidth = $(this).textWidth()+10;
  613. $(this).focus();
  614. var tmpStr = $(this).val();
  615. $(this).val('');
  616. $(this).val(tmpStr);
  617. $(this).css({
  618. width: inputWidth
  619. })
  620. }).trigger('input');
  621. if (command.type == Models.COMMAND_TYPES.comment) {
  622. dom_object.parent().on('click', function(e) {
  623. dom_object.find('.value_rendered').remove();
  624. dom_object.find('.value_rendered').empty();
  625. dom_object.find('.value_rendered').remove();
  626. dom_object.empty();
  627. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  628. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  629. });
  630. }
  631. }
  632. function openInputToFunction (command, ref_object, dom_object, menu_var_or_value, function_obj, function_selected, expression_element) {
  633. ref_object.function_called = function_selected;
  634. ref_object.parameters_list = [];
  635. if (function_selected.parameters_list != null && function_selected.parameters_list.length > 0) {
  636. menu_var_or_value.find('.text').text(' ');
  637. dom_object.find('.menu_var_or_value_dom').remove();
  638. var parameters_menu;
  639. if (function_selected.name) {
  640. parameters_menu = '<div class="parameters_function_called"> '+function_selected.name+' <span> ( </span>';
  641. } else {
  642. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.translateInternalFunction(function_selected.identifier, function_selected.category)+'</i> <span> ( </span>';
  643. }
  644. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  645. parameters_menu += '<div class="render_style_param parameter_'+j+'"></div>';
  646. if ((j + 1) != function_selected.parameters_list.length) {
  647. parameters_menu += ' , ';
  648. }
  649. }
  650. parameters_menu += '<span> ) </span></div>';
  651. parameters_menu = $(parameters_menu);
  652. dom_object.append(parameters_menu);
  653. for (var j = 0; j < function_selected.parameters_list.length; j++) {
  654. var temp;
  655. if (function_selected.parameters_list[j].dimensions > 0) {
  656. temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.variable_and_function, null, null, null, true, function_selected.parameters_list[j].dimensions);
  657. } else {
  658. temp = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  659. }
  660. ref_object.parameters_list.push(temp);
  661. renderMenu(command, temp, parameters_menu.find('.parameter_'+j), function_obj, 2, expression_element);
  662. }
  663. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  664. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  665. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  666. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  667. context_menu += '<div class="menu">';
  668. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  669. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  670. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  671. context_menu += '</div></div>';
  672. }*/
  673. context_menu += '</div></div>';
  674. context_menu = $(context_menu);
  675. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  676. context_menu.dropdown({
  677. onChange: function(value, text, $selectedItem) {
  678. console.log('S8');
  679. if ($selectedItem.data('clear')) {
  680. console.log('PP7');
  681. dom_object.text('');
  682. ref_object.content = null;
  683. ref_object.row = null;
  684. ref_object.column = null;
  685. delete ref_object.function_called;
  686. delete ref_object.parameters_list;
  687. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  688. }
  689. if ($selectedItem.data('exp')) {
  690. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  691. }
  692. },
  693. selectOnKeydown: false
  694. });
  695. } else {
  696. menu_var_or_value.find('.text').text(' ');
  697. dom_object.find('.menu_var_or_value_dom').remove();
  698. var parameters_menu;
  699. if (function_selected.name) {
  700. parameters_menu = '<div class="parameters_function_called"> '+function_selected.name+' <span> ( </span>';
  701. } else {
  702. parameters_menu = '<div class="parameters_function_called"> <i>'+LocalizedStrings.translateInternalFunction(function_selected.identifier, function_selected.category)+'</i> <span> ( </span>';
  703. }
  704. parameters_menu += '<span> ) </span></div>';
  705. parameters_menu = $(parameters_menu);
  706. dom_object.append(parameters_menu);
  707. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  708. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  709. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  710. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  711. context_menu += '<div class="menu">';
  712. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  713. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  714. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  715. context_menu += '</div></div>';
  716. }*/
  717. context_menu += '</div></div>';
  718. context_menu = $(context_menu);
  719. context_menu.insertAfter( dom_object.find('.parameters_function_called') );
  720. context_menu.dropdown({
  721. onChange: function(value, text, $selectedItem) {
  722. console.log('S9');
  723. if ($selectedItem.data('clear')) {
  724. console.log('PP8');
  725. dom_object.text('');
  726. ref_object.content = null;
  727. ref_object.row = null;
  728. ref_object.column = null;
  729. delete ref_object.function_called;
  730. delete ref_object.parameters_list;
  731. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  732. }
  733. if ($selectedItem.data('exp')) {
  734. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  735. }
  736. },
  737. selectOnKeydown: false
  738. });
  739. }
  740. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  741. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  742. }*/
  743. }
  744. function openInputToVariable (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected, expression_element) {
  745. ref_object.content = variable_selected;
  746. menu_var_or_value.find('.text').text(' ');
  747. dom_object.find('.menu_var_or_value_dom').remove();
  748. var variable_render = '<div class="variable_rendered"> <span class="var_name">'+variable_selected.name+'</span>';
  749. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  750. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  751. }
  752. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  753. variable_render += ' <span>[ </span> <div class="row_container"></div> <span> ]</span> ';
  754. variable_render += ' <span>[ </span> <div class="column_container"></div> <span> ]</span>';
  755. }
  756. variable_render += '</div>';
  757. variable_render = $(variable_render);
  758. dom_object.append(variable_render);
  759. if (variable_selected.dimensions == 1 && ref_object.dimensions != 1) {
  760. ref_object.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  761. renderMenu(command, ref_object.column, variable_render.find('.column_container'), function_obj, 2, expression_element);
  762. }
  763. if (variable_selected.dimensions == 2 && ref_object.dimensions != 2) {
  764. ref_object.row = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  765. renderMenu(command, ref_object.row, variable_render.find('.row_container'), function_obj, 2, expression_element);
  766. ref_object.column = new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true);
  767. renderMenu(command, ref_object.column, variable_render.find('.column_container'), function_obj, 2, expression_element);
  768. }
  769. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  770. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  771. /*if (command.type == Models.COMMAND_TYPES.attribution && !dom_object.hasClass('var_attributed')) {
  772. console.log("dom_object 10: ");
  773. console.log(dom_object);
  774. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  775. context_menu += '<div class="menu">';
  776. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  777. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  778. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  779. context_menu += '</div></div>';
  780. }*/
  781. context_menu += '</div></div>';
  782. context_menu = $(context_menu);
  783. context_menu.insertAfter( dom_object.find('.variable_rendered') );
  784. context_menu.dropdown({
  785. onChange: function(value, text, $selectedItem) {
  786. console.log('S10');
  787. if ($selectedItem.data('clear')) {
  788. console.log('PP9');
  789. dom_object.text('');
  790. ref_object.content = null;
  791. ref_object.row = null;
  792. ref_object.column = null;
  793. delete ref_object.function_called;
  794. delete ref_object.parameters_list;
  795. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  796. }
  797. if ($selectedItem.data('exp')) {
  798. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  799. }
  800. if (command.type == Models.COMMAND_TYPES.repeatNtimes) {
  801. RepeatNTimesManagement.manageClearExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  802. }
  803. },
  804. selectOnKeydown: false
  805. });
  806. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  807. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected);
  808. }*/
  809. }
  810. function openInputToValue (command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element) {
  811. if (ref_object.content == null) {
  812. ref_object.content = "";
  813. }
  814. menu_var_or_value.find('.text').text(' ');
  815. var field = $('<input type="text" size="2" class="width-dynamic-minus" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />');
  816. field.insertBefore(dom_object.find('.menu_var_or_value_dom'));
  817. var rendered = $('<div class="value_rendered"></div>');
  818. rendered.insertBefore(field);
  819. field.focus();
  820. field.val(ref_object.content);
  821. var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
  822. context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
  823. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  824. context_menu += '<div class="item"><i class="dropdown icon"></i>' + LocalizedStrings.getUI('text_change');
  825. context_menu += '<div class="menu">';
  826. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.exp_op_exp+'">EXP OP EXP</div>';
  827. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.op_exp+'">OP EXP</div>';
  828. context_menu += '<div class="item" data-exp="'+Models.EXPRESSION_ELEMENTS.par_exp_par+'">( EXP )</div>';
  829. context_menu += '</div></div>';
  830. }*/
  831. context_menu += '</div></div>';
  832. context_menu = $(context_menu);
  833. dom_object.find('.menu_var_or_value_dom').remove();
  834. if (ref_object.variable_and_value != VAR_OR_VALUE_TYPES.only_value) {
  835. context_menu.insertAfter( field );
  836. }
  837. context_menu.dropdown({
  838. onChange: function(value, text, $selectedItem) {
  839. console.log('S11');
  840. if ($selectedItem.data('clear')) {
  841. console.log('PP10');
  842. dom_object.text('');
  843. dom_object.find('.value_rendered').remove();
  844. dom_object.find('.context_menu_clear').remove();
  845. dom_object.find('.width-dynamic-minus').remove();
  846. ref_object.content = null;
  847. ref_object.row = null;
  848. ref_object.column = null;
  849. delete ref_object.function_called;
  850. delete ref_object.parameters_list;
  851. renderMenu(command, ref_object, dom_object, function_obj, 2, expression_element);
  852. }
  853. if ($selectedItem.data('exp')) {
  854. AttribuitionsManagement.manageExpressionElements(command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element);
  855. }
  856. },
  857. selectOnKeydown: false
  858. });
  859. dom_object.find('.width-dynamic-minus').focusout(function() {
  860. if ($(this).val().trim()) {
  861. ref_object.content = $(this).val().trim();
  862. }
  863. rendered.text(ref_object.content);
  864. $(this).remove();
  865. });
  866. dom_object.find('.width-dynamic-minus').on('keydown', function(e) {
  867. var code = e.keyCode || e.which;
  868. if(code == 13) {
  869. if ($(this).val().trim()) {
  870. ref_object.content = $(this).val().trim();
  871. }
  872. rendered.text(ref_object.content);
  873. $(this).remove();
  874. }
  875. if(code == 27) {
  876. rendered.text(ref_object.content);
  877. $(this).remove();
  878. }
  879. });
  880. if (command.type == Models.COMMAND_TYPES.comment) {
  881. /*rendered.parent().on('click', function(e) {
  882. rendered.parent().off();
  883. console.log("TTT14");
  884. rendered.remove();
  885. rendered.empty();
  886. rendered.remove();
  887. dom_object.empty();
  888. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  889. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  890. });*/
  891. }
  892. rendered.on('click', function(e) {
  893. console.log("TTT2");
  894. rendered.remove();
  895. rendered.empty();
  896. rendered.remove();
  897. dom_object.empty();
  898. dom_object.append('<span class="menu_var_or_value_dom"> </span>');
  899. openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj, expression_element)
  900. });
  901. /*if (command.type == Models.COMMAND_TYPES.attribution) {
  902. AttribuitionsManagement.renderMenuOperations(command, ref_object, dom_object, menu_var_or_value, function_obj);
  903. }*/
  904. }
  905. $.fn.textWidth = function(text, font) {
  906. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  907. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  908. return $.fn.textWidth.fakeEl.width();
  909. };