Merge branch 'hotfix/4.8.5'

This commit is contained in:
yuri
2017-11-16 11:31:03 +02:00
7 changed files with 71 additions and 63 deletions

View File

@@ -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
);
}

View File

@@ -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();
}
}

View File

@@ -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')

View File

@@ -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));
},

View File

@@ -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;
});

View File

@@ -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 () {

View File

@@ -230,6 +230,8 @@ Espo.define('views/fields/enum', ['views/fields/base', 'lib!Selectize'], functio
};
}
});
this.$el.find('.selectize-dropdown-content').addClass('small');
}
},