ivprog-visual-functions-1.0.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. var counter_new_functions = 0;
  2. var counter_new_parameters = 0;
  3. var counter_new_variables = 0;
  4. function addFunctionHandler() {
  5. new_function = new Funcao(i18n("new_function") + "_" + counter_new_functions);
  6. adicionarFuncao(new_function);
  7. counter_new_functions ++;
  8. renderAlgorithm();
  9. }
  10. function updateSequenceFunctionHandler(index_from, index_to) {
  11. programa.funcoes.splice(index_to, 0, programa.funcoes.splice(index_from, 1)[0]);
  12. renderAlgorithm();
  13. }
  14. function removeFunctionHandler(div_function, sequence) {
  15. programa.funcoes.splice(sequence, 1);
  16. $(div_function).slideUp(400, function(){
  17. renderAlgorithm();
  18. });
  19. }
  20. function minimizeFunctionHandler(div_function, sequence) {
  21. $(div_function).find(".function_area").toggle();
  22. programa.funcoes[sequence].esta_oculta = !programa.funcoes[sequence].esta_oculta;
  23. }
  24. function renderAlgorithm() {
  25. $('.all_functions').empty();
  26. for (i = 0; i < programa.funcoes.length; i++) {
  27. appendFunction(programa.funcoes[i], i);
  28. }
  29. $('.data_types_dropdown').dropdown();
  30. $('.parameter_data_types_dropdown').dropdown();
  31. addHandlers();
  32. }
  33. function addHandlers() {
  34. $('.ui.dropdown.function_return')
  35. .dropdown({
  36. onChange: function(value, text, $selectedItem) {
  37. classList = $selectedItem.attr('class').split(/\s+/);
  38. $.each(classList, function(index, item) {
  39. if (item.indexOf("seq_") > -1) {
  40. seq = item.split("seq_")[1];
  41. for (tm in tiposDados) {
  42. if ($selectedItem.hasClass(tm)) {
  43. programa.funcoes[seq].tipo_retorno = tm;
  44. }
  45. }
  46. updateFunctionReturn(seq, value);
  47. }
  48. });
  49. }
  50. })
  51. ;
  52. $('.ui.dropdown.parameter_type').dropdown({
  53. onChange: function(value, text, $selectedItem) {
  54. classList = $selectedItem.attr('class').split(/\s+/);
  55. var fun;
  56. var seq;
  57. $.each(classList, function(index, item) {
  58. if (item.indexOf("fun_") > -1) {
  59. fun = item.split("fun_")[1];
  60. }
  61. if (item.indexOf("seq_") > -1) {
  62. seq = item.split("seq_")[1];
  63. }
  64. });
  65. var dim = 0;
  66. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  67. dim = 1;
  68. }
  69. for (tm in tiposDados) {
  70. if ($selectedItem.hasClass(tm)) {
  71. updateParameterType(fun, seq, tm, dim);
  72. break;
  73. }
  74. }
  75. }
  76. });
  77. $('.ui.dropdown.variable_type').dropdown({
  78. onChange: function(value, text, $selectedItem) {
  79. classList = $selectedItem.attr('class').split(/\s+/);
  80. var fun;
  81. var seq;
  82. $.each(classList, function(index, item) {
  83. if (item.indexOf("fun_") > -1) {
  84. fun = item.split("fun_")[1];
  85. }
  86. if (item.indexOf("seq_") > -1) {
  87. seq = item.split("seq_")[1];
  88. }
  89. });
  90. var dim = 0;
  91. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  92. dim = value.split('[').length - 1;
  93. }
  94. for (tm in tiposDados) {
  95. if ($selectedItem.hasClass(tm)) {
  96. updateVariableType(fun, seq, tm, dim);
  97. break;
  98. }
  99. }
  100. }
  101. });
  102. }
  103. function updateVariableType(wich_function, wich_variable, new_value, new_dimensions) {
  104. programa.funcoes[wich_function].variaveis[wich_variable].tipo = new_value;
  105. programa.funcoes[wich_function].variaveis[wich_variable].dimensoes = new_dimensions;
  106. if (new_dimensions > 0) {
  107. programa.funcoes[wich_function].variaveis[wich_variable].linhas = new_dimensions;
  108. programa.funcoes[wich_function].variaveis[wich_variable].colunas = 2;
  109. }
  110. if (new_value == tiposDados.integer) {
  111. if (new_dimensions == 0) {
  112. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1;
  113. }
  114. if (new_dimensions == 1) {
  115. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1, 1];
  116. }
  117. if (new_dimensions == 2) {
  118. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1, 1], [1, 1]];
  119. }
  120. }
  121. if (new_value == tiposDados.real) {
  122. if (new_dimensions == 0) {
  123. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1.0;
  124. }
  125. if (new_dimensions == 1) {
  126. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1.0, 1.0];
  127. }
  128. if (new_dimensions == 2) {
  129. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  130. }
  131. }
  132. if (new_value == tiposDados.text) {
  133. if (new_dimensions == 0) {
  134. programa.funcoes[wich_function].variaveis[wich_variable].valor = i18n(tiposDados.text);
  135. }
  136. if (new_dimensions == 1) {
  137. programa.funcoes[wich_function].variaveis[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  138. }
  139. if (new_dimensions == 2) {
  140. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  141. }
  142. }
  143. if (new_value == tiposDados.boolean) {
  144. if (new_dimensions == 0) {
  145. programa.funcoes[wich_function].variaveis[wich_variable].valor = true;
  146. }
  147. if (new_dimensions == 1) {
  148. programa.funcoes[wich_function].variaveis[wich_variable].valor = [true, true];
  149. }
  150. if (new_dimensions == 2) {
  151. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[true, true], [true, true]];
  152. }
  153. }
  154. renderAlgorithm();
  155. }
  156. function addColumnVector(which_function, which_variable) {
  157. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  158. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  159. programa.funcoes[which_function].variaveis[which_variable].valor.push(1);
  160. }
  161. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  162. programa.funcoes[which_function].variaveis[which_variable].valor.push(1.0);
  163. }
  164. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  165. programa.funcoes[which_function].variaveis[which_variable].valor.push(i18n(tiposDados.text));
  166. }
  167. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  168. programa.funcoes[which_function].variaveis[which_variable].valor.push(true);
  169. }
  170. renderAlgorithm();
  171. }
  172. function addColumnMatrix(which_function, which_variable) {
  173. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  174. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  175. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  176. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1);
  177. }
  178. }
  179. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  180. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  181. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1.0);
  182. }
  183. }
  184. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  185. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  186. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(i18n(tiposDados.text));
  187. }
  188. }
  189. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  190. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  191. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(true);
  192. }
  193. }
  194. renderAlgorithm();
  195. }
  196. function addLineMatrix(which_function, which_variable) {
  197. programa.funcoes[which_function].variaveis[which_variable].linhas ++;
  198. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  199. var n_l = [];
  200. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  201. n_l.push(1);
  202. }
  203. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  204. }
  205. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  206. var n_l = [];
  207. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  208. n_l.push(1.0);
  209. }
  210. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  211. }
  212. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  213. var n_l = [];
  214. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  215. n_l.push(i18n(tiposDados.text));
  216. }
  217. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  218. }
  219. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  220. var n_l = [];
  221. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  222. n_l.push(true);
  223. }
  224. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  225. }
  226. renderAlgorithm();
  227. }
  228. function removeColumnVector(which_function, which_variable) {
  229. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  230. return;
  231. }
  232. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  233. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  234. renderAlgorithm();
  235. }
  236. function removeColumnMatrix(which_function, which_variable) {
  237. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  238. return;
  239. }
  240. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  241. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  242. programa.funcoes[which_function].variaveis[which_variable].valor[i].splice(programa.funcoes[which_function].variaveis[which_variable].valor[i].length - 1, 1);
  243. }
  244. renderAlgorithm();
  245. }
  246. function removeLineMatrix(which_function, which_variable) {
  247. if (programa.funcoes[which_function].variaveis[which_variable].linhas == 0) {
  248. return;
  249. }
  250. programa.funcoes[which_function].variaveis[which_variable].linhas --;
  251. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  252. renderAlgorithm();
  253. }
  254. function addVariable(sequence) {//tipo, nome, valor
  255. var v = new Variavel(tiposDados.integer, i18n('new_variable') + '_' + counter_new_variables, 1);
  256. adicionarVariavel(sequence, v);
  257. counter_new_variables ++;
  258. renderAlgorithm();
  259. }
  260. function deleteVariable(which_function, which_variable) {
  261. programa.funcoes[which_function].variaveis.splice(which_variable, 1);
  262. renderAlgorithm();
  263. }
  264. function addParameter(sequence) {
  265. if (programa.funcoes[sequence].lista_parametros == null) {
  266. programa.funcoes[sequence].lista_parametros = new Array();
  267. }
  268. programa.funcoes[sequence].lista_parametros.push(new Variavel(tiposDados.integer, i18n("new_parameter") + "_" + counter_new_parameters));
  269. counter_new_parameters ++;
  270. renderAlgorithm();
  271. }
  272. function updateFunctionReturn(sequence, new_value) {
  273. if (new_value.indexOf(i18n(tiposDados.vector)) > -1) {
  274. programa.funcoes[sequence].dimensoes_retorno = 1;
  275. } else {
  276. programa.funcoes[sequence].dimensoes_retorno = 0;
  277. }
  278. }
  279. function updateParameterType(wich_function, wich_parameter, new_value, new_dimensions) {
  280. programa.funcoes[wich_function].lista_parametros[wich_parameter].tipo = new_value;
  281. programa.funcoes[wich_function].lista_parametros[wich_parameter].dimensoes = new_dimensions;
  282. }
  283. var opened_name_function = false;
  284. var opened_input = null;
  285. var sequence_name_opened;
  286. function enableNameFunctionUpdate(div_el, sequence) {
  287. if (opened_name_function) {
  288. $(opened_input).focus();
  289. return;
  290. }
  291. opened_name_function = true;
  292. sequence_name_opened = sequence;
  293. $(div_el).find('.span_name_function').text('');
  294. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+programa.funcoes[sequence].nome+"' />" ).insertBefore($(div_el).find('.span_name_function'));
  295. $('.width-dynamic').on('input', function() {
  296. var inputWidth = $(this).textWidth()+10;
  297. opened_input = this;
  298. $(this).focus();
  299. var tmpStr = $(this).val();
  300. $(this).val('');
  301. $(this).val(tmpStr);
  302. $(this).css({
  303. width: inputWidth
  304. })
  305. }).trigger('input');
  306. $('.width-dynamic').focusout(function() {
  307. /// update array:
  308. if ($(this).val().trim()) {
  309. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  310. }
  311. $(this).remove();
  312. /// update elements:
  313. opened_name_function = false;
  314. opened_input = false;
  315. renderAlgorithm();
  316. });
  317. $('.width-dynamic').on('keydown', function(e) {
  318. var code = e.keyCode || e.which;
  319. if(code == 13) {
  320. if ($(this).val().trim()) {
  321. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  322. }
  323. $(this).remove();
  324. /// update elements:
  325. opened_name_function = false;
  326. opened_input = false;
  327. renderAlgorithm();
  328. }
  329. if(code == 27) {
  330. $(div_el).find('.span_name_function').text(programa.funcoes[sequence_name_opened].nome);
  331. $(this).remove();
  332. /// update elements:
  333. opened_name_function = false;
  334. opened_input = false;
  335. }
  336. });
  337. }
  338. function alternateBooleanVarVectorValue(parent_node, which_function, which_var, column_index) {
  339. programa.funcoes[which_function].variaveis[which_var].valor[column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[column_index];
  340. renderAlgorithm();
  341. }
  342. function alternateBooleanVarMatrixValue(parent_node, which_function, which_var, row_index, column_index) {
  343. programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index];
  344. renderAlgorithm();
  345. }
  346. function alternateBooleanVarValue(parent_node, which_function, which_var) {
  347. programa.funcoes[which_function].variaveis[which_var].valor = !programa.funcoes[which_function].variaveis[which_var].valor;
  348. renderAlgorithm();
  349. }
  350. var opened_name_value_vector_variable = false;
  351. var opened_input_value_vector_variable = null;
  352. var sequence_name_opened_value_vector_variable;
  353. var sequence_function_opened_value_vector_variable;
  354. function enableVarVectorValueUpdate(parent_node, which_function, which_parameter, column_index) {
  355. if (opened_name_value_vector_variable) {
  356. $(opened_input_value_vector_variable).focus();
  357. return;
  358. }
  359. opened_name_value_vector_variable = true;
  360. sequence_name_opened_value_vector_variable = which_parameter;
  361. sequence_function_opened_value_vector_variable = which_function;
  362. $(parent_node).find('.span_value_variable').text('');
  363. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  364. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  365. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  366. } else {
  367. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  368. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  369. }
  370. $('.width-dynamic').on('input', function() {
  371. var inputWidth = $(this).textWidth()+10;
  372. opened_input_value_vector_variable = this;
  373. $(this).focus();
  374. var tmpStr = $(this).val();
  375. $(this).val('');
  376. $(this).val(tmpStr);
  377. $(this).css({
  378. width: inputWidth
  379. })
  380. }).trigger('input');
  381. $('.width-dynamic').focusout(function() {
  382. /// update array:
  383. if ($(this).val().trim()) {
  384. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  385. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  386. } else {
  387. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  388. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  389. } else {
  390. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  391. }
  392. }
  393. }
  394. $(this).remove();
  395. /// update elements:
  396. opened_name_value_vector_variable = false;
  397. opened_input_value_vector_variable = false;
  398. renderAlgorithm();
  399. });
  400. $('.width-dynamic').on('keydown', function(e) {
  401. var code = e.keyCode || e.which;
  402. if(code == 13) {
  403. if ($(this).val().trim()) {
  404. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  405. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  406. } else {
  407. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  408. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  409. } else {
  410. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  411. }
  412. }
  413. }
  414. $(this).remove();
  415. /// update elements:
  416. opened_name_value_vector_variable = false;
  417. opened_input_value_vector_variable = false;
  418. renderAlgorithm();
  419. }
  420. if(code == 27) {
  421. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  422. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1));
  423. } else {
  424. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index]);
  425. }
  426. $(this).remove();
  427. /// update elements:
  428. opened_name_value_vector_variable = false;
  429. opened_input_value_vector_variable = false;
  430. }
  431. });
  432. }
  433. var opened_name_value_matrix_variable = false;
  434. var opened_input_value_matrix_variable = null;
  435. var sequence_name_opened_value_matrix_variable;
  436. var sequence_function_opened_value_matrix_variable;
  437. function enableVarMatrixValueUpdate(parent_node, which_function, which_parameter, row_index, column_index) {
  438. if (opened_name_value_matrix_variable) {
  439. $(opened_input_value_matrix_variable).focus();
  440. return;
  441. }
  442. opened_name_value_matrix_variable = true;
  443. sequence_name_opened_value_matrix_variable = which_parameter;
  444. sequence_function_opened_value_matrix_variable = which_function;
  445. $(parent_node).find('.span_value_variable').text('');
  446. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  447. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  448. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  449. } else {
  450. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  451. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  452. }
  453. $('.width-dynamic').on('input', function() {
  454. var inputWidth = $(this).textWidth()+10;
  455. opened_input_value_matrix_variable = this;
  456. $(this).focus();
  457. var tmpStr = $(this).val();
  458. $(this).val('');
  459. $(this).val(tmpStr);
  460. $(this).css({
  461. width: inputWidth
  462. })
  463. }).trigger('input');
  464. $('.width-dynamic').focusout(function() {
  465. /// update array:
  466. if ($(this).val().trim()) {
  467. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  468. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  469. } else {
  470. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  471. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  472. } else {
  473. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  474. }
  475. }
  476. }
  477. $(this).remove();
  478. /// update elements:
  479. opened_name_value_matrix_variable = false;
  480. opened_input_value_matrix_variable = false;
  481. renderAlgorithm();
  482. });
  483. $('.width-dynamic').on('keydown', function(e) {
  484. var code = e.keyCode || e.which;
  485. if(code == 13) {
  486. if ($(this).val().trim()) {
  487. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  488. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  489. } else {
  490. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  491. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  492. } else {
  493. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  494. }
  495. }
  496. }
  497. $(this).remove();
  498. /// update elements:
  499. opened_name_value_matrix_variable = false;
  500. opened_input_value_matrix_variable = false;
  501. renderAlgorithm();
  502. }
  503. if(code == 27) {
  504. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  505. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1));
  506. } else {
  507. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index]);
  508. }
  509. $(this).remove();
  510. /// update elements:
  511. opened_name_value_matrix_variable = false;
  512. opened_input_value_matrix_variable = false;
  513. }
  514. });
  515. }
  516. var opened_name_value_variable = false;
  517. var opened_input_value_variable = null;
  518. var sequence_name_opened_value_variable;
  519. var sequence_function_opened_value_variable;
  520. function enableVarValueUpdate(parent_node, which_function, which_parameter) {
  521. if (opened_name_value_variable) {
  522. $(opened_input_value_variable).focus();
  523. return;
  524. }
  525. opened_name_value_variable = true;
  526. sequence_name_opened_value_variable = which_parameter;
  527. sequence_function_opened_value_variable = which_function;
  528. $(parent_node).find('.span_value_variable').text('');
  529. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  530. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  531. + programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  532. } else {
  533. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  534. + programa.funcoes[which_function].variaveis[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  535. }
  536. $('.width-dynamic').on('input', function() {
  537. var inputWidth = $(this).textWidth()+10;
  538. opened_input_value_variable = this;
  539. $(this).focus();
  540. var tmpStr = $(this).val();
  541. $(this).val('');
  542. $(this).val(tmpStr);
  543. $(this).css({
  544. width: inputWidth
  545. })
  546. }).trigger('input');
  547. $('.width-dynamic').focusout(function() {
  548. /// update array:
  549. if ($(this).val().trim()) {
  550. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  551. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  552. } else{
  553. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  554. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  555. } else {
  556. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  557. }
  558. }
  559. }
  560. $(this).remove();
  561. /// update elements:
  562. opened_name_value_variable = false;
  563. opened_input_value_variable = false;
  564. renderAlgorithm();
  565. });
  566. $('.width-dynamic').on('keydown', function(e) {
  567. var code = e.keyCode || e.which;
  568. if(code == 13) {
  569. if ($(this).val().trim()) {
  570. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  571. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  572. } else{
  573. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  574. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  575. } else {
  576. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  577. }
  578. }
  579. }
  580. $(this).remove();
  581. /// update elements:
  582. opened_name_value_variable = false;
  583. opened_input_value_variable = false;
  584. renderAlgorithm();
  585. }
  586. if(code == 27) {
  587. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  588. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1));
  589. } else{
  590. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor);
  591. }
  592. $(this).remove();
  593. /// update elements:
  594. opened_name_value_variable = false;
  595. opened_input_value_variable = false;
  596. }
  597. });
  598. }
  599. var opened_name_variable = false;
  600. var opened_input_variable = null;
  601. var sequence_name_opened_variable;
  602. var sequence_function_opened_variable;
  603. function enableNameVariableUpdate(parent_node, which_function, which_parameter) {
  604. if (opened_name_variable) {
  605. $(opened_input_variable).focus();
  606. return;
  607. }
  608. opened_name_variable = true;
  609. sequence_name_opened_variable = which_parameter;
  610. sequence_function_opened_variable = which_function;
  611. $(parent_node).find('.span_name_variable').text('');
  612. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  613. + programa.funcoes[which_function].variaveis[which_parameter].nome + "' />" ).insertBefore($(parent_node).find('.span_name_variable'));
  614. $('.width-dynamic').on('input', function() {
  615. var inputWidth = $(this).textWidth()+10;
  616. opened_input_variable = this;
  617. $(this).focus();
  618. var tmpStr = $(this).val();
  619. $(this).val('');
  620. $(this).val(tmpStr);
  621. $(this).css({
  622. width: inputWidth
  623. })
  624. }).trigger('input');
  625. $('.width-dynamic').focusout(function() {
  626. /// update array:
  627. if ($(this).val().trim()) {
  628. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  629. }
  630. $(this).remove();
  631. /// update elements:
  632. opened_name_variable = false;
  633. opened_input_variable = false;
  634. renderAlgorithm();
  635. });
  636. $('.width-dynamic').on('keydown', function(e) {
  637. var code = e.keyCode || e.which;
  638. if(code == 13) {
  639. if ($(this).val().trim()) {
  640. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  641. }
  642. $(this).remove();
  643. /// update elements:
  644. opened_name_variable = false;
  645. opened_input_variable = false;
  646. renderAlgorithm();
  647. }
  648. if(code == 27) {
  649. $(parent_node).find('.span_name_variable').text(programa.funcoes[which_function].variaveis[which_parameter].nome);
  650. $(this).remove();
  651. /// update elements:
  652. opened_name_variable = false;
  653. opened_input_variable = false;
  654. }
  655. });
  656. }
  657. var opened_name_parameter = false;
  658. var opened_input_parameter = null;
  659. var sequence_name_opened_parameter;
  660. var sequence_function_opened_parameter;
  661. function enableNameParameterUpdate(parent_node, which_function, which_parameter) {
  662. if (opened_name_parameter) {
  663. $(opened_input_parameter).focus();
  664. return;
  665. }
  666. opened_name_parameter = true;
  667. sequence_name_opened_parameter = which_parameter;
  668. sequence_function_opened_parameter = which_function;
  669. $(parent_node).find('.span_name_parameter').text('');
  670. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+programa.funcoes[which_function].lista_parametros[which_parameter].nome+"' />" ).insertBefore($(parent_node).find('.span_name_parameter'));
  671. $('.width-dynamic').on('input', function() {
  672. var inputWidth = $(this).textWidth()+10;
  673. opened_input_parameter = this;
  674. $(this).focus();
  675. var tmpStr = $(this).val();
  676. $(this).val('');
  677. $(this).val(tmpStr);
  678. $(this).css({
  679. width: inputWidth
  680. })
  681. }).trigger('input');
  682. $('.width-dynamic').focusout(function() {
  683. /// update array:
  684. if ($(this).val().trim()) {
  685. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  686. }
  687. $(this).remove();
  688. /// update elements:
  689. opened_name_parameter = false;
  690. opened_input_parameter = false;
  691. renderAlgorithm();
  692. });
  693. $('.width-dynamic').on('keydown', function(e) {
  694. var code = e.keyCode || e.which;
  695. if(code == 13) {
  696. if ($(this).val().trim()) {
  697. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  698. }
  699. $(this).remove();
  700. /// update elements:
  701. opened_name_parameter = false;
  702. opened_input_parameter = false;
  703. renderAlgorithm();
  704. }
  705. if(code == 27) {
  706. $(parent_node).find('.span_name_parameter').text(programa.funcoes[which_function].lista_parametros[which_parameter].nome);
  707. $(this).remove();
  708. /// update elements:
  709. opened_name_parameter = false;
  710. opened_input_parameter = false;
  711. }
  712. });
  713. }
  714. function removeParameter(parent_node, which_function, which_parameter) {
  715. programa.funcoes[which_function].lista_parametros.splice(which_parameter, 1);
  716. renderAlgorithm();
  717. }
  718. function appendFunction(function_obj, sequence) {
  719. var appender = '<div class="ui secondary segment function_div list-group-item">'
  720. + '<span class="glyphicon glyphicon-move" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>'
  721. + (!function_obj.eh_principal ? '<button class="ui icon button large remove_function_button" onclick="removeFunctionHandler(this.parentNode, '+sequence+')"><i class="red icon times"></i></button>' : '')
  722. + '<button class="ui icon button tiny minimize_function_button" onclick="minimizeFunctionHandler(this.parentNode, '+sequence+')"><i class="icon window minimize"></i></button>'
  723. + '<div class="function_signature_div">'+i18n('function')+' ';
  724. if (function_obj.eh_principal) {
  725. appender += '<div class="function_name_div"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + i18n('void') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="span_name_function" >'+function_obj.nome+'</span> </div> '
  726. + '( <div class="ui large labels parameters_list">';
  727. } else {
  728. appender += renderFunctionReturn(function_obj, sequence);
  729. appender += '<div class="function_name_div"><span class="span_name_function" ondblclick="enableNameFunctionUpdate(this.parentNode, '+sequence+')" >'+function_obj.nome+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableNameFunctionUpdate(this.parentNode, '+sequence+')"></i></div> '
  730. + '( <i class="ui icon plus square outline add_parameter" onclick="addParameter('+sequence+')"></i> <div class="ui large labels parameters_list">';
  731. }
  732. appender += renderFunctionParameters(function_obj, sequence);
  733. appender += '</div> ) {</div>'
  734. + (function_obj.esta_oculta ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ')
  735. + '<div class="ui top attached segment variables_list_div"><div class="ui teal small labeled icon button add_variable_button" onclick="addVariable('+sequence+')">'+i18n('Variable')+'<i class="add icon"></i></div>'
  736. + renderVariables(function_obj, sequence)
  737. + '</div>'
  738. + '<div class="ui bottom attached segment commands_list_div"><div class="ui teal small labeled icon button add_command_button seq_'+sequence+'">'+i18n('Command')+'<i class="add icon"></i></div></div>'
  739. + '<div class="function_close_div">}</div>'
  740. + '</div>'
  741. + '</div>';
  742. $('.all_functions').append(appender);
  743. }
  744. // Essa função imprime os parâmetros e cria os elementos para a sua manipulação
  745. function renderFunctionParameters(function_obj, sequence) {
  746. var ret = "";
  747. if (function_obj.lista_parametros != null) {
  748. for (var j = 0; j < function_obj.lista_parametros.length; j++) {
  749. var par_temp = function_obj.lista_parametros[j];
  750. ret += '<div class="ui label function_name_parameter"><span class="span_name_parameter" ondblclick="enableNameParameterUpdate(this.parentNode, '+sequence+', '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameParameterUpdate(this.parentNode, '+sequence+', '+j+')"></i>';
  751. ret += '<div class="ui dropdown parameter_type seq_'+j+' fun_'+sequence+'">';
  752. if (par_temp.dimensoes > 0) {
  753. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  754. ret += '</div>';
  755. } else {
  756. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  757. }
  758. ret += '<i class="dropdown icon"></i>'
  759. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  760. var i = 0;
  761. for (tm in tiposDados) {
  762. i ++;
  763. if (i == 1) { continue; }
  764. if (i == (Object.keys(tiposDados).length)) { break; }
  765. ret += '<div class="item ' + ((par_temp.tipo == tm && par_temp.dimensoes < 1) ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  766. }
  767. i = 0;
  768. for (tm in tiposDados) {
  769. i ++;
  770. if (i == 1) { continue; }
  771. if (i == (Object.keys(tiposDados).length)) { break; }
  772. ret += '<div class="item seq_'+j+' '+tm+' fun_'+sequence+' ' + ((par_temp.tipo == tm && par_temp.dimensoes > 0) ? ' selected ' : '') + ' ">'
  773. + i18n(tiposDados.vector)+':'+i18n(tm)
  774. + '</div>';
  775. }
  776. ret += '</div></div>';
  777. ret += ' <i class="red icon times remove_parameter" onclick="removeParameter(this.parentNode, '+sequence+', '+j+')"></i></div>';
  778. }
  779. }
  780. return ret;
  781. }
  782. // Essa função imprime as variáveis e os recursos para sua manipulação
  783. function renderVariables(function_obj, sequence) {
  784. var ret = "";
  785. if (function_obj.variaveis != null) {
  786. for (var j = 0; j < function_obj.variaveis.length; j++) {
  787. var par_temp = function_obj.variaveis[j];
  788. ret += '<div class="ui label name_variable"><span class="span_name_variable" ondblclick="enableNameVariableUpdate(this.parentNode, '+sequence+', '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameVariableUpdate(this.parentNode, '+sequence+', '+j+')"></i>';
  789. ret += '<div class="ui dropdown variable_type seq_'+j+' fun_'+sequence+'">';
  790. if (par_temp.dimensoes > 0) {
  791. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  792. for (i = 0; i < par_temp.dimensoes; i ++) {
  793. ret += ' [ ] ';
  794. }
  795. ret += '</div>';
  796. } else {
  797. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  798. }
  799. ret += '<i class="dropdown icon"></i>'
  800. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  801. var i = 0;
  802. for (tm in tiposDados) {
  803. i ++;
  804. if (i == 1) { continue; }
  805. if (i == (Object.keys(tiposDados).length)) { break; }
  806. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  807. }
  808. i = 0;
  809. for (tm in tiposDados) {
  810. i ++;
  811. if (i == 1) { continue; }
  812. if (i == (Object.keys(tiposDados).length)) { break; }
  813. ret += '<div class="item seq_'+j+' fun_'+sequence+'">'
  814. + '<i class="dropdown icon"></i>'
  815. + i18n(tiposDados.vector)+':'+i18n(tm)
  816. + '<div class="menu seq_'+j+' fun_'+sequence+'">'
  817. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  818. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  819. + '</div>'
  820. + '</div>';
  821. }
  822. ret += '</div></div> = ';
  823. if (par_temp.dimensoes == 0) {
  824. if (par_temp.tipo == tiposDados.real) {
  825. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor.toFixed(1)+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  826. } else {
  827. if (par_temp.tipo == tiposDados.boolean) {
  828. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="alternateBooleanVarValue(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="alternateBooleanVarValue(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  829. } else {
  830. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  831. }
  832. }
  833. } else {
  834. ret += '<table class="tabela_var">';
  835. if (par_temp.dimensoes == 1) {
  836. ret += '<tr>';
  837. if (par_temp.tipo == tiposDados.real) {
  838. for (var k = 0; k < par_temp.colunas; k++) {
  839. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  840. }
  841. } else {
  842. for (var k = 0; k < par_temp.colunas; k++) {
  843. if (par_temp.tipo == tiposDados.boolean) {
  844. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarVectorValue(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  845. } else {
  846. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  847. }
  848. }
  849. }
  850. ret += '</tr>';
  851. ret += '</table>';
  852. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnVector('+sequence+', '+j+')"></i>'
  853. + ' <i class="ui icon plus square outline" onclick="addColumnVector('+sequence+', '+j+')"></i></div>';
  854. }
  855. if (par_temp.dimensoes == 2) {
  856. if (par_temp.tipo == tiposDados.real) {
  857. for (var l = 0; l < par_temp.linhas; l++) {
  858. ret += '<tr>';
  859. for (var k = 0; k < par_temp.colunas; k++) {
  860. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  861. }
  862. ret += '</tr>';
  863. }
  864. } else {
  865. for (var l = 0; l < par_temp.linhas; l++) {
  866. ret += '<tr>';
  867. for (var k = 0; k < par_temp.colunas; k++) {
  868. if (par_temp.tipo == tiposDados.boolean) {
  869. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarMatrixValue(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  870. } else {
  871. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  872. }
  873. }
  874. ret += '</tr>';
  875. }
  876. }
  877. if (par_temp.linhas == 0) {
  878. ret += '<tr><td></td></tr>';
  879. }
  880. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineMatrix('+sequence+', '+j+')"></i>'
  881. + ' <i class="ui icon plus square outline" onclick="addLineMatrix('+sequence+', '+j+')"></i></td></tr>';
  882. ret += '</table>';
  883. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnMatrix('+sequence+', '+j+')"></i>'
  884. + ' <i class="ui icon plus square outline" onclick="addColumnMatrix('+sequence+', '+j+')"></i></div>';
  885. }
  886. }
  887. ret += ' <i class="red icon times remove_parameter" onclick="deleteVariable('+sequence+', '+j+')"></i></div>';
  888. }
  889. }
  890. return ret;
  891. }
  892. // Essa função imprime o tipo de retorno da função e cria o menu do tipo 'select' para alteração
  893. function renderFunctionReturn(function_obj, sequence) {
  894. var ret = '<div class="ui dropdown function_return seq_'+sequence+'">';
  895. if (function_obj.dimensoes_retorno > 0) {
  896. ret += '<div class="text seq_'+sequence+'"">'+ i18n(tiposDados.vector)+':'+i18n(function_obj.tipo_retorno);
  897. ret += '</div>';
  898. } else {
  899. ret += '<div class="text seq_'+sequence+'"">'+i18n(function_obj.tipo_retorno)+'</div>';
  900. }
  901. ret += '<i class="dropdown icon"></i>'
  902. + '<div class="menu seq_'+sequence+'"">';
  903. var i = 0;
  904. for (tm in tiposDados) {
  905. if (i == (Object.keys(tiposDados).length - 1)) { break; }
  906. ret += '<div class="item ' + ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno < 1) ? ' selected ' : '') + ' seq_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  907. i ++;
  908. }
  909. i = 0;
  910. for (tm in tiposDados) {
  911. i ++;
  912. if (i == 1) { continue; }
  913. if (i == (Object.keys(tiposDados).length)) { break; }
  914. ret += '<div class="item seq_'+sequence+' '+tm+' '+ ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno > 0) ? ' selected ' : '') +'" data-text="'+i18n(tiposDados.vector)+':'+i18n(tm)+' ">'
  915. + i18n(tiposDados.vector)+':'+i18n(tm)
  916. + '</div>';
  917. }
  918. ret += '</div></div>';
  919. return ret;
  920. }
  921. $.fn.textWidth = function(text, font) {
  922. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  923. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  924. return $.fn.textWidth.fakeEl.width();
  925. };