variable_value_menu.js 43 KB

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