From e2412e03e78900f1c740eadfe434d78a212f1a1e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 4 Jan 2023 08:17:28 +0100 Subject: [PATCH] refs #4974 Now the session is kept open with the ODBC credentials, and minor changes --- src/main.js | 81 +++++++++++++++++++++-------------------------- src/vn-access.hta | 2 +- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/main.js b/src/main.js index 3acdce0..769ee32 100755 --- a/src/main.js +++ b/src/main.js @@ -80,11 +80,9 @@ var App = { window.resizeTo(width, height); window.moveTo((screen.width - width) / 2, (screen.height - height) / 2); }, - onUnload: function() { this.disableUi(false); }, - onLoad: function() { // Initializes the global variables var split = Verdnatura.commandLine.match(/(?:[^\s"]+|"[^"]*")+/g); @@ -151,22 +149,23 @@ var App = { this.$('user').value = this.regRead(Conf.odbcPath + Conf.dsName, 'UID'); this.$('password').value = password - if (notSignOut && password) { - this.$('password').value = password; - this.$('notSignOut').checked = true; - this.onEnterClick(); - } else - this.resetForm(true); - // Branch options this.$('branch').value = this.getBranch(); this.onChangeBranch(); // Datasource options 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) { if (clearPassword) this.$('password').value = ''; @@ -174,15 +173,12 @@ var App = { this.$('user').focus(); this.$('user').select(); }, - createODBC: function(path, dsName, driverName) { var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath; var datasource = Conf.defaultDatasource; var serverURL, sslMode; - serverURL = Conf.datasources[datasource].SERVER sslMode = Conf.datasources[datasource].SSLMODE - var params = { Driver: driverPath, DESCRIPTION: Conf.appName, @@ -199,10 +195,8 @@ var App = { this.regWrite(path + 'ODBC Data Sources', dsName, driverName); this.regWrites(path + dsName, params); }, - updateODBC: function(path, dsName, datasource) { var params = Conf.datasources[datasource] - var datasourcePath = this.getDatasourcePath(); var myUID = this.regRead(datasourcePath, 'UID'); var myPWD = this.regRead(datasourcePath, 'PWD'); @@ -211,10 +205,8 @@ var App = { params['UID'] = myUID; params['PWD'] = myPWD; } - this.regWrites(path + dsName, params); }, - disableUi: function(disabled, loadMessage) { if (disabled) this.hideMessage(); @@ -232,18 +224,15 @@ var App = { this.$('background').style.display = display; this.$('spinner').style.display = display; }, - onCleanCacheClick: function() { setTimeout(function() { App.cleanCache(); }); }, - onShowBranchOptionsClick: function() { var style = this.$("branchSelector").style; style.display = style.display == 'none' || !style.display ? 'inline' : 'none'; }, - onShowDatasourceOptionsClick: function() { var style = this.$("datasourceSelector").style; style.display = style.display == 'none' || !style.display @@ -256,7 +245,6 @@ var App = { this.$("datasourceLogo").className = ""; }, - onChangeBranch: function() { if (this.$("branch").value == "master"||"test"||"dev") { this.$("branchButton").className = this.$("branch").value; @@ -267,8 +255,13 @@ var App = { } 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; if (myDatasource == "production"||"test"||"dev") { this.$("datasourceButton").className = myDatasource; @@ -276,27 +269,26 @@ var App = { } else { this.$("datasourceButton").className = null; this.$("datasource").className = null; - } - if (!isOnLoad) { + }; + if (!hasUpdate) { this.updateDatasource(myDatasource); this.updateODBC( Conf.odbcPath, Conf.dsName, myDatasource ); - } - - var datasourcePath = this.getDatasourcePath(); - var myUID = this.regRead(datasourcePath, 'UID'); - var myPWD = this.regRead(datasourcePath, 'PWD'); - - if (myUID && myPWD) { - this.$('user').value = myUID; - this.$('password').value = myPWD; - } + }; + if (hasChangeCredentials) { + var datasourcePath = this.getDatasourcePath(); + var myUID = this.regRead(datasourcePath, 'UID'); + var myPWD = this.regRead(datasourcePath, 'PWD'); + if (myUID && myPWD) { + this.$('user').value = myUID; + this.$('password').value = myPWD; + }; + }; this.$('user').focus(); }, - cleanCache: function() { if (this.fso.folderExists(this.moduleDir)) { var folder = this.fso.getFolder(this.moduleDir); @@ -312,7 +304,6 @@ var App = { } this.showMessage(_('Cache files have been deleted'), 'notice'); }, - onKeyPress: function(event) { switch (event.keyCode) { case 13: // Enter @@ -323,7 +314,6 @@ var App = { break; } }, - onEnterPress: function(event) { var target = event.target || event.srcElement; @@ -334,12 +324,10 @@ var App = { this.onEnterClick(); }, - onEnterClick: function() { this.disableUi(true, _('Loading')); setTimeout(function() { App.login(); }); }, - login: function() { try { var user = this.$('user').value; @@ -357,7 +345,7 @@ var App = { var version = this.fetchVersion(); // Check if there is a new version, and if there is, download it - if (version !== null) { + if (version) { this.disableUi(true, _('Updating')); var remoteFile = version ? '.archive/'+ this.module +'/'+ version +'.7z' @@ -390,7 +378,7 @@ var App = { var serverURL = Conf.datasources[datasource].SERVER; var sslMode = Conf.datasources[datasource].SSLMODE; - // FIXME: Can't login to dev-db + // FIXME: Can't login in dev-db if (datasource == 'dev') { serverURL = Conf.datasources.production.SERVER sslMode = Conf.datasources.production.SERVER @@ -554,7 +542,10 @@ var App = { return; 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); this.response = JSON.parse(request.responseText) @@ -585,7 +576,7 @@ var App = { try { 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); this.lastVersion = response[0].version diff --git a/src/vn-access.hta b/src/vn-access.hta index 0d3f8a3..782b6ce 100755 --- a/src/vn-access.hta +++ b/src/vn-access.hta @@ -78,7 +78,7 @@ App.onShowBranchOptionsClick()" alt="Change datasource"/>
-