Skip to content

EspoCRM – Open Source CRM Application

ref

Yuri Kuznetsov24b5b94d6349
diff --git a/client/src/app.js b/client/src/app.js
index 60191c6533..b553a76f79 100644
--- a/client/src/app.js
+++ b/client/src/app.js
@@ -468,94 +468,95 @@ class App {
return;
}
- this.initUserData(null, () => this.onAuth.call(this));
+ this.initUserData(null, () => this.onAuth());
}
/**
* @private
* @param {boolean} [afterLogin]
*/
- onAuth(afterLogin) {
- this.metadata.load().then(() => {
- this.fieldManager.defs = this.metadata.get('fields');
- this.fieldManager.metadata = this.metadata;
-
- this.settings.defs = this.metadata.get('entityDefs.Settings') || {};
- this.user.defs = this.metadata.get('entityDefs.User');
- this.preferences.defs = this.metadata.get('entityDefs.Preferences');
- this.viewHelper.layoutManager.setUserId(this.user.id);
-
- if (this.themeManager.isUserTheme()) {
- this.loadStylesheet();
- }
+ async onAuth(afterLogin = false) {
+ await this.metadata.load();
- this.applyUserStyle();
+ this.fieldManager.defs = this.metadata.get('fields') || {};
+ this.fieldManager.metadata = this.metadata;
- if (this.anotherUser) {
- this.viewHelper.webSocketManager = null;
- this.webSocketManager = null;
- }
+ this.settings.setDefs(this.metadata.get('entityDefs.Settings') || {});
+ this.preferences.setDefs(this.metadata.get('entityDefs.Preferences') || {});
- if (this.webSocketManager) {
- this.webSocketManager.connect(this.auth, this.user.id);
- }
+ this.viewHelper.layoutManager.setUserId(this.user.id);
- const promiseList = [];
- const aclImplementationClassMap = {};
+ if (this.themeManager.isUserTheme()) {
+ this.loadStylesheet();
+ }
- const clientDefs = this.metadata.get('clientDefs') || {};
+ this.applyUserStyle();
- Object.keys(clientDefs).forEach(scope => {
- const o = clientDefs[scope];
+ if (this.anotherUser) {
+ this.viewHelper.webSocketManager = null;
+ this.webSocketManager = null;
+ }
- const implClassName = (o || {})[this.aclName];
+ if (this.webSocketManager) {
+ this.webSocketManager.connect(this.auth, this.user.id);
+ }
- if (!implClassName) {
- return;
- }
+ const promiseList = [];
+ const aclImplementationClassMap = {};
- promiseList.push(
- new Promise(resolve => {
- this.loader.require(implClassName, implClass => {
- aclImplementationClassMap[scope] = implClass;
+ const clientDefs = this.metadata.get('clientDefs') || {};
- resolve();
- });
- })
- );
+ Object.keys(clientDefs).forEach(scope => {
+ const o = clientDefs[scope];
+
+ const implClassName = (o || {})[this.aclName];
+
+ if (!implClassName) {
+ return;
+ }
+
+ const promise = new Promise(resolve => {
+ this.loader.require(implClassName, Class => {
+ aclImplementationClassMap[scope] = Class;
+
+ resolve();
+ });
});
- if (!this.themeManager.isApplied() && this.themeManager.isUserTheme()) {
- promiseList.push(
- new Promise(resolve => {
- const check = i => {
- if (this.themeManager.isApplied() || i === 50) {
- resolve();
+ promiseList.push(promise);
+ });
- return;
- }
+ if (!this.themeManager.isApplied() && this.themeManager.isUserTheme()) {
+ const promise = new Promise(resolve => {
+ const check = i => {
+ if (this.themeManager.isApplied() || i === 50) {
+ resolve();
- i = i || 0;
+ return;
+ }
- setTimeout(() => check(i + 1), 10);
- }
+ i = i || 0;
- check();
- })
- );
- }
+ setTimeout(() => check(i + 1), 10);
+ }
- Promise.all(promiseList)
- .then(() => {
- this.acl.implementationClassMap = aclImplementationClassMap;
+ check();
+ });
- this.initRouter();
- });
+ promiseList.push(promise);
+ }
- if (afterLogin) {
- this.broadcastChannel.postMessage('logged-in');
- }
- });
+ const promise = Promise.all(promiseList);
+
+ if (afterLogin) {
+ this.broadcastChannel.postMessage('logged-in');
+ }
+
+ await promise;
+
+ this.acl.implementationClassMap = aclImplementationClassMap;
+
+ this.initRouter();
}
/**