diff --git a/client/src/controllers/base.js b/client/src/controllers/base.js index d9eb314237..1fc1ad1c0c 100644 --- a/client/src/controllers/base.js +++ b/client/src/controllers/base.js @@ -33,34 +33,35 @@ define('controllers/base', 'controller', function (Dep) { login: function () { var viewName = this.getConfig().get('loginView') || 'views/login'; - this.entire(viewName, {}, function (loginView) { + this.entire(viewName, {}, loginView => { loginView.render(); - loginView.on('login', function (userName, data) { + loginView.on('login', (userName, data) => { this.trigger('login', this.normalizeLoginData(userName, data)); - }, this); + }); - loginView.once('redirect', function (viewName, userName, password, data) { + loginView.once('redirect', (viewName, userName, password, data) => { loginView.remove(); + this.entire(viewName, { loginData: data, userName: userName, password: password, - }, function (secondStepView) { + }, secondStepView => { secondStepView.render(); - secondStepView.once('login', function (userName, data) { + secondStepView.once('login', (userName, data) => { this.trigger('login', this.normalizeLoginData(userName, data)); - }, this); + }); - secondStepView.once('back', function () { + secondStepView.once('back', () => { secondStepView.remove(); this.login(); - }, this); - }.bind(this)); - }, this); - }.bind(this)); + }); + }); + }); + }); }, normalizeLoginData: function (userName, data) { @@ -84,6 +85,7 @@ define('controllers/base', 'controller', function (Dep) { logout: function () { var title = this.getConfig().get('applicationName') || 'EspoCRM'; $('head title').text(title); + this.trigger('logout'); }, @@ -98,22 +100,21 @@ define('controllers/base', 'controller', function (Dep) { clearCache: function () { this.entire('views/clear-cache', { cache: this.getCache() - }, function (view) { + }, (view) => { view.render(); }); }, error404: function () { - this.entire('views/base', {template: 'errors/404'}, function (view) { + this.entire('views/base', {template: 'errors/404'}, (view) => { view.render(); }); }, error403: function () { - this.entire('views/base', {template: 'errors/403'}, function (view) { + this.entire('views/base', {template: 'errors/403'}, (view) => { view.render(); }); }, - }); }); diff --git a/client/src/views/login-second-step.js b/client/src/views/login-second-step.js index aeea931436..ab70efe814 100644 --- a/client/src/views/login-second-step.js +++ b/client/src/views/login-second-step.js @@ -42,6 +42,7 @@ define('views/login-second-step', 'view', function (Dep) { events: { 'submit #login-form': function (e) { this.send(); + return; }, 'click [data-action="backToLogin"]': function () { @@ -60,7 +61,10 @@ define('views/login-second-step', 'view', function (Dep) { }, send: function () { - var code = $('[data-name="field-code"]').val().trim().replace(/\s/g, ''); + var code = $('[data-name="field-code"]') + .val() + .trim() + .replace(/\s/g, ''); var userName = this.options.userName; var password = this.options.loginData.token || this.options.password; @@ -68,8 +72,8 @@ define('views/login-second-step', 'view', function (Dep) { var $submit = this.$el.find('#btn-send'); if (code == '') { - this.isPopoverDestroyed = false; + var $el = $("#field-code"); var message = this.getLanguage().translate('codeIsRequired', 'messages', 'User'); @@ -82,13 +86,20 @@ define('views/login-second-step', 'view', function (Dep) { }).popover('show'); var $cell = $el.closest('.form-group'); + $cell.addClass('has-error'); - $el.one('mousedown click', function () { + + $el.one('mousedown click', () => { $cell.removeClass('has-error'); - if (this.isPopoverDestroyed) return; + + if (this.isPopoverDestroyed) { + return; + } + $el.popover('destroy'); + this.isPopoverDestroyed = true; - }.bind(this)); + }); return; } @@ -97,38 +108,38 @@ define('views/login-second-step', 'view', function (Dep) { Espo.Ui.notify(this.translate('pleaseWait', 'messages')); - Espo.Ajax.getRequest('App/user', {code: code}, { - login: true, - headers: { - 'Authorization': 'Basic ' + base64.encode(userName + ':' + password), - 'Espo-Authorization': base64.encode(userName + ':' + password), - 'Espo-Authorization-Code': code, - 'Espo-Authorization-Create-Token-Secret': true, - }, - }).then( - function (data) { + Espo.Ajax + .getRequest('App/user', {code: code}, { + login: true, + headers: { + 'Authorization': 'Basic ' + base64.encode(userName + ':' + password), + 'Espo-Authorization': base64.encode(userName + ':' + password), + 'Espo-Authorization-Code': code, + 'Espo-Authorization-Create-Token-Secret': true, + }, + }) + .then(data => { this.notify(false); this.trigger('login', userName, data); - }.bind(this) - ).fail( - function (xhr) { + }) + .catch(xhr => { $submit.removeClass('disabled').removeAttr('disabled'); - if (xhr.status == 401) { + if (xhr.status === 401) { this.onWrongCredentials(); } - }.bind(this) - ); + }); }, onWrongCredentials: function () { var cell = $('#login .form-group'); cell.addClass('has-error'); - this.$el.one('mousedown click', function () { + + this.$el.one('mousedown click', () => { cell.removeClass('has-error'); }); + Espo.Ui.error(this.translate('wrongCode', 'messages', 'User')); }, - }); }); diff --git a/client/src/views/login.js b/client/src/views/login.js index f53b6cd7f8..608c5ba528 100644 --- a/client/src/views/login.js +++ b/client/src/views/login.js @@ -45,7 +45,7 @@ define('views/login', 'view', function (Dep) { return false; }, - 'click a[data-action="passwordChangeRequest"]': function (e) { + 'click a[data-action="passwordChangeRequest"]': function () { this.showPasswordChangeRequest(); } }, @@ -99,7 +99,7 @@ define('views/login', 'view', function (Dep) { $cell.addClass('has-error'); - $el.one('mousedown click', function () { + $el.one('mousedown click', () => { $cell.removeClass('has-error'); if (this.isPopoverDestroyed) { @@ -109,7 +109,7 @@ define('views/login', 'view', function (Dep) { $el.popover('destroy'); this.isPopoverDestroyed = true; - }.bind(this)); + }); return; } @@ -118,25 +118,25 @@ define('views/login', 'view', function (Dep) { Espo.Ui.notify(this.translate('pleaseWait', 'messages')); - Espo.Ajax.getRequest('App/user', null, { - login: true, - headers: { - 'Authorization': 'Basic ' + base64.encode(userName + ':' + password), - 'Espo-Authorization': base64.encode(userName + ':' + password), - 'Espo-Authorization-By-Token': false, - 'Espo-Authorization-Create-Token-Secret': true, - }, - }).then( - function (data) { + Espo.Ajax + .getRequest('App/user', null, { + login: true, + headers: { + 'Authorization': 'Basic ' + base64.encode(userName + ':' + password), + 'Espo-Authorization': base64.encode(userName + ':' + password), + 'Espo-Authorization-By-Token': false, + 'Espo-Authorization-Create-Token-Secret': true, + }, + }) + .then(data => { this.notify(false); this.trigger('login', userName, data); - }.bind(this) - ).fail( - function (xhr) { + }) + .catch(xhr => { $submit.removeClass('disabled').removeAttr('disabled'); - if (xhr.status == 401) { + if (xhr.status === 401) { var data = xhr.responseJSON || {}; var statusReason = xhr.getResponseHeader('X-Status-Reason'); @@ -151,8 +151,7 @@ define('views/login', 'view', function (Dep) { this.onWrongCredentials(); } - }.bind(this) - ); + }); }, onSecondStepRequired: function (userName, password, data) { @@ -166,7 +165,7 @@ define('views/login', 'view', function (Dep) { cell.addClass('has-error'); - this.$el.one('mousedown click', function () { + this.$el.one('mousedown click', () => { cell.removeClass('has-error'); }); @@ -178,7 +177,7 @@ define('views/login', 'view', function (Dep) { this.createView('passwordChangeRequest', 'views/modals/password-change-request', { url: window.location.href, - }, function (view) { + }, (view) => { view.render(); Espo.Ui.notify(false);