variable_value_menu.js 46 KB

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