diff --git a/src/main.js b/src/main.js index 946a70d..7d3e31d 100755 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,3 @@ -// Check when version 6 is uploaded -// Only in case all host have version 5 -// Delete code with comment REMOVE! - var Conf = { appName: 'Verdnatura', odbcPath: 'HKCU\\SOFTWARE\\ODBC\\ODBC.INI\\', @@ -9,7 +5,7 @@ var Conf = { defaultModule: 'vn', defaultLocale: 'es', defaultBranch: 'master', - defaultDatasource: 'production', + defaultDatasource: 'verdnatura', defaultRemoteURL: 'https://salix.verdnatura.es', defaultServer: 'db.verdnatura.es', dbName: 'vn2008', @@ -18,7 +14,8 @@ var Conf = { driverPath: '\\MySQL\\Connector ODBC 8.0\\myodbc8w.dll', version: 5, cdnURL: 'https://cdn.verdnatura.es/vn-access', - identifier: '.vn' + identifier: '.vn', + productionDatasource: 'production.vn' }; var Locale = { @@ -76,12 +73,11 @@ var App = { this.certFile = this.appDir +'\\cacert.pem'; this.lockFile = this.moduleDir +'\\' + this.module +'.ldb'; this.mdbFile = this.moduleDir +'\\' + this.module +'.mdb'; - var defaultDsName = this.formatDatasource(Conf.defaultDatasource); var mdbDsName = this.mdbGetValue( 'SELECT dsName FROM TblConfig', 'dsName', String ); - this.dsName = mdbDsName || defaultDsName; + this.dsName = mdbDsName || Conf.defaultDatasource; // Creates the necessary registry entries var lastVersion = this.regRead(Conf.regPath, 'lastExecutedVersion'); @@ -99,21 +95,21 @@ var App = { // Creates the MySQL ODBC connection this.createODBC(Conf.odbcPath, - defaultDsName, + Conf.defaultDatasource, Conf.odbcDriver, - Conf.defaultDatasource + 'keep for backward compatibility' ); this.regWrite(Conf.regPath, 'remoteURL', Conf.defaultRemoteURL); this.regWrite(Conf.regPath, 'lastExecutedVersion', Conf.version); - // REMOVE! + this.createODBC(Conf.odbcPath, - 'verdnatura', + Conf.productionDatasource, Conf.odbcDriver, - 'keep for backward compatibility' + Conf.productionDatasource ); - // ----- + this.regDelete(Conf.regPath +'\\configured'); this.regDelete(Conf.regPath + '\\remember'); } @@ -146,9 +142,9 @@ var App = { var selectDatarouce = document.querySelector('#datasource'); var option = []; var allOdbc = this.enumValues(Conf.odbcPath +'ODBC Data Sources\\'); - var idLen = Conf.identifier.length; for (var y in allOdbc) { - if (allOdbc[y].slice(-idLen) == Conf.identifier) { + var odbcName = allOdbc[y]; + if (this.isDs(odbcName) || odbcName == 'verdnatura') { var odbcName = allOdbc[y]; option[y] = document.createElement('option'); option[y].text = this.getDatasource(odbcName); @@ -156,13 +152,7 @@ var App = { selectDatarouce.options.add(option[y]) } } - // REMOVE! - if (this.dsName == 'verdnatura') { - this.dsName = Conf.defaultDatasource; - this.$('datasource').value = this.dsName + Conf.identifier; - this.$('datasource').text = this.dsName; - } else // ----- - this.$('datasource').value = this.dsName; + this.$('datasource').value = this.dsName; if (notSignOut && password) { this.$('notSignOut').checked = true; @@ -173,11 +163,13 @@ var App = { this.onChangeDatasource(true); } }, - formatDatasource: function(datasource) { - return datasource + Conf.identifier; + isDs: function(dsName) { + return /\.vn$/.test(dsName); }, getDatasource: function(dsName) { - return dsName.substr(0, dsName.length - Conf.identifier.length); + return this.isDs(dsName) + ? dsName.substr(0, dsName.length - Conf.identifier.length) + : dsName; }, resetForm: function(clearPassword) { if (clearPassword) @@ -239,30 +231,30 @@ var App = { setTimeout(function() { App.cleanCache(); }); }, onShowBranchOptionsClick: function() { - var style = this.$("branchSelector").style; + var style = this.$('branchSelector').style; style.display = style.display == 'none' || !style.display ? 'inline' : 'none'; }, onShowDatasourceOptionsClick: function() { - var style = this.$("datasourceSelector").style; + var style = this.$('datasourceSelector').style; style.display = style.display == 'none' || !style.display ? 'inline' : 'none'; - if (!this.$("datasourceLogo").className) - this.$("datasourceLogo").className = "on"; + if (!this.$('datasourceLogo').className) + this.$('datasourceLogo').className = 'on'; else - this.$("datasourceLogo").className = ""; + this.$('datasourceLogo').className = ''; }, onChangeBranch: function() { - if (this.$("branch").value == "master"||"test"||"dev") { - this.$("branchButton").className = this.$("branch").value; - this.$("branch").className = this.$("branch").value; + if (this.$('branch').value == 'master'||'test'||'dev') { + this.$('branchButton').className = this.$('branch').value; + this.$('branch').className = this.$('branch').value; } else { - this.$("branchButton").className = null; - this.$("branch").className = null; + this.$('branchButton').className = null; + this.$('branch').className = null; } this.$('user').focus(); }, @@ -272,15 +264,18 @@ var App = { * @param {Boolean} hasUpdate */ onChangeDatasource: function(hasUpdate) { - this.dsName = this.$("datasource").value; + this.dsName = this.$('datasource').value; var myDatasource = this.getDatasource(this.dsName); - if (myDatasource == "production"||"test"||"dev") { - this.$("datasourceButton").className = myDatasource; - this.$("datasource").className = myDatasource; + if (myDatasource == 'verdnatura') + myDatasource = 'production'; + + if (myDatasource == 'production'||'test'||'dev') { + this.$('datasourceButton').className = myDatasource; + this.$('datasource').className = myDatasource; } else { - this.$("datasourceButton").className = null; - this.$("datasource").className = null; + this.$('datasourceButton').className = null; + this.$('datasource').className = null; }; if (!hasUpdate) { this.updateODBC(); @@ -710,20 +705,20 @@ var App = { }, enumValues: function(RegKey) { var RootKey = new Object() - RootKey["HKCR"] = RootKey["HKEY_CLASSES_ROOT"] = 0x80000000; - RootKey["HKCU"] = RootKey["HKEY_CURRENT_USER"] = 0x80000001; - RootKey["HKLM"] = RootKey["HKEY_LOCAL_MACHINE"] = 0x80000002; - RootKey["HKUS"] = RootKey["HKEY_USERS"] = 0x80000003; - RootKey["HKCC"] = RootKey["HKEY_CURRENT_CONFIG"] = 0x80000005; - var RootVal = RootKey[RegKey.substr(0, RegKey.indexOf("\\"))] + RootKey['HKCR'] = RootKey['HKEY_CLASSES_ROOT'] = 0x80000000; + RootKey['HKCU'] = RootKey['HKEY_CURRENT_USER'] = 0x80000001; + RootKey['HKLM'] = RootKey['HKEY_LOCAL_MACHINE'] = 0x80000002; + RootKey['HKUS'] = RootKey['HKEY_USERS'] = 0x80000003; + RootKey['HKCC'] = RootKey['HKEY_CURRENT_CONFIG'] = 0x80000005; + var RootVal = RootKey[RegKey.substr(0, RegKey.indexOf('\\'))] if (RootVal != undefined) { - Locator = new ActiveXObject("WbemScripting.SWbemLocator"); - ServerConn = Locator.ConnectServer(null, "root\\default"); - Registry = ServerConn.Get("StdRegProv"); - Method = Registry.Methods_.Item("enumValues"); + Locator = new ActiveXObject('WbemScripting.SWbemLocator'); + ServerConn = Locator.ConnectServer(null, 'root\\default'); + Registry = ServerConn.Get('StdRegProv'); + Method = Registry.Methods_.Item('enumValues'); p_In = Method.InParameters.SpawnInstance_(); p_In.hDefKey = RootVal; - p_In.sSubKeyName = RegKey.substr(RegKey.indexOf("\\") + 1) + p_In.sSubKeyName = RegKey.substr(RegKey.indexOf('\\') + 1) p_Out = Registry.ExecMethod_(Method.Name, p_In); return p_Out.sNames.toArray(); }