From a82b3acc2b373b9e5d341c1018e1cd5d97b16daa Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 15 Nov 2017 16:12:17 +0200 Subject: [PATCH 1/2] selectize small in search mode --- client/src/views/fields/array.js | 2 ++ client/src/views/fields/enum.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/client/src/views/fields/array.js b/client/src/views/fields/array.js index 66692ca7c5..ab90094758 100644 --- a/client/src/views/fields/array.js +++ b/client/src/views/fields/array.js @@ -248,6 +248,8 @@ Espo.define('views/fields/array', ['views/fields/base', 'lib!Selectize'], functi }; } }); + + this.$el.find('.selectize-dropdown-content').addClass('small'); }, fetchFromDom: function () { diff --git a/client/src/views/fields/enum.js b/client/src/views/fields/enum.js index fd9f83eed2..0048b226c6 100644 --- a/client/src/views/fields/enum.js +++ b/client/src/views/fields/enum.js @@ -230,6 +230,8 @@ Espo.define('views/fields/enum', ['views/fields/base', 'lib!Selectize'], functio }; } }); + + this.$el.find('.selectize-dropdown-content').addClass('small'); } }, From b94f702cc0f73c9a70a286c2b67383919a8ebaec Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 16 Nov 2017 11:30:53 +0200 Subject: [PATCH 2/2] language caching and fix --- application/Espo/Controllers/App.php | 5 +- application/Espo/Controllers/I18n.php | 5 +- application/Espo/Core/Container.php | 2 +- client/src/app.js | 67 +++++++++++++-------------- client/src/language.js | 51 ++++++++++---------- 5 files changed, 67 insertions(+), 63 deletions(-) diff --git a/application/Espo/Controllers/App.php b/application/Espo/Controllers/App.php index f4baeffb6b..d1a48a9de3 100644 --- a/application/Espo/Controllers/App.php +++ b/application/Espo/Controllers/App.php @@ -68,12 +68,15 @@ class App extends \Espo\Core\Controllers\Base unset($userData['authTokenId']); unset($userData['password']); + $language = \Espo\Core\Utils\Language::detectLanguage($this->getConfig(), $this->getPreferences()); + return array( 'user' => $userData, 'acl' => $this->getAcl()->getMap(), 'preferences' => $preferences, 'token' => $this->getUser()->get('token'), - 'settings' => $settings + 'settings' => $settings, + 'language' => $language ); } diff --git a/application/Espo/Controllers/I18n.php b/application/Espo/Controllers/I18n.php index a8ab6cddc8..721f4c850e 100644 --- a/application/Espo/Controllers/I18n.php +++ b/application/Espo/Controllers/I18n.php @@ -31,8 +31,11 @@ namespace Espo\Controllers; class I18n extends \Espo\Core\Controllers\Base { - public function actionRead($params, $data) + public function actionRead($params, $data, $request) { + if ($request->get('default')) { + return $this->getContainer()->get('defaultLanguage')->getAll(); + } return $this->getContainer()->get('language')->getAll(); } } diff --git a/application/Espo/Core/Container.php b/application/Espo/Core/Container.php index c246157f3c..1b02243e2d 100644 --- a/application/Espo/Core/Container.php +++ b/application/Espo/Core/Container.php @@ -298,7 +298,7 @@ class Container protected function loadDefaultLanguage() { return new \Espo\Core\Utils\Language( - null, + \Espo\Core\Utils\Language::detectLanguage($this->get('config')), $this->get('fileManager'), $this->get('metadata'), $this->get('useCache') diff --git a/client/src/app.js b/client/src/app.js index 8d0e0145f7..b0fd448229 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -98,7 +98,7 @@ Espo.define( new Promise(function (resolve) { this.language.load(function () { resolve(); - }); + }, false, true); }.bind(this)) ]).then(function () { this.loader.addLibsConfig(this.settings.get('jsLibs') || {}); @@ -448,7 +448,6 @@ Espo.define( this.acl.clear(); this.storage.clear('user', 'auth'); this.doAction({action: 'login'}); - this.language.clearCache(); this.unsetCookieAuth(); @@ -486,48 +485,48 @@ Espo.define( options = data; resolve(); }); - - }.bind(this)), - new Promise(function (resolve) { - this.language.load(function () { - resolve(); - }.bind(this), true); }.bind(this)) ]).then(function () { - this.dateTime.setLanguage(this.language); + (new Promise(function (resolve) { + this.language.name = options.language; + this.language.load(function () { + resolve(); + }.bind(this)); + }.bind(this))).then(function () { + this.dateTime.setLanguage(this.language); - var userData = options.user || null; - var preferencesData = options.preferences || null; - var aclData = options.acl || null; + var userData = options.user || null; + var preferencesData = options.preferences || null; + var aclData = options.acl || null; - var settingData = options.settings || {}; + var settingData = options.settings || {}; - this.user.set(userData); - this.preferences.set(preferencesData); + this.user.set(userData); + this.preferences.set(preferencesData); - this.settings.set(settingData); - this.acl.set(aclData); + this.settings.set(settingData); + this.acl.set(aclData); - if (!this.auth) { - return; - } - - var xhr = new XMLHttpRequest(); - - xhr.open('GET', this.basePath + this.url + '/'); - xhr.setRequestHeader('Authorization', 'Basic ' + this.auth); - - xhr.onreadystatechange = function () { - if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { - - var arr = Base64.decode(this.auth).split(':'); - this.setCookieAuth(arr[0], arr[1]); - callback(); + if (!this.auth) { + return; } - }.bind(this); - xhr.send(''); + var xhr = new XMLHttpRequest(); + xhr.open('GET', this.basePath + this.url + '/'); + xhr.setRequestHeader('Authorization', 'Basic ' + this.auth); + + xhr.onreadystatechange = function () { + if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { + + var arr = Base64.decode(this.auth).split(':'); + this.setCookieAuth(arr[0], arr[1]); + callback(); + } + }.bind(this); + + xhr.send(''); + }.bind(this)); }.bind(this)); }, diff --git a/client/src/language.js b/client/src/language.js index 539d717756..567cc1aca0 100644 --- a/client/src/language.js +++ b/client/src/language.js @@ -26,11 +26,12 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('language', [], function () { +Espo.define('language', ['ajax'], function (Ajax) { var Language = function (cache) { this.cache = cache || null; this.data = {}; + this.name = 'default'; }; _.extend(Language.prototype, { @@ -83,10 +84,13 @@ Espo.define('language', [], function () { return translation[value] || value; }, - loadFromCache: function () { - + loadFromCache: function (loadDefault) { + var name = this.name; + if (loadDefault) { + name = 'default'; + } if (this.cache) { - var cached = this.cache.get('app', 'language'); + var cached = this.cache.get('app', 'language-' + name); if (cached) { this.data = cached; return true; @@ -97,44 +101,41 @@ Espo.define('language', [], function () { clearCache: function () { if (this.cache) { - this.cache.clear('app', 'language'); + this.cache.clear('app', 'language-' + this.name); } }, - storeToCache: function () { + storeToCache: function (loadDefault) { + var name = this.name; + if (loadDefault) { + name = 'default'; + } if (this.cache) { - this.cache.set('app', 'language', this.data); + this.cache.set('app', 'language-' + name, this.data); } }, - load: function (callback, disableCache) { + load: function (callback, disableCache, loadDefault) { this.once('sync', callback); if (!disableCache) { - if (this.loadFromCache()) { + if (this.loadFromCache(loadDefault)) { this.trigger('sync'); return; } } - this.fetch(false, disableCache); + this.fetch(disableCache, loadDefault); }, - fetch: function (sync, disableCache) { - var self = this; - $.ajax({ - url: this.url, - type: 'GET', - dataType: 'JSON', - async: !(sync || false), - success: function (data) { - self.data = data; - if (!disableCache) { - self.storeToCache(); - } - self.trigger('sync'); + fetch: function (disableCache, loadDefault) { + Ajax.getRequest(this.url, {default: loadDefault}).then(function (data) { + this.data = data; + if (!disableCache) { + this.storeToCache(loadDefault); } - }); + this.trigger('sync'); + }.bind(this)); }, sortFieldList: function (scope, fieldList) { @@ -158,5 +159,3 @@ Espo.define('language', [], function () { return Language; }); - -