diff --git a/application/Espo/Resources/metadata/clientDefs/EmailAccount.json b/application/Espo/Resources/metadata/clientDefs/EmailAccount.json index 05436532bd..0e4e00e78b 100644 --- a/application/Espo/Resources/metadata/clientDefs/EmailAccount.json +++ b/application/Espo/Resources/metadata/clientDefs/EmailAccount.json @@ -1,5 +1,4 @@ { - "controller": "controllers/email-account", "recordViews": { "list":"views/email-account/record/list", "detail": "views/email-account/record/detail", diff --git a/client/src/controllers/about.js b/client/src/controllers/about.js index c1919bc567..f485549fd2 100644 --- a/client/src/controllers/about.js +++ b/client/src/controllers/about.js @@ -26,16 +26,18 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/about', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class AboutController extends Controller { - defaultAction: 'about', + defaultAction = 'about' - actionAbout: function () { - this.main('About', {}, function (view) { - view.render(); - }); - }, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionAbout() { + this.main('About', {}, view => { + view.render(); + }); + } +} + +export default AboutController; diff --git a/client/src/controllers/address-map.js b/client/src/controllers/address-map.js index cf48edfd8d..9a0224c569 100644 --- a/client/src/controllers/address-map.js +++ b/client/src/controllers/address-map.js @@ -26,34 +26,39 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/address-map', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class AddressMapController extends Controller { - defaultAction: 'index', + defaultAction = 'index' - actionIndex: function () { - this.error404(); - }, + // noinspection JSUnusedGlobalSymbols + actionIndex() { + this.error404(); + } - actionView: function (o) { - this.modelFactory.create(o.entityType) - .then( - function (model) { - model.id = o.id; - model.fetch().then( - function () { - var viewName = this.getMetadata().get(['AddressMap', 'view']) || - 'views/address-map/view'; + // noinspection JSUnusedGlobalSymbols + /** + * @param {Object} o + */ + actionView(o) { + this.modelFactory + .create(o.entityType) + .then(model => { + model.id = o.id; - this.main(viewName, { - model: model, - field: o.field, - }); - }.bind(this) - ); - }.bind(this) - ); - }, - }); -}); + model.fetch() + .then(() => { + let viewName = this.getMetadata().get(['AddressMap', 'view']) || + 'views/address-map/view'; + + this.main(viewName, { + model: model, + field: o.field, + }); + }); + }); + } +} + +export default AddressMapController; diff --git a/client/src/controllers/dashboard.js b/client/src/controllers/dashboard.js index 4b5638c08f..865b83ed8d 100644 --- a/client/src/controllers/dashboard.js +++ b/client/src/controllers/dashboard.js @@ -26,18 +26,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/dashboard', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class DashboardController extends Controller { - defaultAction: 'index', + defaultAction = 'index' - actionIndex: function () { - this.main('views/dashboard', { - displayTitle: true, - }, (view) => { - view.render(); - }); - }, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionIndex() { + this.main('views/dashboard', { + displayTitle: true, + }, view => { + view.render(); + }); + } +} + +export default DashboardController; diff --git a/client/src/controllers/email-account.js b/client/src/controllers/email-account.js deleted file mode 100644 index f6a384a98f..0000000000 --- a/client/src/controllers/email-account.js +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -define('controllers/email-account', ['controllers/record'], function (Dep) { - - return Dep.extend({ - - }); -}); diff --git a/client/src/controllers/email.js b/client/src/controllers/email.js index 2317255bdd..b07e7805be 100644 --- a/client/src/controllers/email.js +++ b/client/src/controllers/email.js @@ -26,21 +26,22 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/email', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class EmailController extends RecordController { - prepareModelView: function (model, options) { - Dep.prototype.prepareModelView(model, options); + prepareModelView(model, options) { + super.prepareModelView(model, options); - this.listenToOnce(model, 'after:send', () => { - let key = this.name + 'List'; - let stored = this.getStoredMainView(key); + this.listenToOnce(model, 'after:send', () => { + let key = this.name + 'List'; + let stored = this.getStoredMainView(key); - if (stored) { - this.clearStoredMainView(key); - } - }); - }, - }); -}); + if (stored) { + this.clearStoredMainView(key); + } + }); + } +} + +export default EmailController; diff --git a/client/src/controllers/external-account.js b/client/src/controllers/external-account.js index b962cee34f..3a953070bf 100644 --- a/client/src/controllers/external-account.js +++ b/client/src/controllers/external-account.js @@ -26,37 +26,41 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/external-account', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class ExternalAccountController extends Controller { - defaultAction: 'list', + defaultAction = 'list' - actionList: function (options) { - this.collectionFactory.create('ExternalAccount', (collection) => { - collection.once('sync', () => { - this.main('ExternalAccount.Index', { - collection: collection, - }); + actionList() { + this.collectionFactory.create('ExternalAccount', collection => { + collection.once('sync', () => { + this.main('ExternalAccount.Index', { + collection: collection, }); - - collection.fetch(); }); - }, - actionEdit: function (options) { - let id = options.id; + collection.fetch(); + }); + } - this.collectionFactory.create('ExternalAccount', (collection) => { - collection.once('sync', () => { - this.main('ExternalAccount.Index', { - collection: collection, - id: id, - }); + /** + * @param {{id: string}} options + */ + actionEdit(options) { + let id = options.id; + + this.collectionFactory.create('ExternalAccount', collection => { + collection.once('sync', () => { + this.main('ExternalAccount.Index', { + collection: collection, + id: id, }); - - collection.fetch(); }); - }, - }); -}); + + collection.fetch(); + }); + } +} + +export default ExternalAccountController; diff --git a/client/src/controllers/home.js b/client/src/controllers/home.js index cf59753d83..72800e9a84 100644 --- a/client/src/controllers/home.js +++ b/client/src/controllers/home.js @@ -26,12 +26,14 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/home', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class HomeController extends Controller { - actionIndex: function () { - this.main('views/home', null); - }, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionIndex() { + this.main('views/home', null); + } +} + +export default HomeController; diff --git a/client/src/controllers/import.js b/client/src/controllers/import.js index 44e21b25e7..953a503c87 100644 --- a/client/src/controllers/import.js +++ b/client/src/controllers/import.js @@ -26,71 +26,79 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/import', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class ImportController extends RecordController { - defaultAction: 'index', + defaultAction = 'index' - checkAccessGlobal: function () { - if (this.getAcl().checkScope('Import')) { - return true; - } + checkAccessGlobal() { + if (this.getAcl().checkScope('Import')) { + return true; + } - return false; - }, + return false; + } - checkAccess: function () { - if (this.getAcl().checkScope('Import')) { - return true; - } + checkAccess(action) { + if (this.getAcl().checkScope('Import')) { + return true; + } - return false; - }, + return false; + } - actionIndex: function (o) { - o = o || {}; + // noinspection JSUnusedGlobalSymbols + /** + * @param {{ + * step?: int|string, + * fromAdmin?: boolean, + * formData?: Object + * }} o + */ + actionIndex(o) { + o = o || {}; - var step = null; + let step = null; - if (o.step) { - step = parseInt(step); - } + if (o.step) { + step = parseInt(step); + } - var formData = null; - var fileContents = null; + let formData = null; + let fileContents = null; - if (this.storedData) { - formData = this.storedData.formData; - fileContents = this.storedData.fileContents; - } + if (this.storedData) { + formData = this.storedData.formData; + fileContents = this.storedData.fileContents; + } - if (!formData) { - step = null; - } + if (!formData) { + step = null; + } - formData = formData || o.formData; + formData = formData || o.formData; - this.main('views/import/index', { - step: step, - formData: formData, - fileContents: fileContents, - fromAdmin: o.fromAdmin, - }, (view) => { - this.listenTo(view, 'change', () => { - this.storedData = { - formData: view.formData, - fileContents: view.fileContents, - }; - }); - - this.listenTo(view, 'done', () => { - delete this.storedData; - }); - - view.render(); + this.main('views/import/index', { + step: step, + formData: formData, + fileContents: fileContents, + fromAdmin: o.fromAdmin, + }, /** module:views/import/index */ view => { + this.listenTo(view, 'change', () => { + this.storedData = { + formData: view.formData, + fileContents: view.fileContents, + }; }); - }, - }); -}); + this.listenTo(view, 'done', () => { + delete this.storedData; + }); + + view.render(); + }); + } +} + +export default ImportController; diff --git a/client/src/field-manager.js b/client/src/field-manager.js index 66918f1b84..390379eea7 100644 --- a/client/src/field-manager.js +++ b/client/src/field-manager.js @@ -80,7 +80,7 @@ class FieldManager { * Get a list of parameters for a specific field type. * * @param {string} fieldType A field type. - * @returns {string[]} + * @returns {Object.[]} */ getParamList(fieldType) { if (fieldType in this.defs) { diff --git a/client/src/handlers/create-related.js b/client/src/handlers/create-related.js index 9854cb2b90..e96e09d45f 100644 --- a/client/src/handlers/create-related.js +++ b/client/src/handlers/create-related.js @@ -26,36 +26,31 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('handlers/create-related', [], () => { +/** + * Prepares attributes for a related record that is being created. + * + * @abstract + */ +class CreateRelatedHandler { /** - * Prepares attributes for a related record that is being created. - * - * @abstract - * @class - * @name Class - * @memberOf module:handlers/create-related + * @param {module:view-helper} viewHelper */ - class Class { - - /** - * @param {module:view-helper} viewHelper - */ - constructor(viewHelper) { - this.viewHelper = viewHelper; - } - - /** - * Get attributes for a new record. - * - * @abstract - * @param {module:model} model A model. - * @return {Promise>} Attributes. - */ - getAttributes(model) { - return Promise.resolve({}); - } + constructor(viewHelper) { + // noinspection JSUnusedGlobalSymbols + this.viewHelper = viewHelper; } - return Class; -}); + /** + * Get attributes for a new record. + * + * @abstract + * @param {module:model} model A model. + * @return {Promise>} Attributes. + */ + getAttributes(model) { + return Promise.resolve({}); + } +} + +export default CreateRelatedHandler; diff --git a/client/src/handlers/email-filter.js b/client/src/handlers/email-filter.js index d3e02a2865..7298626a3a 100644 --- a/client/src/handlers/email-filter.js +++ b/client/src/handlers/email-filter.js @@ -26,101 +26,101 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('handlers/email-filter', ['dynamic-handler'], (Dep) => { +import DynamicHandler from 'dynamic-handler'; - return Dep.extend({ +class EmailFilterHandler extends DynamicHandler { - init: function () { - if (this.model.isNew()) { - if (!this.recordView.getUser().isAdmin()) { - this.recordView.hideField('isGlobal'); - } - } - - if ( - !this.model.isNew() && - !this.recordView.getUser().isAdmin() && - !this.model.get('isGlobal') - ) { + init() { + if (this.model.isNew()) { + if (!this.recordView.getUser().isAdmin()) { this.recordView.hideField('isGlobal'); } + } - if (this.model.isNew() && !this.model.get('parentId')) { - this.model.set('parentType', 'User'); - this.model.set('parentId', this.recordView.getUser().id); - this.model.set('parentName', this.recordView.getUser().get('name')); + if ( + !this.model.isNew() && + !this.recordView.getUser().isAdmin() && + !this.model.get('isGlobal') + ) { + this.recordView.hideField('isGlobal'); + } - if (!this.recordView.getUser().isAdmin()) { - this.recordView.setFieldReadOnly('parent'); - } - } - else if ( - this.model.get('parentType') && - !this.recordView.options.duplicateSourceId - ) { + if (this.model.isNew() && !this.model.get('parentId')) { + this.model.set('parentType', 'User'); + this.model.set('parentId', this.recordView.getUser().id); + this.model.set('parentName', this.recordView.getUser().get('name')); + + if (!this.recordView.getUser().isAdmin()) { this.recordView.setFieldReadOnly('parent'); - this.recordView.setFieldReadOnly('isGlobal'); + } + } + else if ( + this.model.get('parentType') && + !this.recordView.options.duplicateSourceId + ) { + this.recordView.setFieldReadOnly('parent'); + this.recordView.setFieldReadOnly('isGlobal'); + } + + this.recordView.listenTo(this.model, 'change:isGlobal', (model, value, o) => { + if (!o.ui) { + return; } - this.recordView.listenTo(this.model, 'change:isGlobal', (model, value, o) => { - if (!o.ui) { + if (value) { + this.model.set({ + action: 'Skip', + parentName: null, + parentType: null, + parentId: null, + emailFolderId: null, + groupEmailFolderId: null, + markAsRead: false, + }); + } + }); + + this.recordView.listenTo(this.model, 'change:parentType', (model, value, o) => { + if (!o.ui) { + return; + } + + // Avoiding side effects. + setTimeout(() => { + if (value !== 'User') { + this.model.set('markAsRead', false); + } + + if (value === 'EmailAccount') { + this.model.set('action', 'Skip'); + this.model.set('emailFolderId', null); + this.model.set('groupEmailFolderId', null); + this.model.set('markAsRead', false); + return; } - if (value) { - this.model.set({ - action: 'Skip', - parentName: null, - parentType: null, - parentId: null, - emailFolderId: null, - groupEmailFolderId: null, - markAsRead: false, - }); - } - }); - - this.recordView.listenTo(this.model, 'change:parentType', (model, value, o) => { - if (!o.ui) { - return; - } - - // Avoiding side effects. - setTimeout(() => { - if (value !== 'User') { - this.model.set('markAsRead', false); - } - - if (value === 'EmailAccount') { + if (value !== 'InboundEmail') { + if (this.model.get('action') === 'Move to Group Folder') { this.model.set('action', 'Skip'); - this.model.set('emailFolderId', null); - this.model.set('groupEmailFolderId', null); - this.model.set('markAsRead', false); - - return; } - if (value !== 'InboundEmail') { - if (this.model.get('action') === 'Move to Group Folder') { - this.model.set('action', 'Skip'); - } + this.model.set('groupEmailFolderId', null); - this.model.set('groupEmailFolderId', null); + return; + } - return; + if (value !== 'User') { + if (this.model.get('action') === 'Move to Folder') { + this.model.set('action', 'Skip'); } - if (value !== 'User') { - if (this.model.get('action') === 'Move to Folder') { - this.model.set('action', 'Skip'); - } + this.model.set('groupFolderId', null); + } + }, 40); + }); + } +} - this.model.set('groupFolderId', null); +export default EmailFilterHandler; - return; - } - }, 40); - }); - }, - }); -}); diff --git a/client/src/handlers/import.js b/client/src/handlers/import.js index a42d05b69e..b11fc6e569 100644 --- a/client/src/handlers/import.js +++ b/client/src/handlers/import.js @@ -26,29 +26,26 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('handlers/import', ['action-handler'], function (Dep) { +import ActionHandler from 'action-handler'; - /** - * @extends module:action-handler - */ - class Class extends Dep { +class ImportHandler extends ActionHandler { - actionErrorExport() { - Espo.Ajax - .postRequest(`Import/${this.view.model.id}/exportErrors`) - .then(data => { - if (!data.attachmentId) { - let message = this.view.translate('noErrors', 'messages', 'Import'); + // noinspection JSUnusedGlobalSymbols + actionErrorExport() { + Espo.Ajax + .postRequest(`Import/${this.view.model.id}/exportErrors`) + .then(data => { + if (!data.attachmentId) { + let message = this.view.translate('noErrors', 'messages', 'Import'); - Espo.Ui.warning(message); + Espo.Ui.warning(message); - return; - } + return; + } - window.location = this.view.getBasePath() + '?entryPoint=download&id=' + data.attachmentId; - }); - } + window.location = this.view.getBasePath() + '?entryPoint=download&id=' + data.attachmentId; + }); } +} - return Class; -}); +export default ImportHandler; diff --git a/client/src/handlers/login.js b/client/src/handlers/login.js index 160605e6f4..7b2243fd8b 100644 --- a/client/src/handlers/login.js +++ b/client/src/handlers/login.js @@ -33,7 +33,7 @@ * * @abstract */ -class Handler { +class LoginHandler { /** * @param {module:views/login} loginView A login view. @@ -67,4 +67,4 @@ class Handler { } } -export default Handler; +export default LoginHandler; diff --git a/client/src/handlers/login/oidc.js b/client/src/handlers/login/oidc.js index eb29d99b6f..19a3c5463a 100644 --- a/client/src/handlers/login/oidc.js +++ b/client/src/handlers/login/oidc.js @@ -26,10 +26,10 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -import Dep from 'handlers/login'; +import LoginHandler from 'handlers/login'; import Base64 from 'js-base64'; -class Handler extends Dep { +class OidcLoginHandler extends LoginHandler { /** @inheritDoc */ process() { @@ -209,4 +209,4 @@ class Handler extends Dep { } } -export default Handler; +export default OidcLoginHandler; diff --git a/client/src/handlers/select-related.js b/client/src/handlers/select-related.js index 03697bc9ee..b3f9d86223 100644 --- a/client/src/handlers/select-related.js +++ b/client/src/handlers/select-related.js @@ -42,12 +42,13 @@ * * @abstract */ -class SelectRelated { +class SelectRelatedHandler { /** * @param {module:view-helper} viewHelper */ constructor(viewHelper) { + // noinspection JSUnusedGlobalSymbols /** @protected */ this.viewHelper = viewHelper; } @@ -64,4 +65,4 @@ class SelectRelated { } } -export default SelectRelated; +export default SelectRelatedHandler; diff --git a/client/src/handlers/select-related/same-account-many.js b/client/src/handlers/select-related/same-account-many.js index 8b11821154..e8c8924d3d 100644 --- a/client/src/handlers/select-related/same-account-many.js +++ b/client/src/handlers/select-related/same-account-many.js @@ -26,44 +26,47 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('handlers/select-related/same-account-many', ['handlers/select-related'], Dep => { +import SelectRelatedHandler from 'handlers/select-related'; - return class extends Dep { - /** - * @param {module:model} model - * @return {Promise} - */ - getFilters(model) { - let advanced = {}; +class SameAccountManySelectRelatedHandler extends SelectRelatedHandler { - let accountId = null; - let accountName = null; + /** + * @param {module:model} model + * @return {Promise} + */ + getFilters(model) { + let advanced = {}; - if (model.get('accountId')) { - accountId = model.get('accountId'); - accountName = model.get('accountName'); - } + let accountId = null; + let accountName = null; - if (!accountId && model.get('parentType') === 'Account' && model.get('parentId')) { - accountId = model.get('parentId'); - accountName = model.get('parentName'); - } - - if (accountId) { - let nameHash = {}; - nameHash[accountId] = accountName; - - advanced.accounts = { - field: 'accounts', - type: 'linkedWith', - value: [accountId], - data: {nameHash: nameHash}, - }; - } - - return Promise.resolve({ - advanced: advanced, - }); + if (model.get('accountId')) { + accountId = model.get('accountId'); + accountName = model.get('accountName'); } + + if (!accountId && model.get('parentType') === 'Account' && model.get('parentId')) { + accountId = model.get('parentId'); + accountName = model.get('parentName'); + } + + if (accountId) { + let nameHash = {}; + nameHash[accountId] = accountName; + + advanced.accounts = { + field: 'accounts', + type: 'linkedWith', + value: [accountId], + data: {nameHash: nameHash}, + }; + } + + return Promise.resolve({ + advanced: advanced, + }); } -}); +} + +// noinspection JSUnusedGlobalSymbols +export default SameAccountManySelectRelatedHandler; diff --git a/client/src/handlers/select-related/same-account.js b/client/src/handlers/select-related/same-account.js index 17d7405474..9d749529d3 100644 --- a/client/src/handlers/select-related/same-account.js +++ b/client/src/handlers/select-related/same-account.js @@ -26,44 +26,46 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('handlers/select-related/same-account', ['handlers/select-related'], Dep => { +import SelectRelatedHandler from 'handlers/select-related'; - return class extends Dep { - /** - * @param {module:model} model - * @return {Promise} - */ - getFilters(model) { - let advanced = {}; +class SameAccountSelectRelatedHandler extends SelectRelatedHandler { - let accountId = null; - let accountName = null; + /** + * @param {module:model} model + * @return {Promise} + */ + getFilters(model) { + let advanced = {}; - if (model.get('accountId')) { - accountId = model.get('accountId'); - accountName = model.get('accountName'); - } + let accountId = null; + let accountName = null; - if (!accountId && model.get('parentType') === 'Account' && model.get('parentId')) { - accountId = model.get('parentId'); - accountName = model.get('parentName'); - } - - if (accountId) { - advanced.account = { - attribute: 'accountId', - type: 'equals', - value: accountId, - data: { - type: 'is', - nameValue: accountName, - }, - }; - } - - return Promise.resolve({ - advanced: advanced, - }); + if (model.get('accountId')) { + accountId = model.get('accountId'); + accountName = model.get('accountName'); } + + if (!accountId && model.get('parentType') === 'Account' && model.get('parentId')) { + accountId = model.get('parentId'); + accountName = model.get('parentName'); + } + + if (accountId) { + advanced.account = { + attribute: 'accountId', + type: 'equals', + value: accountId, + data: { + type: 'is', + nameValue: accountName, + }, + }; + } + + return Promise.resolve({ + advanced: advanced, + }); } -}); +} + +export default SameAccountSelectRelatedHandler; diff --git a/client/src/helpers/misc/field-language.js b/client/src/helpers/misc/field-language.js index 857a3bb7e9..abbd3a5919 100644 --- a/client/src/helpers/misc/field-language.js +++ b/client/src/helpers/misc/field-language.js @@ -30,26 +30,26 @@ /** * A field-language util. - * - * @class - * @param {module:metadata} metadata A metadata. - * @param {module:language} language A language. */ -const FieldLanguage = function (metadata, language) { - /** - * @private - * @type {module:metadata} - */ - this.metadata = metadata; +class FieldLanguage { /** - * @private - * @type {module:language} + * @param {module:metadata} metadata A metadata. + * @param {module:language} language A language. */ - this.language = language; -}; + constructor(metadata, language) { + /** + * @private + * @type {module:metadata} + */ + this.metadata = metadata; -_.extend(FieldLanguage.prototype, /** @lends FieldLanguage# */{ + /** + * @private + * @type {module:language} + */ + this.language = language; + } /** * Translate an attribute. @@ -58,61 +58,61 @@ _.extend(FieldLanguage.prototype, /** @lends FieldLanguage# */{ * @param {string} name An attribute name. * @returns {string} */ - translateAttribute: function (scope, name) { + translateAttribute(scope, name) { let label = this.language.translate(name, 'fields', scope); if (name.indexOf('Id') === name.length - 2) { - let baseField = name.substr(0, name.length - 2); + let baseField = name.slice(0, name.length - 2); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('id', 'fields') + ')'; + ' (' + this.language.translate('id', 'fields') + ')'; } } else if (name.indexOf('Name') === name.length - 4) { - let baseField = name.substr(0, name.length - 4); + let baseField = name.slice(0, name.length - 4); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('name', 'fields') + ')'; + ' (' + this.language.translate('name', 'fields') + ')'; } } else if (name.indexOf('Type') === name.length - 4) { - let baseField = name.substr(0, name.length - 4); + let baseField = name.slice(0, name.length - 4); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('type', 'fields') + ')'; + ' (' + this.language.translate('type', 'fields') + ')'; } } if (name.indexOf('Ids') === name.length - 3) { - let baseField = name.substr(0, name.length - 3); + let baseField = name.slice(0, name.length - 3); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('ids', 'fields') + ')'; + ' (' + this.language.translate('ids', 'fields') + ')'; } } else if (name.indexOf('Names') === name.length - 5) { - let baseField = name.substr(0, name.length - 5); + let baseField = name.slice(0, name.length - 5); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('names', 'fields') + ')'; + ' (' + this.language.translate('names', 'fields') + ')'; } } else if (name.indexOf('Types') === name.length - 5) { - let baseField = name.substr(0, name.length - 5); + let baseField = name.slice(0, name.length - 5); if (this.metadata.get(['entityDefs', scope, 'fields', baseField])) { label = this.language.translate(baseField, 'fields', scope) + - ' (' + this.language.translate('types', 'fields') + ')'; + ' (' + this.language.translate('types', 'fields') + ')'; } } return label; - }, -}); + } +} export default FieldLanguage;