refs #4974 Now the session is kept open

with the ODBC credentials, and minor changes
This commit is contained in:
Guillermo Bonet 2023-01-04 08:17:28 +01:00
parent 192ac251cd
commit e2412e03e7
2 changed files with 37 additions and 46 deletions

View File

@ -80,11 +80,9 @@ var App = {
window.resizeTo(width, height); window.resizeTo(width, height);
window.moveTo((screen.width - width) / 2, (screen.height - height) / 2); window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
}, },
onUnload: function() { onUnload: function() {
this.disableUi(false); this.disableUi(false);
}, },
onLoad: function() { onLoad: function() {
// Initializes the global variables // Initializes the global variables
var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g); var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g);
@ -151,22 +149,23 @@ var App = {
this.$('user').value = this.regRead(Conf.odbcPath + Conf.dsName, 'UID'); this.$('user').value = this.regRead(Conf.odbcPath + Conf.dsName, 'UID');
this.$('password').value = password this.$('password').value = password
if (notSignOut && password) {
this.$('password').value = password;
this.$('notSignOut').checked = true;
this.onEnterClick();
} else
this.resetForm(true);
// Branch options // Branch options
this.$('branch').value = this.getBranch(); this.$('branch').value = this.getBranch();
this.onChangeBranch(); this.onChangeBranch();
// Datasource options // Datasource options
this.$('datasource').value = this.getDatasource(); this.$('datasource').value = this.getDatasource();
this.onChangeDatasource(true);
},
if (notSignOut && password) {
this.$('password').value = password;
this.$('notSignOut').checked = true;
this.onChangeDatasource(true, false);
this.onEnterClick();
} else {
this.resetForm(true);
this.onChangeDatasource(true, true);
}
},
resetForm: function(clearPassword) { resetForm: function(clearPassword) {
if (clearPassword) if (clearPassword)
this.$('password').value = ''; this.$('password').value = '';
@ -174,15 +173,12 @@ var App = {
this.$('user').focus(); this.$('user').focus();
this.$('user').select(); this.$('user').select();
}, },
createODBC: function(path, dsName, driverName) { createODBC: function(path, dsName, driverName) {
var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath; var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath;
var datasource = Conf.defaultDatasource; var datasource = Conf.defaultDatasource;
var serverURL, sslMode; var serverURL, sslMode;
serverURL = Conf.datasources[datasource].SERVER serverURL = Conf.datasources[datasource].SERVER
sslMode = Conf.datasources[datasource].SSLMODE sslMode = Conf.datasources[datasource].SSLMODE
var params = { var params = {
Driver: driverPath, Driver: driverPath,
DESCRIPTION: Conf.appName, DESCRIPTION: Conf.appName,
@ -199,10 +195,8 @@ var App = {
this.regWrite(path + 'ODBC Data Sources', dsName, driverName); this.regWrite(path + 'ODBC Data Sources', dsName, driverName);
this.regWrites(path + dsName, params); this.regWrites(path + dsName, params);
}, },
updateODBC: function(path, dsName, datasource) { updateODBC: function(path, dsName, datasource) {
var params = Conf.datasources[datasource] var params = Conf.datasources[datasource]
var datasourcePath = this.getDatasourcePath(); var datasourcePath = this.getDatasourcePath();
var myUID = this.regRead(datasourcePath, 'UID'); var myUID = this.regRead(datasourcePath, 'UID');
var myPWD = this.regRead(datasourcePath, 'PWD'); var myPWD = this.regRead(datasourcePath, 'PWD');
@ -211,10 +205,8 @@ var App = {
params['UID'] = myUID; params['UID'] = myUID;
params['PWD'] = myPWD; params['PWD'] = myPWD;
} }
this.regWrites(path + dsName, params); this.regWrites(path + dsName, params);
}, },
disableUi: function(disabled, loadMessage) { disableUi: function(disabled, loadMessage) {
if (disabled) if (disabled)
this.hideMessage(); this.hideMessage();
@ -232,18 +224,15 @@ var App = {
this.$('background').style.display = display; this.$('background').style.display = display;
this.$('spinner').style.display = display; this.$('spinner').style.display = display;
}, },
onCleanCacheClick: function() { onCleanCacheClick: function() {
setTimeout(function() { App.cleanCache(); }); setTimeout(function() { App.cleanCache(); });
}, },
onShowBranchOptionsClick: function() { onShowBranchOptionsClick: function() {
var style = this.$("branchSelector").style; var style = this.$("branchSelector").style;
style.display = style.display == 'none' || !style.display style.display = style.display == 'none' || !style.display
? 'inline' ? 'inline'
: 'none'; : 'none';
}, },
onShowDatasourceOptionsClick: function() { onShowDatasourceOptionsClick: function() {
var style = this.$("datasourceSelector").style; var style = this.$("datasourceSelector").style;
style.display = style.display == 'none' || !style.display style.display = style.display == 'none' || !style.display
@ -256,7 +245,6 @@ var App = {
this.$("datasourceLogo").className = ""; this.$("datasourceLogo").className = "";
}, },
onChangeBranch: function() { onChangeBranch: function() {
if (this.$("branch").value == "master"||"test"||"dev") { if (this.$("branch").value == "master"||"test"||"dev") {
this.$("branchButton").className = this.$("branch").value; this.$("branchButton").className = this.$("branch").value;
@ -267,8 +255,13 @@ var App = {
} }
this.$('user').focus(); this.$('user').focus();
}, },
/**
onChangeDatasource: function(isOnLoad) { * Changes the datasource, and optionally do the following
*
* @param {Boolean} hasUpdate
* @param {Boolean} hasChangeCredentials
*/
onChangeDatasource: function(hasUpdate, hasChangeCredentials) {
var myDatasource = this.$("datasource").value; var myDatasource = this.$("datasource").value;
if (myDatasource == "production"||"test"||"dev") { if (myDatasource == "production"||"test"||"dev") {
this.$("datasourceButton").className = myDatasource; this.$("datasourceButton").className = myDatasource;
@ -276,27 +269,26 @@ var App = {
} else { } else {
this.$("datasourceButton").className = null; this.$("datasourceButton").className = null;
this.$("datasource").className = null; this.$("datasource").className = null;
} };
if (!isOnLoad) { if (!hasUpdate) {
this.updateDatasource(myDatasource); this.updateDatasource(myDatasource);
this.updateODBC( this.updateODBC(
Conf.odbcPath, Conf.odbcPath,
Conf.dsName, Conf.dsName,
myDatasource myDatasource
); );
} };
if (hasChangeCredentials) {
var datasourcePath = this.getDatasourcePath(); var datasourcePath = this.getDatasourcePath();
var myUID = this.regRead(datasourcePath, 'UID'); var myUID = this.regRead(datasourcePath, 'UID');
var myPWD = this.regRead(datasourcePath, 'PWD'); var myPWD = this.regRead(datasourcePath, 'PWD');
if (myUID && myPWD) {
if (myUID && myPWD) { this.$('user').value = myUID;
this.$('user').value = myUID; this.$('password').value = myPWD;
this.$('password').value = myPWD; };
} };
this.$('user').focus(); this.$('user').focus();
}, },
cleanCache: function() { cleanCache: function() {
if (this.fso.folderExists(this.moduleDir)) { if (this.fso.folderExists(this.moduleDir)) {
var folder = this.fso.getFolder(this.moduleDir); var folder = this.fso.getFolder(this.moduleDir);
@ -312,7 +304,6 @@ var App = {
} }
this.showMessage(_('Cache files have been deleted'), 'notice'); this.showMessage(_('Cache files have been deleted'), 'notice');
}, },
onKeyPress: function(event) { onKeyPress: function(event) {
switch (event.keyCode) { switch (event.keyCode) {
case 13: // Enter case 13: // Enter
@ -323,7 +314,6 @@ var App = {
break; break;
} }
}, },
onEnterPress: function(event) { onEnterPress: function(event) {
var target = event.target || event.srcElement; var target = event.target || event.srcElement;
@ -334,12 +324,10 @@ var App = {
this.onEnterClick(); this.onEnterClick();
}, },
onEnterClick: function() { onEnterClick: function() {
this.disableUi(true, _('Loading')); this.disableUi(true, _('Loading'));
setTimeout(function() { App.login(); }); setTimeout(function() { App.login(); });
}, },
login: function() { login: function() {
try { try {
var user = this.$('user').value; var user = this.$('user').value;
@ -357,7 +345,7 @@ var App = {
var version = this.fetchVersion(); var version = this.fetchVersion();
// Check if there is a new version, and if there is, download it // Check if there is a new version, and if there is, download it
if (version !== null) { if (version) {
this.disableUi(true, _('Updating')); this.disableUi(true, _('Updating'));
var remoteFile = version var remoteFile = version
? '.archive/'+ this.module +'/'+ version +'.7z' ? '.archive/'+ this.module +'/'+ version +'.7z'
@ -390,7 +378,7 @@ var App = {
var serverURL = Conf.datasources[datasource].SERVER; var serverURL = Conf.datasources[datasource].SERVER;
var sslMode = Conf.datasources[datasource].SSLMODE; var sslMode = Conf.datasources[datasource].SSLMODE;
// FIXME: Can't login to dev-db // FIXME: Can't login in dev-db
if (datasource == 'dev') { if (datasource == 'dev') {
serverURL = Conf.datasources.production.SERVER serverURL = Conf.datasources.production.SERVER
sslMode = Conf.datasources.production.SERVER sslMode = Conf.datasources.production.SERVER
@ -554,7 +542,10 @@ var App = {
return; return;
try { try {
if (request.status !== 200 ) if (request.status == 401) //Unhauthorized
throw new Error('Bad login in the remoteURL "' + this.getRemoteURL() +
'":\nThe latest version could not be obtained');
else if (request.status !== 200 )
throw new Error('HTTP: '+ request.statusText + ' ' + request.status); throw new Error('HTTP: '+ request.statusText + ' ' + request.status);
this.response = JSON.parse(request.responseText) this.response = JSON.parse(request.responseText)
@ -585,7 +576,7 @@ var App = {
try { try {
if (request.status !== 200 ) if (request.status !== 200 )
throw new Error('HTTP: '+ request.statusText + ' .' + request.status + '.'); throw new Error('HTTP: '+ request.statusText + ' ' + request.status);
var response = JSON.parse(request.responseText); var response = JSON.parse(request.responseText);
this.lastVersion = response[0].version this.lastVersion = response[0].version

View File

@ -78,7 +78,7 @@
App.onShowBranchOptionsClick()" App.onShowBranchOptionsClick()"
alt="Change datasource"/> alt="Change datasource"/>
<div id="datasourceSelector"> <div id="datasourceSelector">
<select id="datasource" onchange="App.onChangeDatasource(false)"> <select id="datasource" onchange="App.onChangeDatasource(false, true)">
<option value="production">production</option> <option value="production">production</option>
<option value="test">test</option> <option value="test">test</option>
<option value="dev">dev</option> <option value="dev">dev</option>