From b5125d2d549a6155f5ecb6dc48d3c2e1b89bf75b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 15 Sep 2024 19:06:27 +0300 Subject: [PATCH] ref --- .../src/views/admin/auth-log-record/list.js | 35 +++--- .../admin/auth-log-record/modals/detail.js | 12 +- .../auth-log-record/record/detail-small.js | 15 +-- .../admin/auth-log-record/record/detail.js | 11 +- .../admin/auth-log-record/record/list.js | 15 ++- client/src/views/admin/auth-token/list.js | 31 +++-- .../views/admin/auth-token/modals/detail.js | 12 +- .../admin/auth-token/record/detail-small.js | 14 +-- .../views/admin/auth-token/record/detail.js | 12 +- .../src/views/admin/auth-token/record/list.js | 116 +++++++++--------- .../auth-token/record/row-actions/default.js | 67 +++++----- .../authentication/fields/test-connection.js | 112 ++++++++--------- 12 files changed, 213 insertions(+), 239 deletions(-) diff --git a/client/src/views/admin/auth-log-record/list.js b/client/src/views/admin/auth-log-record/list.js index f9a11c69b3..e9bc209463 100644 --- a/client/src/views/admin/auth-log-record/list.js +++ b/client/src/views/admin/auth-log-record/list.js @@ -26,26 +26,21 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-log-record/list', ['views/list'], function (Dep) { +import ListView from 'views/list'; - return Dep.extend({ +export default class extends ListView { - setup: function () { - Dep.prototype.setup.call(this); - }, + getHeader() { + return this.buildHeaderHtml([ + $('') + .attr('href', '#Admin') + .text(this.translate('Administration')), + $('') + .text(this.getLanguage().translate('Auth Log', 'labels', 'Admin')), + ]); + } - getHeader: function () { - return this.buildHeaderHtml([ - $('') - .attr('href', '#Admin') - .text(this.translate('Administration')), - $('') - .text(this.getLanguage().translate('Auth Log', 'labels', 'Admin')), - ]); - }, - - updatePageTitle: function () { - this.setPageTitle(this.getLanguage().translate('Auth Log', 'labels', 'Admin')); - }, - }); -}); + updatePageTitle() { + this.setPageTitle(this.getLanguage().translate('Auth Log', 'labels', 'Admin')); + } +} diff --git a/client/src/views/admin/auth-log-record/modals/detail.js b/client/src/views/admin/auth-log-record/modals/detail.js index 2ca724da88..002584baff 100644 --- a/client/src/views/admin/auth-log-record/modals/detail.js +++ b/client/src/views/admin/auth-log-record/modals/detail.js @@ -26,12 +26,10 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-log-record/modals/detail', ['views/modals/detail'], function (Dep) { +import DetailModalView from 'views/modals/detail'; - return Dep.extend({ +export default class extends DetailModalView { - sideDisabled: true, - - editDisabled: true, - }); -}); + sideDisabled = true + editDisabled = true +} diff --git a/client/src/views/admin/auth-log-record/record/detail-small.js b/client/src/views/admin/auth-log-record/record/detail-small.js index f94ad35738..1ffec424c2 100644 --- a/client/src/views/admin/auth-log-record/record/detail-small.js +++ b/client/src/views/admin/auth-log-record/record/detail-small.js @@ -26,14 +26,11 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-log-record/record/detail-small', ['views/record/detail-small'], function (Dep) { +import DetailSmallRecordView from 'views/record/detail-small'; - return Dep.extend({ +export default class extends DetailSmallRecordView { - sideDisabled: true, - - isWide: true, - - bottomView: 'views/record/detail-bottom', - }); -}); + sideDisabled = true + isWide = true + bottomView = 'views/record/detail-bottom' +} diff --git a/client/src/views/admin/auth-log-record/record/detail.js b/client/src/views/admin/auth-log-record/record/detail.js index 0ca616265d..39f27e6887 100644 --- a/client/src/views/admin/auth-log-record/record/detail.js +++ b/client/src/views/admin/auth-log-record/record/detail.js @@ -26,12 +26,11 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-log-record/record/detail', ['views/record/detail'], function (Dep) { +import DetailRecordView from 'views/record/detail'; - return Dep.extend({ +export default class extends DetailRecordView { - sideDisabled: true, + sideDisabled = true + readOnly = true +} - readOnly: true, - }); -}); diff --git a/client/src/views/admin/auth-log-record/record/list.js b/client/src/views/admin/auth-log-record/record/list.js index 86c026abc4..c5744085a5 100644 --- a/client/src/views/admin/auth-log-record/record/list.js +++ b/client/src/views/admin/auth-log-record/record/list.js @@ -26,14 +26,13 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-log-record/record/list', ['views/record/list'], function (Dep) { +import ListRecordView from 'views/record/list'; - return Dep.extend({ +export default class extends ListRecordView { - rowActionsView: 'views/record/row-actions/view-and-remove', + rowActionsView = 'views/record/row-actions/view-and-remove' - massActionList: ['remove'], - checkAllResultMassActionList: ['remove'], - forceSettings: true, - }); -}); + massActionList = ['remove'] + checkAllResultMassActionList = ['remove'] + forceSettings = true +} diff --git a/client/src/views/admin/auth-token/list.js b/client/src/views/admin/auth-token/list.js index 46355e30c6..1e1c89d421 100644 --- a/client/src/views/admin/auth-token/list.js +++ b/client/src/views/admin/auth-token/list.js @@ -26,25 +26,24 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/list', ['views/list'], function (Dep) { +import ListView from 'views/list'; - return Dep.extend({ +export default class extends ListView { - setup: function () { - Dep.prototype.setup.call(this); + createButton = false - this.menu.buttons = []; - }, + getHeader() { + const a = document.createElement('a'); + a.href = '#Admin'; + a.innerText = this.translate('Administration'); - getHeader: function () { - return '' + this.translate('Administration') + '' + - ' ' + - this.getLanguage().translate('Auth Tokens', 'labels', 'Admin'); - }, + const text = document.createElement('span'); + text.innerText = this.getLanguage().translate('Auth Tokens', 'labels', 'Admin'); - updatePageTitle: function () { - this.setPageTitle(this.getLanguage().translate('Auth Tokens', 'labels', 'Admin')); - }, - }); -}); + return this.buildHeaderHtml([a, text]); + } + updatePageTitle() { + this.setPageTitle(this.getLanguage().translate('Auth Tokens', 'labels', 'Admin')); + } +} diff --git a/client/src/views/admin/auth-token/modals/detail.js b/client/src/views/admin/auth-token/modals/detail.js index 54a8784f78..002584baff 100644 --- a/client/src/views/admin/auth-token/modals/detail.js +++ b/client/src/views/admin/auth-token/modals/detail.js @@ -26,12 +26,10 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/modals/detail', ['views/modals/detail'], function (Dep) { +import DetailModalView from 'views/modals/detail'; - return Dep.extend({ +export default class extends DetailModalView { - sideDisabled: true, - - editDisabled: true, - }); -}); + sideDisabled = true + editDisabled = true +} diff --git a/client/src/views/admin/auth-token/record/detail-small.js b/client/src/views/admin/auth-token/record/detail-small.js index 5ccbef21b2..2f820fa860 100644 --- a/client/src/views/admin/auth-token/record/detail-small.js +++ b/client/src/views/admin/auth-token/record/detail-small.js @@ -26,14 +26,12 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/record/detail-small', ['views/record/detail-small'], function (Dep) { +import DetailSmallRecordView from 'views/record/detail-small'; - return Dep.extend({ +export default class extends DetailSmallRecordView { - sideDisabled: true, + sideDisabled = true + isWide = true + bottomView = 'views/record/detail-bottom' +} - isWide: true, - - bottomView: 'views/record/detail-bottom', - }); -}); diff --git a/client/src/views/admin/auth-token/record/detail.js b/client/src/views/admin/auth-token/record/detail.js index 9f89f45ce2..8d29fbd190 100644 --- a/client/src/views/admin/auth-token/record/detail.js +++ b/client/src/views/admin/auth-token/record/detail.js @@ -26,12 +26,10 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/record/detail', ['views/record/detail'], function (Dep) { +import DetailRecordView from 'views/record/detail'; - return Dep.extend({ +export default class extends DetailRecordView { - sideDisabled: true, - - readOnly: true, - }); -}); + sideDisabled = true + readOnly = true +} diff --git a/client/src/views/admin/auth-token/record/list.js b/client/src/views/admin/auth-token/record/list.js index 0256c758e0..34b1e11271 100644 --- a/client/src/views/admin/auth-token/record/list.js +++ b/client/src/views/admin/auth-token/record/list.js @@ -26,72 +26,74 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/record/list', ['views/record/list'], function (Dep) { +import ListRecordView from 'views/record/list'; - return Dep.extend({ +export default class extends ListRecordView { - rowActionsView: 'views/admin/auth-token/record/row-actions/default', + rowActionsView = 'views/admin/auth-token/record/row-actions/default' + massActionList = ['remove', 'setInactive'] + checkAllResultMassActionList = ['remove', 'setInactive'] - massActionList: ['remove', 'setInactive'], + // noinspection JSUnusedGlobalSymbols + massActionSetInactive() { + let ids = null; + const allResultIsChecked = this.allResultIsChecked; - checkAllResultMassActionList: ['remove', 'setInactive'], + if (!allResultIsChecked) { + ids = this.checkedList; + } - massActionSetInactive: function () { - let ids = null; - let allResultIsChecked = this.allResultIsChecked; + const attributes = { + isActive: false, + }; - if (!allResultIsChecked) { - ids = this.checkedList; - } + Espo.Ajax + .postRequest('MassAction', { + action: 'update', + entityType: this.entityType, + params: { + ids: ids || null, + where: (!ids || ids.length === 0) ? this.collection.getWhere() : null, + searchParams: (!ids || ids.length === 0) ? this.collection.data : null, + }, + data: attributes, + }) + .then(() => { + this.collection + .fetch() + .then(() => { + Espo.Ui.success(this.translate('Done')); - let attributes = { - isActive: false, - }; + if (ids) { + ids.forEach(id => { + this.checkRecord(id); + }); + } + }); + }); + } - Espo.Ajax - .postRequest('MassAction', { - action: 'update', - entityType: this.entityType, - params: { - ids: ids || null, - where: (!ids || ids.length === 0) ? this.collection.getWhere() : null, - searchParams: (!ids || ids.length === 0) ? this.collection.data : null, - }, - data: attributes, - }) - .then(() => { - this.collection - .fetch() - .then(() => { - Espo.Ui.success(this.translate('Done')); + // noinspection JSUnusedGlobalSymbols + /** + * @param {Record} data + */ + actionSetInactive(data) { + if (!data.id) { + return; + } - if (ids) { - ids.forEach(id => { - this.checkRecord(id); - }); - } - }); - }); - }, + const model = this.collection.get(data.id); - actionSetInactive: function (data) { - if (!data.id) { - return; - } + if (!model) { + return; + } - var model = this.collection.get(data.id); + Espo.Ui.notify(this.translate('pleaseWait', 'messages')); - if (!model) { - return; - } - - Espo.Ui.notify(this.translate('pleaseWait', 'messages')); - - model - .save({'isActive': false}, {patch: true}) - .then(() => { - Espo.Ui.notify(false); - }); - }, - }); -}); + model + .save({'isActive': false}, {patch: true}) + .then(() => { + Espo.Ui.notify(false); + }); + } +} diff --git a/client/src/views/admin/auth-token/record/row-actions/default.js b/client/src/views/admin/auth-token/record/row-actions/default.js index 2007a56abb..52f362a930 100644 --- a/client/src/views/admin/auth-token/record/row-actions/default.js +++ b/client/src/views/admin/auth-token/record/row-actions/default.js @@ -26,50 +26,41 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/auth-token/record/row-actions/default', ['views/record/row-actions/default'], function (Dep) { +import DefaultRowActionsView from 'views/record/row-actions/default'; - return Dep.extend({ +export default class extends DefaultRowActionsView { - setup: function () { - Dep.prototype.setup.call(this); + setup() { + super.setup(); - this.listenTo(this.model, 'change:isActive', () => { - setTimeout(() => { - this.reRender(); - }, 10); - }); - }, + this.listenTo(this.model, 'change:isActive', () => { + setTimeout(() => this.reRender(), 10); + }); + } - getActionList: function () { - var list = []; + getActionList() { + const list = []; + list.push({ + action: 'quickView', + label: 'View', + data: {id: this.model.id}, + }); + + if (this.model.get('isActive')) { list.push({ - action: 'quickView', - label: 'View', - data: { - id: this.model.id - } + action: 'setInactive', + label: 'Set Inactive', + data: {id: this.model.id}, }); + } - if (this.model.get('isActive')) { - list.push({ - action: 'setInactive', - label: 'Set Inactive', - data: { - id: this.model.id - } - }); - } + list.push({ + action: 'quickRemove', + label: 'Remove', + data: {id: this.model.id}, + }); - list.push({ - action: 'quickRemove', - label: 'Remove', - data: { - id: this.model.id - } - }); - - return list; - }, - }); -}); + return list; + } +} diff --git a/client/src/views/admin/authentication/fields/test-connection.js b/client/src/views/admin/authentication/fields/test-connection.js index 9097f21e7b..f0ee7d23d7 100644 --- a/client/src/views/admin/authentication/fields/test-connection.js +++ b/client/src/views/admin/authentication/fields/test-connection.js @@ -26,75 +26,75 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/admin/authentication/fields/test-connection', ['views/fields/base'], function (Dep) { +import BaseFieldView from 'views/fields/base'; - return Dep.extend({ +export default class extends BaseFieldView { - templateContent: ` - - `, + // language=Handlebars + templateContent = ` + + ` - events: { - 'click [data-action="testConnection"]': function () { - this.testConnection(); - }, - }, + fetch() { + return {}; + } - fetch: function () { - return {}; - }, + setup() { + super.setup(); - getConnectionData: function () { - return { - 'host': this.model.get('ldapHost'), - 'port': this.model.get('ldapPort'), - 'useSsl': this.model.get('ldapSecurity'), - 'useStartTls': this.model.get('ldapSecurity'), - 'username': this.model.get('ldapUsername'), - 'password': this.model.get('ldapPassword'), - 'bindRequiresDn': this.model.get('ldapBindRequiresDn'), - 'accountDomainName': this.model.get('ldapAccountDomainName'), - 'accountDomainNameShort': this.model.get('ldapAccountDomainNameShort'), - 'accountCanonicalForm': this.model.get('ldapAccountCanonicalForm'), - }; - }, + this.addActionHandler('testConnection', () => this.testConnection()); + } - testConnection: function () { - let data = this.getConnectionData(); - this.$el.find('button').prop('disabled', true); + getConnectionData() { + return { + 'host': this.model.get('ldapHost'), + 'port': this.model.get('ldapPort'), + 'useSsl': this.model.get('ldapSecurity'), + 'useStartTls': this.model.get('ldapSecurity'), + 'username': this.model.get('ldapUsername'), + 'password': this.model.get('ldapPassword'), + 'bindRequiresDn': this.model.get('ldapBindRequiresDn'), + 'accountDomainName': this.model.get('ldapAccountDomainName'), + 'accountDomainNameShort': this.model.get('ldapAccountDomainNameShort'), + 'accountCanonicalForm': this.model.get('ldapAccountCanonicalForm'), + }; + } - this.notify('Connecting', null, null, 'Settings'); + testConnection() { + const data = this.getConnectionData(); - Espo.Ajax - .postRequest('Ldap/action/testConnection', data) - .then(() => { - this.$el.find('button').prop('disabled', false); + this.$el.find('button').prop('disabled', true); - Espo.Ui.success(this.translate('ldapTestConnection', 'messages', 'Settings')); - }) - .catch(xhr => { - let statusReason = xhr.getResponseHeader('X-Status-Reason') || ''; - statusReason = statusReason.replace(/ $/, ''); - statusReason = statusReason.replace(/,$/, ''); + Espo.Ui.notify(this.translate('Connecting', 'labels', 'Settings')); - let msg = this.translate('Error') + ' ' + xhr.status; + Espo.Ajax.postRequest('Ldap/action/testConnection', data) + .then(() => { + this.$el.find('button').prop('disabled', false); - if (statusReason) { - msg += ': ' + statusReason; - } + Espo.Ui.success(this.translate('ldapTestConnection', 'messages', 'Settings')); + }) + .catch(xhr => { + let statusReason = xhr.getResponseHeader('X-Status-Reason') || ''; + statusReason = statusReason.replace(/ $/, ''); + statusReason = statusReason.replace(/,$/, ''); - Espo.Ui.error(msg, true); + let msg = this.translate('Error') + ' ' + xhr.status; - console.error(msg); + if (statusReason) { + msg += ': ' + statusReason; + } - xhr.errorIsHandled = true; + Espo.Ui.error(msg, true); - this.$el.find('button').prop('disabled', false); - }); - }, - }); -}); + console.error(msg); + + xhr.errorIsHandled = true; + + this.$el.find('button').prop('disabled', false); + }); + } +}