12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085 |
- import { Types } from './types';
- import * as Models from './ivprog_elements';
- import { LocalizedStrings } from './../services/localizedStringsService';
- import * as Utils from './utils';
- import { registerUserEvent, registerSystemEvent, ActionTypes } from "./../services/userLog";
- var counter_new_globals = 0;
- export function addGlobal (program, is_from_click = false) {
- var new_global = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_global') + '_' + counter_new_globals, 0);
- counter_new_globals ++;
- program.addGlobal(new_global);
- registerUserEvent(new_global.name, ActionTypes.INSERT_GLOBAL_VAR);
- var newe = renderGlobal(new_global);
- if (is_from_click) {
- newe.css('display', 'none');
- newe.fadeIn();
- }
- }
- function toggleConstant (global_var) {
- global_var.is_constant = !global_var.is_constant;
- registerUserEvent(global_var.name, ActionTypes.SET_GLOBAL_CONST);
- }
- function updateName (global_var, new_name, global_obj_dom) {
- if (global_var.name == new_name) {
- return;
- }
- if (isValidIdentifier(new_name)) {
- if (globalNameAlreadyExists(new_name)) {
- Utils.renderErrorMessage(global_obj_dom.find('.editing_name_var'), LocalizedStrings.getUI('inform_valid_global_duplicated'));
- } else {
- registerUserEvent(global_var.name, ActionTypes.RENAME_GLOBAL_VAR, new_name);
- global_var.name = new_name;
- }
- } else {
- Utils.renderErrorMessage(global_obj_dom.find('.editing_name_var'), LocalizedStrings.getUI('inform_valid_name'));
- }
- }
- function globalNameAlreadyExists (global_name) {
- for (var i = 0; i < window.program_obj.globals.length; i++) {
- if (window.program_obj.globals[i].name == global_name) {
- return true;
- }
- }
- return false;
- }
- function isValidIdentifier (identifier_str) {
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(identifier_str);
- }
- function updateType (global_var, new_type, new_dimensions = 0) {
- global_var.type = new_type;
- global_var.dimensions = new_dimensions;
- if (new_dimensions > 0) {
- global_var.rows = new_dimensions;
- global_var.columns = 2;
- }
- registerUserEvent(global_var.name, ActionTypes.CHANGE_VAR_TYPE, new_type,
- new_dimensions, global_var.rows, global_var.columns);
- updateInitialValues(global_var);
- }
- function removeGlobal (global_var, global_container) {
- var index = window.program_obj.globals.indexOf(global_var);
- if (index > -1) {
- window.insertContext = true;
- window.program_obj.globals.splice(index, 1);
- }
- registerUserEvent(global_var.name, ActionTypes.REMOVE_GLOBAL_VAR);
- global_container.children().off();
- global_container.off();
- global_container.fadeOut();
- }
- function updateInitialValues (global_var) {
- if (global_var.type == Types.INTEGER) {
- if (global_var.dimensions == 0) {
- global_var.value = 0;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [0, 0];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[0, 0], [0, 0]];
- }
- }
- if (global_var.type == Types.REAL) {
- if (global_var.dimensions == 0) {
- global_var.value = 0.0;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [0.0, 0.0];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[0.0, 0.0], [0.0, 0.0]];
- }
- }
- if (global_var.type == Types.TEXT) {
- if (global_var.dimensions == 0) {
- global_var.value = LocalizedStrings.getUI('textvar_default_value');
- }
- if (global_var.dimensions == 1) {
- global_var.value = [LocalizedStrings.getUI('textvar_default_value'), LocalizedStrings.getUI('textvar_default_value')];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[LocalizedStrings.getUI('textvar_default_value'), LocalizedStrings.getUI('textvar_default_value')],
- [LocalizedStrings.getUI('textvar_default_value'), LocalizedStrings.getUI('textvar_default_value')]];
- }
- }
- if (global_var.type == Types.BOOLEAN) {
- if (global_var.dimensions == 0) {
- global_var.value = true;
- }
- if (global_var.dimensions == 1) {
- global_var.value = [true, true];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [[true, true], [true, true]];
- }
- }
- if (global_var.type == Types.CHAR) {
- if (global_var.dimensions == 0) {
- global_var.value = 'A';
- }
- if (global_var.dimensions == 1) {
- global_var.value = ['A', 'A'];
- }
- if (global_var.dimensions == 2) {
- global_var.value = [['A', 'A'], ['A', 'A']];
- }
- }
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.name,
- global_var.value);
- }
- function alternateBooleanGlobalValue (global_var, value_container) {
- global_var.value = !global_var.value;
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(`logic_value_${global_var.value}`));
- }
- function alternateBooleanGlobalVectorValue (global_var, index, value_container) {
- global_var.value[index] = !global_var.value[index];
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(`logic_value_${global_var.value[index]}`));
- }
- function removeGlobalColumnVector (global_var) {
- if (global_var.columns == 0) {
- return;
- }
- global_var.columns --;
- global_var.value.splice(global_var.value.length - 1, 1);
- }
- function addGlobalColumnVector (global_var) {
- global_var.columns ++;
- if (global_var.type == Types.INTEGER) {
- global_var.value.push(0);
- }
- if (global_var.type == Types.REAL) {
- global_var.value.push(0.0);
- }
- if (global_var.type == Types.TEXT) {
- global_var.value.push(LocalizedStrings.getUI('textvar_default_value'));
- }
- if (global_var.type == Types.BOOLEAN) {
- global_var.value.push(true);
- }
- if (global_var.type == Types.CHAR) {
- global_var.value.push(LocalizedStrings.getUI('charvar_default_value'));
- }
- }
- function removeColumnGlobalMatrix (global_var) {
- if (global_var.columns == 0) {
- return;
- }
- global_var.columns --;
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].splice(global_var.value[i].length - 1, 1);
- }
- }
- function addColumnGlobalMatrix (global_var) {
- global_var.columns ++;
- if (global_var.type == Types.INTEGER) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(0);
- }
- }
- if (global_var.type == Types.REAL) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(0.0);
- }
- }
- if (global_var.type == Types.TEXT) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(LocalizedStrings.getUI('textvar_default_value'));
- }
- }
- if (global_var.type == Types.BOOLEAN) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(true);
- }
- }
- if (global_var.type == Types.CHAR) {
- for (var i = 0; i < global_var.rows; i++) {
- global_var.value[i].push(LocalizedStrings.getUI('charvar_default_value'));
- }
- }
- }
- function removeLineGlobalMatrix (global_var) {
- if (global_var.rows == 0) {
- return;
- }
- global_var.rows --;
- global_var.value.splice(global_var.value.length - 1, 1);
- }
- function addLineGlobalMatrix (global_var) {
- global_var.rows ++;
- if (global_var.type == Types.INTEGER) {
- var n_l = [];
- for (var i = 0; i < global_var.columns; i++) {
- n_l.push(0);
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.REAL) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(0.0);
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.TEXT) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(LocalizedStrings.getUI('textvar_default_value'));
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.BOOLEAN) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(true);
- }
- global_var.value.push(n_l);
- }
- if (global_var.type == Types.CHAR) {
- var n_l = [];
- for (i = 0; i < global_var.columns; i++) {
- n_l.push(LocalizedStrings.getUI('charvar_default_value'));
- }
- global_var.value.push(n_l);
- }
- }
- function alternateBooleanGlobalMatrixValue (global_var, row, index, value_container) {
- global_var.value[row][index] = !global_var.value[row][index];
- $(value_container).find('.span_value_variable').text(LocalizedStrings.getUI(`logic_value_${global_var.value[row][index]}`));
- }
- function renderValues (global_var, global_container) {
- var ret = "";
- var j = 0;
- if (global_var.dimensions == 0) {
- if (global_var.type == Types.REAL) {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+global_var.value.toFixed(1)+'</span> </div> ';
- } else {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable boolean_simple_type">'+LocalizedStrings.getUI(`logic_value_${global_var.value}`)+'</span> </div> ';
- } else {
- ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+global_var.value+'</span> </div> ';
- }
- }
- } else {
- ret += '<table class="tabela_var">';
- if (global_var.dimensions == 1) {
- ret += '<tr>';
- if (global_var.type == Types.REAL) {
- for (var k = 0; k < global_var.columns; k++) {
- ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+global_var.value[k].toFixed(1)+'</span></td>';
- }
- } else {
- for (var k = 0; k < global_var.columns; k++) {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<td><span class="span_value_variable boolean_vector_var" data-index="'+k+'">'+LocalizedStrings.getUI(`logic_value_${global_var.value[k]}`)+'</span></td>';
- } else {
- ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+global_var.value[k]+'</span>'+'</td>';
- }
- }
- }
-
- ret += '</tr>';
- ret += '</table>';
- ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_vector_column"></i>'
- + ' <i class="ui icon plus square outline add_global_vector_column"></i></div>';
- }
- if (global_var.dimensions == 2) {
- if (global_var.type == Types.REAL) {
- for (var l = 0; l < global_var.rows; l++) {
- ret += '<tr>';
- for (var k = 0; k < global_var.columns; k++) {
- ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+global_var.value[l][k].toFixed(1)+'</span>'+'</td>';
- }
- ret += '</tr>';
- }
- } else {
- for (var l = 0; l < global_var.rows; l++) {
- ret += '<tr>';
- for (var k = 0; k < global_var.columns; k++) {
- if (global_var.type == Types.BOOLEAN) {
- ret += '<td><span class="span_value_variable boolean_matrix_var" data-index="'+k+'" data-row="'+l+'">'+LocalizedStrings.getUI(`logic_value_${global_var.value[l][k]}`)+'</span></td>';
- } else {
- ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+global_var.value[l][k]+'</span></td>';
- }
- }
- ret += '</tr>';
- }
- }
- if (global_var.rows == 0) {
- ret += '<tr><td></td></tr>';
- }
- ret += '<tr><td colspan="'+global_var.columns+'" class="tr_manage_lines"><i class="ui icon minus square outline remove_global_matrix_line"></i>'
- + ' <i class="ui icon plus square outline add_global_matrix_line"></i></td></tr>';
- ret += '</table>';
- ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline remove_global_matrix_column"></i>'
- + ' <i class="ui icon plus square outline add_global_matrix_column"></i></div>';
- }
-
- }
- global_container.find( ".div_valor_var" ).html('');
- ret = $(ret);
- ret.find('.span_value_variable').data('associatedOject', global_var);
- ret.find( ".boolean_simple_type" ).on('click', function(e){
- alternateBooleanGlobalValue(global_var, this.parentNode);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- });
- ret.find( ".simple_var" ).on('click', function(e){
- registerUserEvent(global_var.name, ActionTypes.ENTER_CHANGE_GLOBAL_VALUE);
- enableGlobalValueUpdate(global_var, this.parentNode);
- });
- ret.find( ".boolean_vector_var" ).on('click', function(e){
- alternateBooleanGlobalVectorValue(global_var, $(this).data('index'), this.parentNode);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- });
- ret.find( ".vector_var" ).on('click', function(e){
- registerUserEvent(global_var.name, ActionTypes.ENTER_CHANGE_GLOBAL_VALUE);
- enableGlobalVectorValueUpdate(global_var, $(this).data('index'), this.parentNode);
- });
- ret.find( ".remove_global_vector_column" ).on('click', function(e){
- removeGlobalColumnVector(global_var);
- global_container.find( ".div_valor_var" ).html('');
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- renderValues(global_var, global_container);
- });
- ret.find( ".add_global_vector_column" ).on('click', function(e){
- addGlobalColumnVector(global_var);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- global_container.find( ".div_valor_var" ).html('');
- renderValues(global_var, global_container);
- });
- ret.find( ".remove_global_matrix_column" ).on('click', function(e){
- removeColumnGlobalMatrix(global_var);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- global_container.find( ".div_valor_var" ).html('');
- renderValues(global_var, global_container);
- });
- ret.find( ".add_global_matrix_column" ).on('click', function(e){
- addColumnGlobalMatrix(global_var);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- global_container.find( ".div_valor_var" ).html('');
- renderValues(global_var, global_container);
- });
- ret.find( ".remove_global_matrix_line" ).on('click', function(e){
- removeLineGlobalMatrix(global_var);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- global_container.find( ".div_valor_var" ).html('');
- renderValues(global_var, global_container);
- });
- ret.find( ".add_global_matrix_line" ).on('click', function(e){
- addLineGlobalMatrix(global_var);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_TYPE,
- global_var.type, global_var.dimensions, global_var.rows, global_var.columns);
- registerSystemEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- global_container.find( ".div_valor_var" ).html('');
- renderValues(global_var, global_container);
- });
- ret.find( ".boolean_matrix_var" ).on('click', function(e){
- alternateBooleanGlobalMatrixValue(global_var, $(this).data('row'), $(this).data('index'), this.parentNode);
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- });
- ret.find( ".matrix_var" ).on('click', function(e){
- registerUserEvent(global_var.name, ActionTypes.ENTER_CHANGE_GLOBAL_VALUE);
- enableGlobalMatrixValueUpdate(global_var, $(this).data('row'), $(this).data('index'), this.parentNode);
- });
- global_container.find( ".div_valor_var" ).append(ret);
- updateColumnsAndRowsText(global_container, global_var);
- }
- function addHandlers (global_container) {
- var global_var = global_container.data('associatedOject');
- // Manage constant option:
- global_container.find( ".alternate_constant" ).on('click', function(e){
- toggleConstant(global_var);
- $( this ).removeClass( "on off" );
- if (global_var.is_constant) {
- $( this ).addClass( "on" );
- } else {
- $( this ).addClass( "off" );
- }
- });
- // Manage global name:
- global_container.find( ".editing_name_var" ).on('click', function(e){
- registerUserEvent(global_var.name, ActionTypes.ENTER_CHANGE_GLOBAL_NAME);
- enableNameUpdate(global_container);
- });
- // Menu to change type:
- global_container.find('.ui.dropdown.global_type').dropdown({
- onChange: function(_, __, $selectedItem) {
- if ($selectedItem.data('dimensions')) {
- updateType(global_var, Types[$selectedItem.data('type')], $selectedItem.data('dimensions'));
- } else {
- updateType(global_var, Types[$selectedItem.data('type')]);
- }
- renderValues(global_var, global_container);
- },
- selectOnKeydown: false
- });
- // Remove global:
- global_container.find( ".remove_global" ).on('click', function(e){
- removeGlobal(global_var, global_container);
- });
- }
- function updateColumnsAndRowsText (global_container, global_var) {
- var prev = global_container.find('.text').text().split('[');
- if (prev.length == 2) {
- var ff = prev[0] + '[ ' + global_var.columns + ' ] ';
- global_container.find('.text').empty();
- global_container.find('.text').text(ff);
- }
- if (prev.length == 3) {
- var ff = prev[0] + '[ ' + global_var.columns + ' ] [ ' + global_var.rows + ' ] ';
- global_container.find('.text').empty();
- global_container.find('.text').text(ff);
- }
- }
- export function renderGlobal (global_var) {
- var element = '<div class="ui label global_container pink"><i class="ui icon ellipsis vertical inverted"></i><div class="global_const">const: ';
- element += '<i class="ui icon toggle '+(global_var.is_constant?"on":"off")+' alternate_constant"></i></div>';
-
- element += '<div class="ui dropdown global_type">';
- if (global_var.dimensions == 1) {
- element += '<div class="text">'+ LocalizedStrings.getUI('vector')+ ': ' + LocalizedStrings.getUI(`type_${global_var.type}`);
- element += ' [ <span class="dimensions_0"></span> ] ';
- element += '</div>';
- } else if (global_var.dimensions == 2) {
- element += '<div class="text">'+ LocalizedStrings.getUI('matrix')+ ': ' + LocalizedStrings.getUI(`type_${global_var.type}`);
- element += ' [ <span class="dimensions_0"></span> ] [ <span class="dimensions_1"></span> ] ';
- element += '</div>';
- } else {
- element += '<div class="text">' + LocalizedStrings.getUI(`type_${global_var.type.toLowerCase()}`) + '</div>';
- }
- element += '<div class="menu">';
- for (var tm in Types) {
- if (tm == Types.VOID.toUpperCase()) {
- continue;
- }
- element += '<div class="item ' + (global_var.type == tm.toLowerCase() && global_var.dimensions == 0 ? ' selected ' : '') + '" data-type="'+tm+'" >'+LocalizedStrings.getUI(`type_${tm.toLowerCase()}`)+'</div>';
- }
- element += '<div class="item ' + (global_var.dimensions == 1 ? ' selected ' : '') + '">'
- + '<i class="dropdown icon"></i>' + LocalizedStrings.getUI('vector')
- + '<div class="menu">';
- for (var tm in Types) {
- if (tm == Types.VOID.toUpperCase()) {
- continue;
- }
- element += '<div class="item ' + (global_var.type == tm.toLowerCase() && global_var.dimensions == 1 ? ' selected ' : '') + '" data-text="'+ LocalizedStrings.getUI('vector')+':'+LocalizedStrings.getUI(`type_${tm.toLowerCase()}`)+' [ ] " data-type="'+tm+'" data-dimensions="1"> '+LocalizedStrings.getUI(`type_${tm.toLowerCase()}`)+'</div>';
- }
- element += '</div></div>';
- element += '<div class="item ' + (global_var.dimensions == 2 ? ' selected ' : '') + '">'
- + '<i class="dropdown icon"></i>' + LocalizedStrings.getUI('matrix')
- + '<div class="menu">';
- for (var tm in Types) {
- if (tm == Types.VOID.toUpperCase()) {
- continue;
- }
- element += '<div class="item ' + (global_var.type == tm.toLowerCase() && global_var.dimensions == 2 ? ' selected ' : '') + '" data-text="'+ LocalizedStrings.getUI('matrix')+':'+LocalizedStrings.getUI(`type_${tm.toLowerCase()}`)+' [ ] " data-type="'+tm+'" data-dimensions="2"> '+LocalizedStrings.getUI(`type_${tm.toLowerCase()}`)+'</div>';
- }
- element += '</div></div>';
- element += '</div></div> <div class="editing_name_var"> <span class="span_name_variable enable_edit_name_parameter">'+global_var.name+'</span> </div> <span class="character_equals"> <— </span> ';
- element += '<div class="ui div_valor_var">'+global_var.value+'</div>';
- element += ' <i class="yellow inverted icon times remove_global"></i></div>';
- var complete_element = $(element);
- complete_element.data('associatedOject', global_var);
- $('.list_globals').append(complete_element);
- addHandlers(complete_element);
- renderValues(global_var, complete_element);
- if (global_var.dimensions == 1) {
- complete_element.find('.dimensions_0').text(global_var.columns);
- }
- if (global_var.dimensions == 2) {
- complete_element.find('.dimensions_0').text(global_var.columns);
- complete_element.find('.dimensions_1').text(global_var.rows);
- }
- return complete_element;
- }
- var opened_name_value_matrix_global_v = false;
- var opened_input_value_matrix_global_v = null;
- function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
- if (opened_name_value_matrix_global_v) {
- opened_input_value_matrix_global_v.focus();
- return;
- }
- parent_node = $(parent_node);
- opened_name_value_matrix_global_v = true;
- parent_node.find('.span_value_variable').text('');
- var input_field;
- if (global_var.type == Types.REAL) {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[row][index].toFixed(1) + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- } else {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[row][index] + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- }
- input_field.on('input', function() {
- var inputWidth = input_field.textWidth()+10;
- opened_input_value_matrix_global_v = input_field;
- input_field.focus();
- var tmpStr = input_field.val();
- input_field.val('');
- input_field.val(tmpStr);
- input_field.css({
- width: inputWidth
- })
- }).trigger('input');
- input_field.focusout(function() {
- /// update array:
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[row][index] = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[row][index] = parseInt(input_field.val().trim());
- } else {
- global_var.value[row][index] = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value[row][index] = input_field.val();
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- });
- input_field.on('keydown', function(e) {
- var code = e.keyCode || e.which;
- if(code == 13) {
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[row][index] = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[row][index] = parseInt(input_field.val().trim());
- } else {
- global_var.value[row][index] = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value[row][index] = input_field.val();
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- }
- if(code == 27) {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[row][index]);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_matrix_global_v = false;
- opened_input_value_matrix_global_v = false;
- }
- });
- input_field.select();
- }
- var opened_name_value_global_var = false;
- var opened_input_value_global_ar = null;
- function enableGlobalValueUpdate (global_var, parent_node) {
- if (opened_name_value_global_var) {
- opened_input_value_global_ar.focus();
- return;
- }
- parent_node = $(parent_node);
- opened_name_value_global_var = true;
- parent_node.find('.span_value_variable').text('');
- var input_field;
- if (global_var.type == Types.REAL) {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value.toFixed(1) + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- } else {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- }
- input_field.on('input', function() {
- var inputWidth = input_field.textWidth()+10;
- opened_input_value_global_ar = input_field;
- input_field.focus();
- var tmpStr = input_field.val();
- input_field.val('');
- input_field.val(tmpStr);
- input_field.css({
- width: inputWidth
- })
- }).trigger('input');
- input_field.focusout(function() {
- let changed = false;
- /// update array:
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
- } else{
- if (global_var.type == Types.INTEGER) {
- global_var.value = parseInt(input_field.val().trim());
- } else if (global_var.type == Types.CHAR) {
- global_var.value = input_field.val().charAt(0);
- } else {
- global_var.value = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value);
-
- }
- changed = true;
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value = input_field.val();
- changed = true;
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- if (changed) {
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- });
- input_field.on('keydown', function(e) {
- const code = e.keyCode || e.which;
- let changed = true;
- if(code == 13) {
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value = parseInt(input_field.val().trim());
- } else if (global_var.type == Types.CHAR) {
- global_var.value = input_field.val().charAt(0);
- } else {
- global_var.value = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- changed = true;
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value = input_field.val();
- changed = true;
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- if (changed) {
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- }
- if(code == 27) {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
- } else{
- parent_node.find('.span_value_variable').text(global_var.value);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_global_var = false;
- opened_input_value_global_ar = false;
- }
- });
- input_field.select();
- }
- var opened_name_global = false;
- var opened_input_global = null;
- function enableNameUpdate (global_container) {
- var global_var = global_container.data('associatedOject');
- if (opened_name_global) {
- opened_input_global.focus();
- return;
- }
- opened_name_global = true;
- global_container.find('.span_name_variable').text('');
- var input_name = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+global_var.name+"' />" );
- input_name.insertBefore(global_container.find('.span_name_variable'));
- input_name.on('input', function() {
- var inputWidth = input_name.textWidth()+10;
- opened_input_global = input_name;
- opened_input_global.focus();
- opened_input_global.css({
- width: inputWidth
- })
- }).trigger('input');
- input_name.focusout(function() {
- /// update array:
- if (input_name.val().trim().length > 0) {
- updateName(global_var, input_name.val().trim(), global_container);
- global_container.find('.span_name_variable').text(global_var.name);
- } else {
- global_container.find('.span_name_variable').text(global_var.name);
- }
- input_name.off();
- input_name.remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- });
- input_name.on('keydown', function(e) {
- var code = e.keyCode || e.which;
- if(code == 13) {
- if (input_name.val().trim()) {
- updateName(global_var, input_name.val().trim(), global_container);
- global_container.find('.span_name_variable').text(global_var.name);
- } else {
- global_container.find('.span_name_variable').text(global_var.name);
- }
- input_name.off();
- input_name.remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- }
- if(code == 27) {
- global_container.find('.span_name_variable').text(global_var.name);
- input_name.off();
- input_name.remove();
- /// update elements:
- opened_name_global = false;
- opened_input_global = false;
- }
- });
- input_name.select();
-
- }
- var opened_name_value_vector_global_ = false;
- var opened_input_value_vector_global_ = null;
- function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
- if (opened_name_value_vector_global_) {
- opened_input_value_vector_global_.focus();
- return;
- }
- parent_node = $(parent_node);
- opened_name_value_vector_global_ = true;
- parent_node.find('.span_value_variable').text('');
- var input_field;
- if (global_var.type == Types.REAL) {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[index].toFixed(1) + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- } else {
- input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
- + global_var.value[index] + "' />" );
- input_field.insertBefore(parent_node.find('.span_value_variable'));
- }
- input_field.on('input', function() {
- var inputWidth = input_field.textWidth()+10;
- opened_input_value_vector_global_ = input_field;
- input_field.focus();
- var tmpStr = input_field.val();
- input_field.val('');
- input_field.val(tmpStr);
- input_field.css({
- width: inputWidth
- })
- }).trigger('input');
- input_field.focusout(function() {
- let changed = false;
- /// update array:
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[index] = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[index] = parseInt(input_field.val().trim());
- } else {
- global_var.value[index] = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- changed = true;
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value[index] = input_field.val();
- changed = true;
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- if (changed) {
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- });
- input_field.on('keydown', function(e) {
- const code = e.keyCode || e.which;
- let changed = false;
- if(code == 13) {
- if (input_field.val().trim()) {
- if (global_var.type == Types.REAL) {
- global_var.value[index] = parseFloat(input_field.val().trim());
- parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- if (global_var.type == Types.INTEGER) {
- global_var.value[index] = parseInt(input_field.val().trim());
- } else {
- global_var.value[index] = input_field.val().trim();
- }
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- changed = true;
- } else {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- }
- if (global_var.type == Types.TEXT) {
- global_var.value[index] = input_field.val();
- changed = true;
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- if (changed) {
- registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- }
- if(code == 27) {
- if (global_var.type == Types.REAL) {
- parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
- } else {
- parent_node.find('.span_value_variable').text(global_var.value[index]);
- }
- input_field.off();
- input_field.remove();
- /// update elements:
- opened_name_value_vector_global_ = false;
- opened_input_value_vector_global_ = false;
- }
- });
- input_field.select();
- }
- $.fn.textWidth = function(text, font) {
-
- if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
-
- $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
-
- return $.fn.textWidth.fakeEl.width();
- };
|