1
0

variables.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. import $ from 'jquery';
  2. import jQuery from 'jquery';
  3. import { Types } from './types';
  4. import * as Models from './ivprog_elements';
  5. import { LocalizedStrings } from './../services/localizedStringsService';
  6. window.jQuery = jQuery;
  7. import '../semantic/semantic.min.js';
  8. var counter_new_variables = 0;
  9. export function addVariable (function_obj, function_container, is_in_click = false) {
  10. var new_var = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_variable') + '_' + counter_new_variables, 1);
  11. if (function_obj.variables_list == null) {
  12. function_obj.variables_list = [];
  13. }
  14. function_obj.variables_list.push(new_var);
  15. counter_new_variables ++;
  16. var newe = renderVariable(function_container, new_var, function_obj);
  17. if (is_in_click) {
  18. newe.css('display', 'none');
  19. newe.fadeIn();
  20. }
  21. }
  22. function updateName (variable_obj, new_name) {
  23. variable_obj.name = new_name;
  24. }
  25. function removeVariable (variable_obj, variable_container) {
  26. var function_associated = variable_container.data('associatedFunction');
  27. var index = function_associated.variables_list.indexOf(variable_obj);
  28. if (index > -1) {
  29. window.insertContext = true;
  30. delete function_associated.variables_list[index];
  31. function_associated.variables_list.splice(index, 1);
  32. }
  33. variable_container.children().off();
  34. variable_container.off();
  35. variable_container.fadeOut();
  36. }
  37. function updateType (variable_obj, new_type, new_dimensions = 0) {
  38. variable_obj.type = new_type;
  39. variable_obj.dimensions = new_dimensions;
  40. if (new_dimensions > 0) {
  41. variable_obj.rows = new_dimensions;
  42. variable_obj.columns = 2;
  43. }
  44. updateInitialValues(variable_obj);
  45. }
  46. function addHandlers (variable_obj, variable_container) {
  47. // Manage variable name:
  48. variable_container.find( ".enable_edit_name_variable" ).on('click', function(e){
  49. enableNameUpdate(variable_obj, variable_container);
  50. });
  51. // Menu to change type:
  52. variable_container.find('.ui.dropdown.variable_type').dropdown({
  53. onChange: function(value, text, $selectedItem) {
  54. if ($selectedItem.data('dimensions')) {
  55. updateType(variable_obj, Types[$selectedItem.data('type')], $selectedItem.data('dimensions'));
  56. } else {
  57. updateType(variable_obj, Types[$selectedItem.data('type')]);
  58. }
  59. renderValues(variable_obj, variable_container);
  60. },
  61. selectOnKeydown: false
  62. });
  63. // Remove variable:
  64. variable_container.find( ".remove_variable" ).on('click', function(e){
  65. removeVariable(variable_obj, variable_container);
  66. });
  67. }
  68. export function renderVariable (function_container, new_var, function_obj) {
  69. var element = '<div class="ui label variable_container pink"><i class="ui icon ellipsis vertical inverted"></i>';
  70. element += '<div class="ui dropdown variable_type">';
  71. if (new_var.dimensions > 0) {
  72. element += '<div class="text">'+ LocalizedStrings.getUI('vector') + ':' + LocalizedStrings.getUI(new_var.type.toLowerCase());
  73. for (var i = 0; i < new_var.dimensions; i ++) {
  74. element += ' [ ] ';
  75. }
  76. element += '</div>';
  77. } else {
  78. element += '<div class="text">' + LocalizedStrings.getUI(new_var.type.toLowerCase()) + '</div>';
  79. }
  80. element += '<div class="menu">';
  81. for (var tm in Types) {
  82. if (tm == Types.VOID.toUpperCase()) {
  83. continue;
  84. }
  85. element += '<div class="item ' + (new_var.type == tm.toLowerCase() ? ' selected ' : '') + '" data-type="'+tm+'" >'+LocalizedStrings.getUI(tm.toLowerCase())+'</div>';
  86. }
  87. for (var tm in Types) {
  88. if (tm == Types.VOID.toUpperCase()) {
  89. continue;
  90. }
  91. element += '<div class="item">'
  92. + '<i class="dropdown icon"></i>'
  93. + LocalizedStrings.getUI('vector')+':'+LocalizedStrings.getUI(tm.toLowerCase())
  94. + '<div class="menu">'
  95. + '<div class="item" data-text="'+ LocalizedStrings.getUI('vector')+':'+LocalizedStrings.getUI(tm.toLowerCase())+' [ ] " data-type="'+tm+'" data-dimensions="1">[ ]</div>'
  96. + '<div class="item" data-text="'+ LocalizedStrings.getUI('vector')+':'+LocalizedStrings.getUI(tm.toLowerCase())+' [ ] [ ] " data-type="'+tm+'" data-dimensions="2">[ ] [ ] </div>'
  97. + '</div>'
  98. + '</div>';
  99. }
  100. element += '</div></div> ';
  101. element += '<div class="editing_name_var"><span class="span_name_variable enable_edit_name_variable">'+new_var.name+'</span> </div>';
  102. element += ' <span class="character_equals"> = </span> <div class="ui div_valor_var">'+new_var.value+'</div>';
  103. element += ' <i class="yellow inverted icon times remove_variable"></i></div>';
  104. element = $(element);
  105. element.data('associatedFunction', function_obj);
  106. function_container.find('.variables_list_div').append(element);
  107. addHandlers(new_var, element);
  108. renderValues(new_var, element);
  109. return element;
  110. }
  111. function updateColumnsAndRowsText (variable_container, variable_var) {
  112. var prev = variable_container.find('.text').text().split('[');
  113. if (prev.length == 2) {
  114. var ff = prev[0] + '[ ' + variable_var.columns + ' ] ';
  115. variable_container.find('.text').empty();
  116. variable_container.find('.text').text(ff);
  117. }
  118. if (prev.length == 3) {
  119. var ff = prev[0] + '[ ' + variable_var.columns + ' ] [ ' + variable_var.rows + ' ] ';
  120. variable_container.find('.text').empty();
  121. variable_container.find('.text').text(ff);
  122. }
  123. }
  124. function renderValues (new_var, variable_container) {
  125. var ret = "";
  126. var j = 0;
  127. if (new_var.dimensions == 0) {
  128. if (new_var.type == Types.REAL) {
  129. ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+new_var.value.toFixed(1)+'</span> </div> ';
  130. } else {
  131. if (new_var.type == Types.BOOLEAN) {
  132. ret += '<div class="created_div_valor_var"><span class="span_value_variable boolean_simple_type">'+LocalizedStrings.getUI(new_var.value)+'</span> </div> ';
  133. } else {
  134. ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+new_var.value+'</span> </div> ';
  135. }
  136. }
  137. } else {
  138. ret += '<table class="tabela_var">';
  139. if (new_var.dimensions == 1) {
  140. ret += '<tr>';
  141. if (new_var.type == Types.REAL) {
  142. for (var k = 0; k < new_var.columns; k++) {
  143. ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+new_var.value[k].toFixed(1)+'</span></td>';
  144. }
  145. } else {
  146. for (var k = 0; k < new_var.columns; k++) {
  147. if (new_var.type == Types.BOOLEAN) {
  148. ret += '<td><span class="span_value_variable boolean_vector_var" data-index="'+k+'">'+LocalizedStrings.getUI(new_var.value[k])+'</span></td>';
  149. } else {
  150. ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+new_var.value[k]+'</span>'+'</td>';
  151. }
  152. }
  153. }
  154. ret += '</tr>';
  155. ret += '</table>';
  156. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_vector_column"></i>'
  157. + ' <i class="ui icon plus square outline add_global_vector_column"></i></div>';
  158. }
  159. if (new_var.dimensions == 2) {
  160. if (new_var.type == Types.REAL) {
  161. for (var l = 0; l < new_var.rows; l++) {
  162. ret += '<tr>';
  163. for (var k = 0; k < new_var.columns; k++) {
  164. ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+new_var.value[l][k].toFixed(1)+'</span>'+'</td>';
  165. }
  166. ret += '</tr>';
  167. }
  168. } else {
  169. for (var l = 0; l < new_var.rows; l++) {
  170. ret += '<tr>';
  171. for (var k = 0; k < new_var.columns; k++) {
  172. if (new_var.type == Types.BOOLEAN) {
  173. ret += '<td><span class="span_value_variable boolean_matrix_var" data-index="'+k+'" data-row="'+l+'">'+LocalizedStrings.getUI(new_var.value[l][k])+'</span></td>';
  174. } else {
  175. ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+new_var.value[l][k]+'</span></td>';
  176. }
  177. }
  178. ret += '</tr>';
  179. }
  180. }
  181. if (new_var.rows == 0) {
  182. ret += '<tr><td></td></tr>';
  183. }
  184. ret += '<tr><td colspan="'+new_var.columns+'" class="tr_manage_lines"><i class="ui icon minus square outline remove_global_matrix_line"></i>'
  185. + ' <i class="ui icon plus square outline add_global_matrix_line"></i></td></tr>';
  186. ret += '</table>';
  187. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_matrix_column"></i>'
  188. + ' <i class="ui icon plus square outline add_global_matrix_column"></i></div>';
  189. }
  190. }
  191. $( variable_container ).find( ".div_valor_var" ).html('');
  192. ret = $(ret);
  193. $(ret).find('.span_value_variable').data('associatedOject', new_var);
  194. $( ret ).find( ".boolean_simple_type" ).on('click', function(e){
  195. alternateBooleanValue(new_var, this.parentNode);
  196. });
  197. $( ret ).find( ".simple_var" ).on('click', function(e){
  198. enableValueUpdate(new_var, this.parentNode);
  199. });
  200. $( ret ).find( ".boolean_vector_var" ).on('click', function(e){
  201. alternateBooleanVectorValue(new_var, $(this).data('index'), this.parentNode);
  202. });
  203. $( ret ).find( ".vector_var" ).on('click', function(e){
  204. enableVectorValueUpdate(new_var, $(this).data('index'), this.parentNode);
  205. });
  206. $( ret ).find( ".remove_global_vector_column" ).on('click', function(e){
  207. removeColumnVector(new_var);
  208. $( variable_container ).find( ".div_valor_var" ).html('');
  209. renderValues(new_var, variable_container);
  210. });
  211. $( ret ).find( ".add_global_vector_column" ).on('click', function(e){
  212. addColumnVector(new_var);
  213. $( variable_container ).find( ".div_valor_var" ).html('');
  214. renderValues(new_var, variable_container);
  215. });
  216. $( ret ).find( ".remove_global_matrix_column" ).on('click', function(e){
  217. removeColumnMatrix(new_var);
  218. $( variable_container ).find( ".div_valor_var" ).html('');
  219. renderValues(new_var, variable_container);
  220. });
  221. $( ret ).find( ".add_global_matrix_column" ).on('click', function(e){
  222. addColumnMatrix(new_var);
  223. $( variable_container ).find( ".div_valor_var" ).html('');
  224. renderValues(new_var, variable_container);
  225. });
  226. $( ret ).find( ".remove_global_matrix_line" ).on('click', function(e){
  227. removeLineMatrix(new_var);
  228. $( variable_container ).find( ".div_valor_var" ).html('');
  229. renderValues(new_var, variable_container);
  230. });
  231. $( ret ).find( ".add_global_matrix_line" ).on('click', function(e){
  232. addLineMatrix(new_var);
  233. $( variable_container ).find( ".div_valor_var" ).html('');
  234. renderValues(new_var, variable_container);
  235. });
  236. $( ret ).find( ".boolean_matrix_var" ).on('click', function(e){
  237. alternateBooleanMatrixValue(new_var, $(this).data('row'), $(this).data('index'), this.parentNode);
  238. });
  239. $( ret ).find( ".matrix_var" ).on('click', function(e){
  240. enableMatrixValueUpdate(new_var, $(this).data('row'), $(this).data('index'), this.parentNode);
  241. });
  242. $( variable_container ).find( ".div_valor_var" ).append(ret);
  243. updateColumnsAndRowsText(variable_container, new_var);
  244. }
  245. function alternateBooleanMatrixValue (var_obj, row, index, value_container) {
  246. var_obj.value[row][index] = !var_obj.value[row][index];
  247. $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(var_obj.value[row][index]));
  248. }
  249. function addLineMatrix (var_obj) {
  250. var_obj.rows ++;
  251. if (var_obj.type == Types.INTEGER) {
  252. var n_l = [];
  253. for (var i = 0; i < var_obj.columns; i++) {
  254. n_l.push(1);
  255. }
  256. var_obj.value.push(n_l);
  257. }
  258. if (var_obj.type == Types.REAL) {
  259. var n_l = [];
  260. for (i = 0; i < var_obj.columns; i++) {
  261. n_l.push(1.0);
  262. }
  263. var_obj.value.push(n_l);
  264. }
  265. if (var_obj.type == Types.TEXT) {
  266. var n_l = [];
  267. for (i = 0; i < var_obj.columns; i++) {
  268. n_l.push(LocalizedStrings.getUI('text_start'));
  269. }
  270. var_obj.value.push(n_l);
  271. }
  272. if (var_obj.type == Types.BOOLEAN) {
  273. var n_l = [];
  274. for (i = 0; i < var_obj.columns; i++) {
  275. n_l.push(true);
  276. }
  277. var_obj.value.push(n_l);
  278. }
  279. }
  280. function removeLineMatrix (var_obj) {
  281. if (var_obj.rows == 0) {
  282. return;
  283. }
  284. var_obj.rows --;
  285. var_obj.value.splice(var_obj.value.length - 1, 1);
  286. }
  287. function addColumnMatrix (var_obj) {
  288. var_obj.columns ++;
  289. if (var_obj.type == Types.INTEGER) {
  290. for (var i = 0; i < var_obj.rows; i++) {
  291. var_obj.value[i].push(1);
  292. }
  293. }
  294. if (var_obj.type == Types.REAL) {
  295. for (var i = 0; i < var_obj.rows; i++) {
  296. var_obj.value[i].push(1.0);
  297. }
  298. }
  299. if (var_obj.type == Types.TEXT) {
  300. for (var i = 0; i < var_obj.rows; i++) {
  301. var_obj.value[i].push(LocalizedStrings.getUI('text_start'));
  302. }
  303. }
  304. if (var_obj.type == Types.BOOLEAN) {
  305. for (var i = 0; i < var_obj.rows; i++) {
  306. var_obj.value[i].push(true);
  307. }
  308. }
  309. }
  310. function removeColumnMatrix (var_obj) {
  311. if (var_obj.columns == 0) {
  312. return;
  313. }
  314. var_obj.columns --;
  315. for (var i = 0; i < var_obj.rows; i++) {
  316. var_obj.value[i].splice(var_obj.value[i].length - 1, 1);
  317. }
  318. }
  319. function addColumnVector (var_obj) {
  320. var_obj.columns ++;
  321. if (var_obj.type == Types.INTEGER) {
  322. var_obj.value.push(1);
  323. }
  324. if (var_obj.type == Types.REAL) {
  325. var_obj.value.push(1.0);
  326. }
  327. if (var_obj.type == Types.TEXT) {
  328. var_obj.value.push(LocalizedStrings.getUI('text_start'));
  329. }
  330. if (var_obj.type == Types.BOOLEAN) {
  331. var_obj.value.push(true);
  332. }
  333. }
  334. function removeColumnVector (var_obj) {
  335. if (var_obj.columns == 0) {
  336. return;
  337. }
  338. var_obj.columns --;
  339. var_obj.value.splice(var_obj.value.length - 1, 1);
  340. }
  341. function alternateBooleanValue (var_obj, value_container) {
  342. var_obj.value = !var_obj.value;
  343. $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(var_obj.value));
  344. }
  345. function alternateBooleanVectorValue (var_obj, index, value_container) {
  346. var_obj.value[index] = !var_obj.value[index];
  347. $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(var_obj.value[index]));
  348. }
  349. function updateInitialValues (variable_obj) {
  350. if (variable_obj.type == Types.INTEGER) {
  351. if (variable_obj.dimensions == 0) {
  352. variable_obj.value = 1;
  353. }
  354. if (variable_obj.dimensions == 1) {
  355. variable_obj.value = [1, 1];
  356. }
  357. if (variable_obj.dimensions == 2) {
  358. variable_obj.value = [[1, 1], [1, 1]];
  359. }
  360. }
  361. if (variable_obj.type == Types.REAL) {
  362. if (variable_obj.dimensions == 0) {
  363. variable_obj.value = 1.0;
  364. }
  365. if (variable_obj.dimensions == 1) {
  366. variable_obj.value = [1.0, 1.0];
  367. }
  368. if (variable_obj.dimensions == 2) {
  369. variable_obj.value = [[1.0, 1.0], [1.0, 1.0]];
  370. }
  371. }
  372. if (variable_obj.type == Types.TEXT) {
  373. if (variable_obj.dimensions == 0) {
  374. variable_obj.value = LocalizedStrings.getUI('text_start');
  375. }
  376. if (variable_obj.dimensions == 1) {
  377. variable_obj.value = [LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')];
  378. }
  379. if (variable_obj.dimensions == 2) {
  380. variable_obj.value = [[LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')],
  381. [LocalizedStrings.getUI('text_start'), LocalizedStrings.getUI('text_start')]];
  382. }
  383. }
  384. if (variable_obj.type == Types.BOOLEAN) {
  385. if (variable_obj.dimensions == 0) {
  386. variable_obj.value = true;
  387. }
  388. if (variable_obj.dimensions == 1) {
  389. variable_obj.value = [true, true];
  390. }
  391. if (variable_obj.dimensions == 2) {
  392. variable_obj.value = [[true, true], [true, true]];
  393. }
  394. }
  395. }
  396. var opened_name_value_vector_global_ = false;
  397. var opened_input_value_vector_global_ = null;
  398. function enableVectorValueUpdate (var_obj, index, parent_node) {
  399. if (opened_name_value_vector_global_) {
  400. opened_input_value_vector_global_.focus();
  401. return;
  402. }
  403. parent_node = $(parent_node);
  404. opened_name_value_vector_global_ = true;
  405. parent_node.find('.span_value_variable').text('');
  406. var input_field;
  407. if (var_obj.type == Types.REAL) {
  408. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  409. + var_obj.value[index].toFixed(1) + "' />" );
  410. input_field.insertBefore(parent_node.find('.span_value_variable'));
  411. } else {
  412. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  413. + var_obj.value[index] + "' />" );
  414. input_field.insertBefore(parent_node.find('.span_value_variable'));
  415. }
  416. input_field.on('input', function() {
  417. var inputWidth = input_field.textWidth()+10;
  418. opened_input_value_vector_global_ = input_field;
  419. input_field.focus();
  420. var tmpStr = input_field.val();
  421. input_field.val('');
  422. input_field.val(tmpStr);
  423. input_field.css({
  424. width: inputWidth
  425. })
  426. }).trigger('input');
  427. input_field.focusout(function() {
  428. /// update array:
  429. if (input_field.val().trim()) {
  430. if (var_obj.type == Types.REAL) {
  431. var_obj.value[index] = parseFloat(input_field.val().trim());
  432. parent_node.find('.span_value_variable').text(var_obj.value[index].toFixed(1));
  433. } else {
  434. if (var_obj.type == Types.INTEGER) {
  435. var_obj.value[index] = parseInt(input_field.val().trim());
  436. } else {
  437. var_obj.value[index] = input_field.val().trim();
  438. }
  439. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  440. }
  441. } else {
  442. if (var_obj.type == Types.REAL) {
  443. parent_node.find('.span_value_variable').text(var_obj.value[index].toFixed(1));
  444. } else {
  445. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  446. }
  447. }
  448. if (var_obj.type == Types.TEXT) {
  449. var_obj.value[index] = input_field.val();
  450. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  451. }
  452. input_field.off();
  453. input_field.remove();
  454. /// update elements:
  455. opened_name_value_vector_global_ = false;
  456. opened_input_value_vector_global_ = false;
  457. });
  458. input_field.on('keydown', function(e) {
  459. var code = e.keyCode || e.which;
  460. if(code == 13) {
  461. if (input_field.val().trim()) {
  462. if (var_obj.type == Types.REAL) {
  463. var_obj.value[index] = parseFloat(input_field.val().trim());
  464. parent_node.find('.span_value_variable').text(var_obj.value[index].toFixed(1));
  465. } else {
  466. if (var_obj.type == Types.INTEGER) {
  467. var_obj.value[index] = parseInt(input_field.val().trim());
  468. } else {
  469. var_obj.value[index] = input_field.val().trim();
  470. }
  471. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  472. }
  473. } else {
  474. if (var_obj.type == Types.REAL) {
  475. parent_node.find('.span_value_variable').text(var_obj.value[index].toFixed(1));
  476. } else {
  477. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  478. }
  479. }
  480. if (var_obj.type == Types.TEXT) {
  481. var_obj.value[index] = input_field.val();
  482. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  483. }
  484. input_field.off();
  485. input_field.remove();
  486. /// update elements:
  487. opened_name_value_vector_global_ = false;
  488. opened_input_value_vector_global_ = false;
  489. }
  490. if(code == 27) {
  491. if (var_obj.type == Types.REAL) {
  492. parent_node.find('.span_value_variable').text(var_obj.value[index].toFixed(1));
  493. } else {
  494. parent_node.find('.span_value_variable').text(var_obj.value[index]);
  495. }
  496. input_field.off();
  497. input_field.remove();
  498. /// update elements:
  499. opened_name_value_vector_global_ = false;
  500. opened_input_value_vector_global_ = false;
  501. }
  502. });
  503. input_field.select();
  504. }
  505. var opened_name_value_global_var = false;
  506. var opened_input_value_global_ar = null;
  507. function enableValueUpdate (var_obj, parent_node) {
  508. if (opened_name_value_global_var) {
  509. opened_input_value_global_ar.focus();
  510. return;
  511. }
  512. parent_node = $(parent_node);
  513. opened_name_value_global_var = true;
  514. var input_field;
  515. parent_node.find('.span_value_variable').text('');
  516. if (var_obj.type == Types.REAL) {
  517. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  518. + var_obj.value.toFixed(1) + "' />" );
  519. input_field.insertBefore(parent_node.find('.span_value_variable'));
  520. } else {
  521. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  522. + var_obj.value + "' />" );
  523. input_field.insertBefore(parent_node.find('.span_value_variable'));
  524. }
  525. input_field.on('input', function() {
  526. var inputWidth = input_field.textWidth()+10;
  527. opened_input_value_global_ar = input_field;
  528. input_field.focus();
  529. var tmpStr = input_field.val();
  530. input_field.val('');
  531. input_field.val(tmpStr);
  532. input_field.css({
  533. width: inputWidth
  534. })
  535. }).trigger('input');
  536. input_field.focusout(function() {
  537. /// update array:
  538. if (input_field.val().trim()) {
  539. if (var_obj.type == Types.REAL) {
  540. var_obj.value = parseFloat(input_field.val().trim());
  541. parent_node.find('.span_value_variable').text(var_obj.value.toFixed(1));
  542. } else{
  543. if (var_obj.type == Types.INTEGER) {
  544. var_obj.value = parseInt(input_field.val().trim());
  545. } else {
  546. var_obj.value = input_field.val().trim();
  547. }
  548. parent_node.find('.span_value_variable').text(var_obj.value);
  549. }
  550. } else {
  551. if (var_obj.type == Types.REAL) {
  552. parent_node.find('.span_value_variable').text(var_obj.value.toFixed(1));
  553. } else {
  554. parent_node.find('.span_value_variable').text(var_obj.value);
  555. }
  556. }
  557. if (var_obj.type == Types.TEXT) {
  558. var_obj.value = input_field.val();
  559. parent_node.find('.span_value_variable').text(var_obj.value);
  560. }
  561. input_field.off();
  562. input_field.remove();
  563. /// update elements:
  564. opened_name_value_global_var = false;
  565. opened_input_value_global_ar = false;
  566. });
  567. input_field.on('keydown', function(e) {
  568. var code = e.keyCode || e.which;
  569. if(code == 13) {
  570. if (input_field.val().trim()) {
  571. if (var_obj.type == Types.REAL) {
  572. var_obj.value = parseFloat(input_field.val().trim());
  573. parent_node.find('.span_value_variable').text(var_obj.value.toFixed(1));
  574. } else{
  575. if (var_obj.type == Types.INTEGER) {
  576. var_obj.value = parseInt(input_field.val().trim());
  577. } else {
  578. var_obj.value = input_field.val().trim();
  579. }
  580. parent_node.find('.span_value_variable').text(var_obj.value);
  581. }
  582. } else {
  583. if (var_obj.type == Types.REAL) {
  584. parent_node.find('.span_value_variable').text(var_obj.value.toFixed(1));
  585. } else {
  586. parent_node.find('.span_value_variable').text(var_obj.value);
  587. }
  588. }
  589. if (var_obj.type == Types.TEXT) {
  590. var_obj.value = input_field.val();
  591. parent_node.find('.span_value_variable').text(var_obj.value);
  592. }
  593. input_field.off();
  594. input_field.remove();
  595. /// update elements:
  596. opened_name_value_global_var = false;
  597. opened_input_value_global_ar = false;
  598. }
  599. if(code == 27) {
  600. if (var_obj.type == Types.REAL) {
  601. parent_node.find('.span_value_variable').text(var_obj.value.toFixed(1));
  602. } else{
  603. parent_node.find('.span_value_variable').text(var_obj.value);
  604. }
  605. input_field.off();
  606. input_field.remove();
  607. /// update elements:
  608. opened_name_value_global_var = false;
  609. opened_input_value_global_ar = false;
  610. }
  611. });
  612. input_field.select();
  613. }
  614. var opened_name_global = false;
  615. var opened_input_global = null;
  616. function enableNameUpdate (variable_obj, variable_container) {
  617. if (opened_name_global) {
  618. opened_input_global.focus();
  619. return;
  620. }
  621. opened_name_global = true;
  622. variable_container.find('.span_name_variable').text('');
  623. var input_name;
  624. input_name = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+variable_obj.name+"' />" );
  625. input_name.insertBefore(variable_container.find('.span_name_variable'));
  626. input_name.on('input', function() {
  627. var inputWidth = input_name.textWidth()+10;
  628. opened_input_global = input_name;
  629. input_name.focus();
  630. var tmpStr = input_name.val();
  631. input_name.val('');
  632. input_name.val(tmpStr);
  633. input_name.css({
  634. width: inputWidth
  635. })
  636. }).trigger('input');
  637. input_name.focusout(function() {
  638. /// update array:
  639. if (input_name.val().trim().length > 0) {
  640. updateName(variable_obj, input_name.val().trim());
  641. variable_container.find('.span_name_variable').text(variable_obj.name);
  642. } else {
  643. variable_container.find('.span_name_variable').text(variable_obj.name);
  644. }
  645. input_name.off();
  646. input_name.remove();
  647. /// update elements:
  648. opened_name_global = false;
  649. opened_input_global = false;
  650. });
  651. input_name.on('keydown', function(e) {
  652. var code = e.keyCode || e.which;
  653. if(code == 13) {
  654. if (input_name.val().trim().length > 0) {
  655. updateName(variable_obj, input_name.val().trim());
  656. variable_container.find('.span_name_variable').text(variable_obj.name);
  657. } else {
  658. variable_container.find('.span_name_variable').text(variable_obj.name);
  659. }
  660. input_name.off();
  661. input_name.remove();
  662. /// update elements:
  663. opened_name_global = false;
  664. opened_input_global = false;
  665. }
  666. if(code == 27) {
  667. variable_container.find('.span_name_variable').text(variable_obj.name);
  668. input_name.off();
  669. input_name.remove();
  670. /// update elements:
  671. opened_name_global = false;
  672. opened_input_global = false;
  673. }
  674. });
  675. input_name.select();
  676. }
  677. var opened_name_value_matrix_global_v = false;
  678. var opened_input_value_matrix_global_v = null;
  679. function enableMatrixValueUpdate (var_obj, row, index, parent_node) {
  680. if (opened_name_value_matrix_global_v) {
  681. opened_input_value_matrix_global_v.focus();
  682. return;
  683. }
  684. parent_node = $(parent_node);
  685. opened_name_value_matrix_global_v = true;
  686. parent_node.find('.span_value_variable').text('');
  687. var input_field;
  688. if (var_obj.type == Types.REAL) {
  689. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  690. + var_obj.value[row][index].toFixed(1) + "' />" );
  691. input_field.insertBefore(parent_node.find('.span_value_variable'));
  692. } else {
  693. input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  694. + var_obj.value[row][index] + "' />" );
  695. input_field.insertBefore(parent_node.find('.span_value_variable'));
  696. }
  697. input_field.on('input', function() {
  698. var inputWidth = input_field.textWidth()+10;
  699. opened_input_value_matrix_global_v = input_field;
  700. input_field.focus();
  701. var tmpStr = input_field.val();
  702. input_field.val('');
  703. input_field.val(tmpStr);
  704. input_field.css({
  705. width: inputWidth
  706. })
  707. }).trigger('input');
  708. input_field.focusout(function() {
  709. /// update array:
  710. if (input_field.val().trim()) {
  711. if (var_obj.type == Types.REAL) {
  712. var_obj.value[row][index] = parseFloat(input_field.val().trim());
  713. parent_node.find('.span_value_variable').text(var_obj.value[row][index].toFixed(1));
  714. } else {
  715. if (var_obj.type == Types.INTEGER) {
  716. var_obj.value[row][index] = parseInt(input_field.val().trim());
  717. } else {
  718. var_obj.value[row][index] = input_field.val().trim();
  719. }
  720. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  721. }
  722. } else {
  723. if (var_obj.type == Types.REAL) {
  724. parent_node.find('.span_value_variable').text(var_obj.value[row][index].toFixed(1));
  725. } else {
  726. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  727. }
  728. }
  729. if (var_obj.type == Types.TEXT) {
  730. var_obj.value[row][index] = input_field.val();
  731. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  732. }
  733. input_field.off();
  734. input_field.remove();
  735. /// update elements:
  736. opened_name_value_matrix_global_v = false;
  737. opened_input_value_matrix_global_v = false;
  738. });
  739. input_field.on('keydown', function(e) {
  740. var code = e.keyCode || e.which;
  741. if(code == 13) {
  742. if (input_field.val().trim()) {
  743. if (var_obj.type == Types.REAL) {
  744. var_obj.value[row][index] = parseFloat(input_field.val().trim());
  745. parent_node.find('.span_value_variable').text(var_obj.value[row][index].toFixed(1));
  746. } else {
  747. if (var_obj.type == Types.INTEGER) {
  748. var_obj.value[row][index] = parseInt(input_field.val().trim());
  749. } else {
  750. var_obj.value[row][index] = input_field.val().trim();
  751. }
  752. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  753. }
  754. } else {
  755. if (var_obj.type == Types.REAL) {
  756. parent_node.find('.span_value_variable').text(var_obj.value[row][index].toFixed(1));
  757. } else {
  758. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  759. }
  760. }
  761. if (var_obj.type == Types.TEXT) {
  762. var_obj.value[row][index] = input_field.val();
  763. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  764. }
  765. input_field.off();
  766. input_field.remove();
  767. /// update elements:
  768. opened_name_value_matrix_global_v = false;
  769. opened_input_value_matrix_global_v = false;
  770. }
  771. if(code == 27) {
  772. if (var_obj.type == Types.REAL) {
  773. parent_node.find('.span_value_variable').text(var_obj.value[row][index].toFixed(1));
  774. } else {
  775. parent_node.find('.span_value_variable').text(var_obj.value[row][index]);
  776. }
  777. input_field.off();
  778. input_field.remove();
  779. /// update elements:
  780. opened_name_value_matrix_global_v = false;
  781. opened_input_value_matrix_global_v = false;
  782. }
  783. });
  784. input_field.select();
  785. }