variable_value_menu.js 44 KB

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