diff --git a/src/main.js b/src/main.js index 33e2e52..7552946 100755 --- a/src/main.js +++ b/src/main.js @@ -1,13 +1,33 @@ var Conf = { - appName: 'Verdnatura', - dsName: 'verdnatura', - dsPath: 'HKCU\\Software\\ODBC\\ODBC.INI\\verdnatura', - regPath: 'HKCU\\Software\\Verdnatura\\vn-access', - remoteUrl: 'https://www.verdnatura.es/vn-access', - dbHost: 'db.verdnatura.es', - defaultModule: 'tpv' + appName: 'Verdnatura' + ,dsName: 'verdnatura' + ,dsPath: 'HKCU\\Software\\ODBC\\ODBC.INI\\verdnatura' + ,regPath: 'HKCU\\Software\\Verdnatura\\vn-access' + ,remoteUrl: 'https://verdnatura.es/vn-access' + ,dbHost: 'db.verdnatura.es' + ,defaultModule: 'tpv' + ,defaultLocale: 'es' +}; + +var Locale ={ + es: { + "Enter a user name": + "Introduce un nombre de usuario" + ,"Enter a password": + "Introduce una contraseña" + ,"Server can't be reached": + "No se ha podido conectar con el servidor" + ,"Updating": + "Actualizando" + ,"Bad login": + "Usuario o contraseña incorrectos" + ,"Loading": + "Cargando" + ,"Error while updating": + "Error al actualizar" + } }; var App = @@ -191,7 +211,7 @@ var App = _onEnterClick: function () { - this._disableUi (true, 'Cargando'); + this._disableUi (true, _('Loading')); setTimeout (function () {App.login();}, 0); }, @@ -202,9 +222,9 @@ var App = try { if (!user || user === '') - throw new Error ('Introduce un nombre de usuario'); + throw new Error (_('Enter a user name')); if (!password || password === '') - throw new Error ('Introduce una contraseña'); + throw new Error (_('Enter a password')); this.regWrite (Conf.dsPath, 'UID', user, 'REG_SZ'); this.regWrite (Conf.dsPath, 'PWD', password, 'REG_SZ'); @@ -225,17 +245,14 @@ var App = { var errorMsg; var dbError = dbErrors.item(0); - alert (dbError.description ); switch (dbError.NativeError) { case 1045: // Access denied - errorMsg = 'Usuario o contraseña incorrectos'; + errorMsg = _('Bad login'); break; case 2003: // Can't connect - errorMsg = 'No se ha podido conectar con el ' - +'servidor, comprueba que tienes conexión a ' - +'Internet y que el servidor está accesible'; + errorMsg = _('Server can\'t be reached'); break; default: errorMsg = dbError.description; @@ -277,7 +294,7 @@ var App = if (localVersion < lastVersion) { - this._disableUi (true, 'Actualizando'); + this._disableUi (true, _('Updating')); var request = new ActiveXObject ('MSXML2.XMLHTTP'); request.open ('GET', this.remoteFile +'?'+ new Date().getTime(), true); request.onreadystatechange = function () { @@ -325,7 +342,7 @@ var App = } catch (e) { - alert ('Error al actualizar: '+ e.message); + alert (_('Error while updating') +': '+ e.message); } this._disableUi (false); @@ -338,9 +355,7 @@ var App = { var remember = this.$('remember').checked ? 1 : 0; this.regWrite (Conf.regPath, 'remember', remember, 'REG_DWORD'); - - this.shell.exec ('"%ProgramFiles%\\Microsoft Office\\OFFICE11\\MSACCESS.EXE" "'+ - this.mdbFile +'" /cmd "'+ this.$('user').value +'"'); + this.shell.run (this.mdbFile, 0, false); window.close (); }, @@ -418,3 +433,9 @@ var App = }; App.init (); + +function _(string) +{ + var translation = Locale[Conf.defaultLocale][string]; + return translation ? translation : string; +}