diff --git a/client/src/controller.js b/client/src/controller.js index 6b53377c47..872dd92c44 100644 --- a/client/src/controller.js +++ b/client/src/controller.js @@ -441,7 +441,7 @@ class Controller { /** * Create a main view in the master. * - * @param {string} view A view name. + * @param {string} [view] A view name. * @param {Object} [options] Options for view. * @param {module:controller~viewCallback} [callback] A callback with a created view. * @param {boolean} [useStored] Use a stored view if available. diff --git a/client/src/controllers/api-user.js b/client/src/controllers/api-user.js index 20d47395ae..277d1acb76 100644 --- a/client/src/controllers/api-user.js +++ b/client/src/controllers/api-user.js @@ -41,6 +41,12 @@ class ApiUserController extends RecordController { }); } + /** + * @protected + * @param {Object} options + * @param {module:models/user} model + * @param {string} view + */ createViewView(options, model, view) { if (!model.isApi()) { if (model.isPortal()) { diff --git a/client/src/controllers/inbound-email.js b/client/src/controllers/inbound-email.js index 6bcb2ec7c9..6d168f3a3b 100644 --- a/client/src/controllers/inbound-email.js +++ b/client/src/controllers/inbound-email.js @@ -26,17 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/inbound-email', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class InboundEmailController extends RecordController { - checkAccess: function () { - if (this.getUser().isAdmin()) { - return true; - } + checkAccess(action) { + if (this.getUser().isAdmin()) { + return true; + } - return false; - }, + return false; + } +} - }); -}); +export default InboundEmailController; diff --git a/client/src/controllers/last-viewed.js b/client/src/controllers/last-viewed.js index 5b55c804a5..c6ab33e1e2 100644 --- a/client/src/controllers/last-viewed.js +++ b/client/src/controllers/last-viewed.js @@ -26,14 +26,16 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/last-viewed', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class LastViewedController extends RecordController { - entityType: 'ActionHistoryRecord', + entityType = 'ActionHistoryRecord' - checkAccess: function (action) { - return this.getAcl().check(this.entityType, action); - }, - }); -}); + checkAccess(action) { + return this.getAcl().check(this.entityType, action); + } +} + +// noinspection JSUnusedGlobalSymbols +export default LastViewedController; diff --git a/client/src/controllers/layout-set.js b/client/src/controllers/layout-set.js index 5d191f988c..213726941e 100644 --- a/client/src/controllers/layout-set.js +++ b/client/src/controllers/layout-set.js @@ -26,23 +26,27 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/layout-set', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class LayoutSetController extends RecordController { - actionEditLayouts: function (options) { - var id = options.id; + // noinspection JSUnusedGlobalSymbols + /** + * @param {Record} options + */ + actionEditLayouts(options) { + let id = options.id; - if (!id) { - throw new Error("ID not passed."); - } + if (!id) { + throw new Error("ID not passed."); + } - this.main('views/layout-set/layouts', { - layoutSetId: id, - scope: options.scope, - type: options.type, - }); - }, + this.main('views/layout-set/layouts', { + layoutSetId: id, + scope: options.scope, + type: options.type, + }); + } +} - }); -}); +export default LayoutSetController; diff --git a/client/src/controllers/lead-capture-opt-in-confirmation.js b/client/src/controllers/lead-capture-opt-in-confirmation.js index 9fbd6a3497..1dc39f013b 100644 --- a/client/src/controllers/lead-capture-opt-in-confirmation.js +++ b/client/src/controllers/lead-capture-opt-in-confirmation.js @@ -26,32 +26,34 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/lead-capture-opt-in-confirmation', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class LeadCaptureOptInConfirmationController extends Controller { - actionOptInConfirmationSuccess: function (data) { - var viewName = this.getMetadata() - .get(['clientDefs', 'LeadCapture', 'optInConfirmationSuccessView']) || - 'views/lead-capture/opt-in-confirmation-success'; + // noinspection JSUnusedGlobalSymbols + actionOptInConfirmationSuccess(data) { + let viewName = this.getMetadata().get(['clientDefs', 'LeadCapture', 'optInConfirmationSuccessView']) || + 'views/lead-capture/opt-in-confirmation-success'; - this.entire(viewName, { - resultData: data, - }, (view) => { - view.render(); - }); - }, + this.entire(viewName, { + resultData: data, + }, view => { + view.render(); + }); + } - actionOptInConfirmationExpired: function (data) { - var viewName = this.getMetadata() - .get(['clientDefs', 'LeadCapture', 'optInConfirmationExpiredView']) || - 'views/lead-capture/opt-in-confirmation-expired'; + // noinspection JSUnusedGlobalSymbols + actionOptInConfirmationExpired(data) { + let viewName = this.getMetadata().get(['clientDefs', 'LeadCapture', 'optInConfirmationExpiredView']) || + 'views/lead-capture/opt-in-confirmation-expired'; - this.entire(viewName, { - resultData: data - }, (view) => { - view.render(); - }); - }, - }); -}); + this.entire(viewName, { + resultData: data, + }, view => { + view.render(); + }); + } +} + +// noinspection JSUnusedGlobalSymbols +export default LeadCaptureOptInConfirmationController; diff --git a/client/src/controllers/login-as.js b/client/src/controllers/login-as.js index c6c4554f7b..1a1dabab2f 100644 --- a/client/src/controllers/login-as.js +++ b/client/src/controllers/login-as.js @@ -26,29 +26,35 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/login-as', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class LoginAsController extends Controller { - actionLogin: function (options) { - let anotherUser = options.anotherUser; - let username = options.username; + // noinspection JSUnusedGlobalSymbols + /** + * @param {Record} options + */ + actionLogin(options) { + let anotherUser = options.anotherUser; + let username = options.username; - if (!anotherUser) { - throw new Error("No anotherUser."); - } + if (!anotherUser) { + throw new Error("No anotherUser."); + } - this.baseController.login({ - anotherUser: anotherUser, - username: username, - }); + this.baseController.login({ + anotherUser: anotherUser, + username: username, + }); - this.listenToOnce(this.baseController, 'login', () => { - this.baseController.once('router-set', () => { - let url = window.location.href.split('?')[0]; - window.location.replace(url); - }) - }); - }, - }); -}); + this.listenToOnce(this.baseController, 'login', () => { + this.baseController.once('router-set', () => { + let url = window.location.href.split('?')[0]; + + window.location.replace(url); + }) + }); + } +} + +export default LoginAsController; diff --git a/client/src/controllers/note.js b/client/src/controllers/note.js index 67f1d3898e..5ad015f2db 100644 --- a/client/src/controllers/note.js +++ b/client/src/controllers/note.js @@ -26,42 +26,41 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/note', ['controller'], function (Dep) { +import Controller from 'controller'; +class NoteController extends Controller { + + // noinspection JSUnusedGlobalSymbols /** - * @class - * @name Class - * @extends module:controller - * @memberOf module:controllers/note + * @param {Record} options */ - return Dep.extend(/** @lends module:controllers/note.Class# */{ + actionView(options) { + let id = options.id; - actionView: function (options) { - let id = options.id; + if (!id) { + throw new Espo.Exceptions.NotFound; + } - if (!id) { - throw new Espo.Espo.Exceptions.NotFound; - } + let viewName = this.getMetadata().get(['clientDefs', this.name, 'views', 'detail']) || + 'views/note/detail'; - let viewName = 'views/note/detail' || - this.getMetadata().get(['clientDefs', this.name, 'views', 'detail']); + let model; - let model; + this.showLoadingNotification(); - this.showLoadingNotification(); + this.modelFactory.create('Note') + .then(m => { + model = m; + model.id = id; - this.modelFactory.create('Note') - .then(m => { - model = m; - model.id = id; + return model.fetch({main: true}); + }) + .then(() => { + this.hideLoadingNotification(); - return model.fetch({main: true}); - }) - .then(() => { - this.hideLoadingNotification(); + this.main(viewName, {model: model}); + }); + } +} - this.main(viewName, {model: model}); - }); - }, - }); -}); +export default NoteController; diff --git a/client/src/controllers/notification.js b/client/src/controllers/notification.js index 7a154142c9..c35605ef21 100644 --- a/client/src/controllers/notification.js +++ b/client/src/controllers/notification.js @@ -26,16 +26,18 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/notification', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class NotificationController extends Controller { - defaultAction: 'index', + defaultAction = 'index' - actionIndex: function () { - this.main('views/notification/list', {}, (view) => { - view.render(); - }); - }, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionIndex() { + this.main('views/notification/list', {}, view => { + view.render(); + }); + } +} + +export default NotificationController; diff --git a/client/src/controllers/page.js b/client/src/controllers/page.js deleted file mode 100644 index 7a8ad600ee..0000000000 --- a/client/src/controllers/page.js +++ /dev/null @@ -1,39 +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/page', ['controller'], function (Dep) { - - return Dep.extend({ - - actionView: function (options) { - var page = options.id; - - this.main(null, {template: 'pages.' + Espo.Utils.convert(page, 'c-h')}); - }, - }); -}); diff --git a/client/src/controllers/password-change-request.js b/client/src/controllers/password-change-request.js index 71d37cd978..e74edb3e3f 100644 --- a/client/src/controllers/password-change-request.js +++ b/client/src/controllers/password-change-request.js @@ -26,24 +26,26 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/password-change-request', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class PasswordChangeRequestController extends Controller { - actionPasswordChange: function (options) { - options = options || {}; + // noinspection JSUnusedGlobalSymbols + actionPasswordChange(options) { + options = options || {}; - if (!options.id) { - throw new Error(); - } + if (!options.id) { + throw new Error(); + } - this.entire('views/user/password-change-request', { - requestId: options.id, - strengthParams: options.strengthParams, - notFound: options.notFound, - }, view => { - view.render(); - }); - }, - }); -}); + this.entire('views/user/password-change-request', { + requestId: options.id, + strengthParams: options.strengthParams, + notFound: options.notFound, + }, view => { + view.render(); + }); + } +} + +export default PasswordChangeRequestController; diff --git a/client/src/controllers/portal-role.js b/client/src/controllers/portal-role.js index d8225a89f1..a724992d52 100644 --- a/client/src/controllers/portal-role.js +++ b/client/src/controllers/portal-role.js @@ -26,16 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/portal-role', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class PortalRoleController extends RecordController { - checkAccess: function () { - if (this.getUser().isAdmin()) { - return true; - } + checkAccess(action) { + if (this.getUser().isAdmin()) { + return true; + } - return false; - }, - }); -}); + return false; + } +} + +export default PortalRoleController; diff --git a/client/src/controllers/portal-user.js b/client/src/controllers/portal-user.js index 08b56ca20d..2c71807a82 100644 --- a/client/src/controllers/portal-user.js +++ b/client/src/controllers/portal-user.js @@ -41,6 +41,12 @@ class PortalUserController extends RecordController { }); } + /** + * @protected + * @param {Object} options + * @param {module:models/user} model + * @param {string} view + */ createViewView(options, model, view) { if (!model.isPortal()) { if (model.isApi()) { diff --git a/client/src/controllers/preferences.js b/client/src/controllers/preferences.js index 4f8f671ff2..4f0f3aac08 100644 --- a/client/src/controllers/preferences.js +++ b/client/src/controllers/preferences.js @@ -26,36 +26,38 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/preferences', ['controllers/record', 'models/preferences'], function (Dep, Preferences) { +import RecordController from 'controllers/record'; +import Preferences from 'models/preferences'; - return Dep.extend({ +class PreferencesController extends RecordController { - defaultAction: 'own', + defaultAction = 'own' - getModel: function (callback) { - var model = new Preferences(); + getModel(callback, context) { + let model = new Preferences(); - model.settings = this.getConfig(); - model.defs = this.getMetadata().get('entityDefs.Preferences'); + model.settings = this.getConfig(); + model.defs = this.getMetadata().get('entityDefs.Preferences'); - if (callback) { - callback.call(this, model); - } - return new Promise(function (resolve) { - resolve(model); - }); - }, + if (callback) { + callback.call(this, model); + } - checkAccess: function (action) { - return true; - }, + return new Promise(resolve => { + resolve(model); + }); + } - actionOwn: function () { - this.actionEdit({ - id: this.getUser().id - }); - }, + checkAccess(action) { + return true; + } - actionList: function () {}, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionOwn() { + this.actionEdit({id: this.getUser().id}); + } + + actionList() {} +} + +export default PreferencesController; diff --git a/client/src/controllers/record-tree.js b/client/src/controllers/record-tree.js index 96a234f785..0e3b8d2c2b 100644 --- a/client/src/controllers/record-tree.js +++ b/client/src/controllers/record-tree.js @@ -26,36 +26,39 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/record-tree', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class RecordTreeController extends RecordController { - defaultAction: 'listTree', + defaultAction = 'listTree' - beforeView: function (options) { - Dep.prototype.beforeView.call(this, options); + beforeView(options) { + super.beforeView(options); - options = options || {}; + options = options || {}; - if (options.model) { - options.model.unset('childCollection'); - options.model.unset('childList'); - } - }, + if (options.model) { + options.model.unset('childCollection'); + options.model.unset('childList'); + } + } - beforeListTree: function () { - this.handleCheckAccess('read'); - }, + // noinspection JSUnusedGlobalSymbols + beforeListTree() { + this.handleCheckAccess('read'); + } - actionListTree: function () { - this.getCollection().then(collection => { - collection.url = collection.entityType + '/action/listTree'; + // noinspection JSUnusedGlobalSymbols + actionListTree() { + this.getCollection().then(collection => { + collection.url = collection.entityType + '/action/listTree'; - this.main(this.getViewName('listTree'), { - scope: this.name, - collection: collection - }); + this.main(this.getViewName('listTree'), { + scope: this.name, + collection: collection }); - }, - }); -}); + }); + } +} + +export default RecordTreeController; diff --git a/client/src/controllers/record.js b/client/src/controllers/record.js index 1307199c8e..71836a8c93 100644 --- a/client/src/controllers/record.js +++ b/client/src/controllers/record.js @@ -61,7 +61,7 @@ class RecordController extends Controller { * Get a view name/path. * * @protected - * @param {'list'|'detail'|'edit'|'create'|'listRelated'} type A type. + * @param {'list'|'detail'|'edit'|'create'|'listRelated'|string} type A type. * @returns {string} */ getViewName(type) { diff --git a/client/src/controllers/role.js b/client/src/controllers/role.js index 413f7060bb..6d8585ab87 100644 --- a/client/src/controllers/role.js +++ b/client/src/controllers/role.js @@ -26,16 +26,17 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/role', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class RoleController extends RecordController { - checkAccess: function () { - if (this.getUser().isAdmin()) { - return true; - } + checkAccess(action) { + if (this.getUser().isAdmin()) { + return true; + } - return false; - }, - }); -}); + return false; + } +} + +export default RoleController; diff --git a/client/src/controllers/stream.js b/client/src/controllers/stream.js index ae95e04218..8d31ae8b3f 100644 --- a/client/src/controllers/stream.js +++ b/client/src/controllers/stream.js @@ -26,36 +26,40 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/stream', ['controller'], function (Dep) { +import Controller from 'controller'; - return Dep.extend({ +class StreamController extends Controller { - defaultAction: 'index', + defaultAction = 'index' - actionIndex: function () { - this.main('views/stream', { - displayTitle: true, - }, function (view) { - view.render(); - }); - }, + // noinspection JSUnusedGlobalSymbols + actionIndex() { + this.main('views/stream', { + displayTitle: true, + }, view => { + view.render(); + }); + } - actionPosts: function () { - this.main('views/stream', { - displayTitle: true, - filter: 'posts', - }, function (view) { - view.render(); - }); - }, + // noinspection JSUnusedGlobalSymbols + actionPosts() { + this.main('views/stream', { + displayTitle: true, + filter: 'posts', + }, view => { + view.render(); + }); + } - actionUpdates: function () { - this.main('views/stream', { - displayTitle: true, - filter: 'updates', - }, function (view) { - view.render(); - }); - }, - }); -}); + // noinspection JSUnusedGlobalSymbols + actionUpdates() { + this.main('views/stream', { + displayTitle: true, + filter: 'updates', + }, view => { + view.render(); + }); + } +} + +export default StreamController; diff --git a/client/src/controllers/team.js b/client/src/controllers/team.js index bf2999c0eb..12a1a5df2b 100644 --- a/client/src/controllers/team.js +++ b/client/src/controllers/team.js @@ -26,18 +26,21 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/team', ['controllers/record'], function (Dep) { +import RecordController from 'controllers/record'; - return Dep.extend({ +class TeamController extends RecordController { - checkAccess: function (action) { - if (action == 'read') { - return true; - } + checkAccess(action) { + if (action === 'read') { + return true; + } - if (this.getUser().isAdmin()) { - return true; - } - }, - }); -}); + if (this.getUser().isAdmin()) { + return true; + } + + return false; + } +} + +export default TeamController;