refs #4974 Now defaultDatasource is verdnatura

This commit is contained in:
Guillermo Bonet 2023-02-06 17:59:36 +01:00
parent 6a390d194a
commit cc79a76120
1 changed files with 48 additions and 53 deletions

View File

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