variable_value_menu.js 46 KB

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