diff --git a/client/src/acl-portal/email.js b/client/src/acl-portal/email.js index 3bf98cdd3a..28b05d16a5 100644 --- a/client/src/acl-portal/email.js +++ b/client/src/acl-portal/email.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl-portal/email', 'acl-portal', function (Dep) { +define('acl-portal/email', ['acl-portal'], function (Dep) { return Dep.extend({ @@ -57,9 +57,6 @@ Espo.define('acl-portal/email', 'acl-portal', function (Dep) { } return result; - } - + }, }); - }); - diff --git a/client/src/acl-portal/notification.js b/client/src/acl-portal/notification.js index 7d0fd1a22a..fecfac32a9 100644 --- a/client/src/acl-portal/notification.js +++ b/client/src/acl-portal/notification.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl-portal/notification', 'acl-portal', function (Dep) { +define('acl-portal/notification', ['acl-portal'], function (Dep) { return Dep.extend({ @@ -35,7 +35,6 @@ Espo.define('acl-portal/notification', 'acl-portal', function (Dep) { return true; } return false; - } - + }, }); }); diff --git a/client/src/acl-portal/preferences.js b/client/src/acl-portal/preferences.js index dc1002858b..90cd9002b9 100644 --- a/client/src/acl-portal/preferences.js +++ b/client/src/acl-portal/preferences.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl-portal/preferences', 'acl-portal', function (Dep) { +define('acl-portal/preferences', ['acl-portal'], function (Dep) { return Dep.extend({ @@ -36,9 +36,6 @@ Espo.define('acl-portal/preferences', 'acl-portal', function (Dep) { } return false; - } - + }, }); - }); - diff --git a/client/src/acl/email.js b/client/src/acl/email.js index 322f3a8ec3..666ddde6e4 100644 --- a/client/src/acl/email.js +++ b/client/src/acl/email.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl/email', 'acl', function (Dep) { +define('acl/email', ['acl'], function (Dep) { return Dep.extend({ @@ -60,7 +60,10 @@ Espo.define('acl/email', 'acl', function (Dep) { }, checkIsOwner: function (model) { - if (this.getUser().id === model.get('assignedUserId') || this.getUser().id === model.get('createdById')) { + if ( + this.getUser().id === model.get('assignedUserId') || + this.getUser().id === model.get('createdById') + ) { return true; } @@ -109,6 +112,6 @@ Espo.define('acl/email', 'acl', function (Dep) { } return result; - } + }, }); }); diff --git a/client/src/acl/import.js b/client/src/acl/import.js index f68ec017b4..14911ad379 100644 --- a/client/src/acl/import.js +++ b/client/src/acl/import.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl/import', 'acl', function (Dep) { +define('acl/import', ['acl'], function (Dep) { return Dep.extend({ @@ -48,7 +48,6 @@ Espo.define('acl/import', 'acl', function (Dep) { checkModelDelete: function (model, data, precise) { return true; - } - + }, }); }); diff --git a/client/src/acl/notification.js b/client/src/acl/notification.js index fa7d7ff108..789222f295 100644 --- a/client/src/acl/notification.js +++ b/client/src/acl/notification.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl/notification', 'acl', function (Dep) { +define('acl/notification', ['acl'], function (Dep) { return Dep.extend({ @@ -34,6 +34,7 @@ Espo.define('acl/notification', 'acl', function (Dep) { if (this.getUser().id === model.get('userId')) { return true; } + return false; } }); diff --git a/client/src/acl/preferences.js b/client/src/acl/preferences.js index 20f3afa132..2c64dabf1e 100644 --- a/client/src/acl/preferences.js +++ b/client/src/acl/preferences.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('acl/preferences', 'acl', function (Dep) { +define('acl/preferences', ['acl'], function (Dep) { return Dep.extend({ @@ -34,10 +34,8 @@ Espo.define('acl/preferences', 'acl', function (Dep) { if (this.getUser().id === model.id) { return true; } + return false; - } - + }, }); - }); - diff --git a/client/src/acl/team.js b/client/src/acl/team.js index 33c063dfe5..8e4b599187 100644 --- a/client/src/acl/team.js +++ b/client/src/acl/team.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/team', 'acl', function (Dep) { +define('acl/team', ['acl'], function (Dep) { return Dep.extend({ @@ -35,6 +35,5 @@ define('acl/team', 'acl', function (Dep) { return (userTeamIdList.indexOf(model.id) != -1); }, - }); }); diff --git a/client/src/acl/user.js b/client/src/acl/user.js index 8ecadf949d..e980cb168c 100644 --- a/client/src/acl/user.js +++ b/client/src/acl/user.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('acl/user', 'acl', function (Dep) { +define('acl/user', ['acl'], function (Dep) { return Dep.extend({ @@ -43,6 +43,5 @@ define('acl/user', 'acl', function (Dep) { checkIsOwner: function (model) { return this.getUser().id === model.id; }, - }); }); diff --git a/client/src/app.js b/client/src/app.js index 35bf654d81..e7832aef79 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -703,7 +703,7 @@ function ( * Create an acl-manager. * * @protected - * @return {module:acl-manager} + * @return {module:acl-manager.Class} */ createAclManager: function () { return new AclManager(this.user, null, this.settings.get('aclAllowDeleteCreated')); diff --git a/client/src/collections/note.js b/client/src/collections/note.js index 13fbaaeebf..b961fa19bd 100644 --- a/client/src/collections/note.js +++ b/client/src/collections/note.js @@ -26,10 +26,19 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('collections/note', 'collection', function (Dep) { +define('collections/note', ['collection'], function (Dep) { - return Dep.extend({ + /** + * @class + * @name Class + * @extends module:collection.Class + * @memberOf module:collections/note + */ + return Dep.extend(/** @lends module:collections/note.Class# */{ + /** + * @inheritDoc + */ parse: function (response, params) { var total = this.total; @@ -46,6 +55,12 @@ define('collections/note', 'collection', function (Dep) { return list; }, + /** + * Fetch new records. + * + * @param {Object} options Options. + * @returns {Promise} + */ fetchNew: function (options) { options = options || {}; @@ -64,6 +79,5 @@ define('collections/note', 'collection', function (Dep) { return this.fetch(options); }, - }); }); diff --git a/client/src/controllers/about.js b/client/src/controllers/about.js index f31617090a..bc29a167bd 100644 --- a/client/src/controllers/about.js +++ b/client/src/controllers/about.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/about', 'controller', function (Dep) { +define('controllers/about', ['controller'], function (Dep) { return Dep.extend({ @@ -36,7 +36,6 @@ define('controllers/about', 'controller', function (Dep) { this.main('About', {}, function (view) { view.render(); }); - } + }, }); - }); diff --git a/client/src/controllers/address-map.js b/client/src/controllers/address-map.js index 939988b402..02180d77e9 100644 --- a/client/src/controllers/address-map.js +++ b/client/src/controllers/address-map.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/address-map', 'controller', function (Dep) { +define('controllers/address-map', ['controller'], function (Dep) { return Dep.extend({ @@ -43,7 +43,9 @@ define('controllers/address-map', 'controller', function (Dep) { model.id = o.id; model.fetch().then( function () { - var viewName = this.getMetadata().get(['AddressMap', 'view']) || 'views/address-map/view'; + var viewName = this.getMetadata().get(['AddressMap', 'view']) || + 'views/address-map/view'; + this.main(viewName, { model: model, field: o.field, @@ -53,6 +55,5 @@ define('controllers/address-map', 'controller', function (Dep) { }.bind(this) ); }, - }); }); diff --git a/client/src/controllers/admin.js b/client/src/controllers/admin.js index fe7ebc7304..a3a6cd6c82 100644 --- a/client/src/controllers/admin.js +++ b/client/src/controllers/admin.js @@ -26,10 +26,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/admin', ['controller', 'search-manager', 'lib!underscore'], function (Dep, SearchManager, _) { +define('controllers/admin', ['controller', 'search-manager', 'lib!underscore'], +function (Dep, /** typeof module:search-manager.Class */SearchManager, _) { - return Dep.extend({ + /** + * @class + * @name Class + * @memberOf module:controllers/admin + * @extends module:controller.Class + */ + return Dep.extend(/** @lends module:controllers/admin.Class# */{ + /** + * @inheritDoc + */ checkAccessGlobal: function () { if (this.getUser().isAdmin()) { return true; @@ -271,6 +281,9 @@ define('controllers/admin', ['controller', 'search-manager', 'lib!underscore'], this.main('views/admin/system-requirements/index'); }, + /** + * @returns {module:models/settings.Class} + */ getSettingsModel: function () { let model = this.getConfig().clone(); model.defs = this.getConfig().defs; @@ -408,6 +421,9 @@ define('controllers/admin', ['controller', 'search-manager', 'lib!underscore'], }); }, + /** + * @returns {Object|null} + */ getPageDefs: function (page) { let panelsDefs = this.getMetadata().get(['app', 'adminPanel']) || {}; diff --git a/client/src/controllers/api-user.js b/client/src/controllers/api-user.js index 5bb6b8babe..332c2b937f 100644 --- a/client/src/controllers/api-user.js +++ b/client/src/controllers/api-user.js @@ -26,15 +26,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/api-user', 'controllers/record', function (Dep) { +define('controllers/api-user', ['controllers/record'], function (Dep) { - return Dep.extend({ + /** + * @class + * @name Class + * @extends module:controllers/record.Class + * @memberOf module:controllers/api-user + */ + return Dep.extend(/** @lends module:controllers/api-user.Class# */{ entityType: 'User', getCollection: function (callback, context, usePreviouslyFetched) { - context = context || this; - Dep.prototype.getCollection.call(this, function (collection) { + return Dep.prototype.getCollection.call(this, (collection) => { collection.data.userType = 'api'; callback.call(context, collection); @@ -59,6 +64,5 @@ define('controllers/api-user', 'controllers/record', function (Dep) { options.attributes.type = 'api'; Dep.prototype.actionCreate.call(this, options); }, - }); }); diff --git a/client/src/controllers/dashboard.js b/client/src/controllers/dashboard.js index eca1fc1b1f..256d8f5714 100644 --- a/client/src/controllers/dashboard.js +++ b/client/src/controllers/dashboard.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/dashboard', 'controller', function (Dep) { +define('controllers/dashboard', ['controller'], function (Dep) { return Dep.extend({ @@ -35,11 +35,9 @@ define('controllers/dashboard', 'controller', function (Dep) { actionIndex: function () { this.main('views/dashboard', { displayTitle: true, - }, function (view) { + }, (view) => { view.render(); }); - } - + }, }); - }); diff --git a/client/src/controllers/email-account.js b/client/src/controllers/email-account.js index b1cb4db85b..f109752e75 100644 --- a/client/src/controllers/email-account.js +++ b/client/src/controllers/email-account.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/email-account', 'controllers/record', function (Dep) { +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 9e94630614..a8e3f65cf9 100644 --- a/client/src/controllers/email.js +++ b/client/src/controllers/email.js @@ -26,20 +26,21 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/email', 'controllers/record', function (Dep) { +define('controllers/email', ['controllers/record'], function (Dep) { return Dep.extend({ prepareModelView: function (model, options) { Dep.prototype.prepareModelView(model, options); - this.listenToOnce(model, 'after:send', function () { - var key = this.name + 'List'; - var stored = this.getStoredMainView(key); + + this.listenToOnce(model, 'after:send', () => { + let key = this.name + 'List'; + let stored = this.getStoredMainView(key); + if (stored) { this.clearStoredMainView(key); } - }, this); - } - + }); + }, }); }); diff --git a/client/src/controllers/external-account.js b/client/src/controllers/external-account.js index 8ca142f91c..14fa5fafd2 100644 --- a/client/src/controllers/external-account.js +++ b/client/src/controllers/external-account.js @@ -26,35 +26,37 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/external-account', 'controller', function (Dep) { +define('controllers/external-account', ['controller'], function (Dep) { return Dep.extend({ defaultAction: 'list', actionList: function (options) { - this.collectionFactory.create('ExternalAccount', function (collection) { - collection.once('sync', function () { + this.collectionFactory.create('ExternalAccount', (collection) => { + collection.once('sync', () => { this.main('ExternalAccount.Index', { collection: collection, }); - }, this); + }); + collection.fetch(); - }, this); + }); }, actionEdit: function (options) { - var id = options.id; + let id = options.id; - this.collectionFactory.create('ExternalAccount', function (collection) { - collection.once('sync', function () { + this.collectionFactory.create('ExternalAccount', (collection) => { + collection.once('sync', () => { this.main('ExternalAccount.Index', { collection: collection, - id: id + id: id, }); - }, this); + }); + collection.fetch(); - }, this); + }); }, }); }); diff --git a/client/src/controllers/home.js b/client/src/controllers/home.js index 8be6246438..e9ad005aa2 100644 --- a/client/src/controllers/home.js +++ b/client/src/controllers/home.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/home', 'controller', function (Dep) { +define('controllers/home', ['controller'], function (Dep) { return Dep.extend({ diff --git a/client/src/controllers/import.js b/client/src/controllers/import.js index 2bd9a5645e..8c88ae4067 100644 --- a/client/src/controllers/import.js +++ b/client/src/controllers/import.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/import', 'controllers/record', function (Dep) { +define('controllers/import', ['controllers/record'], function (Dep) { return Dep.extend({ diff --git a/client/src/controllers/inbound-email.js b/client/src/controllers/inbound-email.js index 7904efa681..79d413d845 100644 --- a/client/src/controllers/inbound-email.js +++ b/client/src/controllers/inbound-email.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/inbound-email', 'controllers/record', function (Dep) { +define('controllers/inbound-email', ['controllers/record'], function (Dep) { return Dep.extend({ @@ -34,6 +34,7 @@ define('controllers/inbound-email', 'controllers/record', function (Dep) { if (this.getUser().isAdmin()) { return true; } + return false; }, diff --git a/client/src/controllers/last-viewed.js b/client/src/controllers/last-viewed.js index 5dc311faa0..043a2da517 100644 --- a/client/src/controllers/last-viewed.js +++ b/client/src/controllers/last-viewed.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/last-viewed', 'controllers/record', function (Dep) { +define('controllers/last-viewed', ['controllers/record'], function (Dep) { return Dep.extend({ diff --git a/client/src/controllers/layout-set.js b/client/src/controllers/layout-set.js index a0ba04a2f3..b5b4a9d16f 100644 --- a/client/src/controllers/layout-set.js +++ b/client/src/controllers/layout-set.js @@ -26,13 +26,16 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/layout-set', 'controllers/record', function (Dep) { +define('controllers/layout-set', ['controllers/record'], function (Dep) { return Dep.extend({ actionEditLayouts: function (options) { var 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, diff --git a/client/src/controllers/lead-capture-opt-in-confirmation.js b/client/src/controllers/lead-capture-opt-in-confirmation.js index eebb940191..11e38d1208 100644 --- a/client/src/controllers/lead-capture-opt-in-confirmation.js +++ b/client/src/controllers/lead-capture-opt-in-confirmation.js @@ -26,31 +26,32 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/lead-capture-opt-in-confirmation', 'controller', function (Dep) { +define('controllers/lead-capture-opt-in-confirmation', ['controller'], function (Dep) { return Dep.extend({ actionOptInConfirmationSuccess: function (data) { - var viewName = this.getMetadata().get(['clientDefs', 'LeadCapture', 'optInConfirmationSuccessView']) || + var viewName = this.getMetadata() + .get(['clientDefs', 'LeadCapture', 'optInConfirmationSuccessView']) || 'views/lead-capture/opt-in-confirmation-success'; this.entire(viewName, { - resultData: data - }, function (view) { + resultData: data, + }, (view) => { view.render(); }); }, actionOptInConfirmationExpired: function (data) { - var viewName = this.getMetadata().get(['clientDefs', 'LeadCapture', 'optInConfirmationExpiredView']) || + var viewName = this.getMetadata() + .get(['clientDefs', 'LeadCapture', 'optInConfirmationExpiredView']) || 'views/lead-capture/opt-in-confirmation-expired'; this.entire(viewName, { resultData: data - }, function (view) { + }, (view) => { view.render(); }); - } - + }, }); }); diff --git a/client/src/controllers/notification.js b/client/src/controllers/notification.js index 376d7f17c9..32b935ebee 100644 --- a/client/src/controllers/notification.js +++ b/client/src/controllers/notification.js @@ -26,18 +26,16 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/notification', 'controller', function (Dep) { +define('controllers/notification', ['controller'], function (Dep) { return Dep.extend({ defaultAction: 'index', actionIndex: function () { - this.main('views/notification/list', { - }, function (view) { + this.main('views/notification/list', {}, (view) => { view.render(); }); - } - + }, }); }); diff --git a/client/src/controllers/page.js b/client/src/controllers/page.js index a3ddfd3773..665543e2c4 100644 --- a/client/src/controllers/page.js +++ b/client/src/controllers/page.js @@ -26,13 +26,14 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/page', 'controller', function (Dep) { +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 52df2ccc07..0e5461f652 100644 --- a/client/src/controllers/password-change-request.js +++ b/client/src/controllers/password-change-request.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/password-change-request', 'controller', function (Dep) { +define('controllers/password-change-request', ['controller'], function (Dep) { return Dep.extend({ diff --git a/client/src/controllers/portal-role.js b/client/src/controllers/portal-role.js index ff0b97f940..414a9ba8c9 100644 --- a/client/src/controllers/portal-role.js +++ b/client/src/controllers/portal-role.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/portal-role', 'controllers/record', function (Dep) { +define('controllers/portal-role', ['controllers/record'], function (Dep) { return Dep.extend({ @@ -34,9 +34,8 @@ define('controllers/portal-role', 'controllers/record', function (Dep) { if (this.getUser().isAdmin()) { return true; } + return false; - } - + }, }); - }); diff --git a/client/src/controllers/portal-user.js b/client/src/controllers/portal-user.js index 0d96246539..8a836151ce 100644 --- a/client/src/controllers/portal-user.js +++ b/client/src/controllers/portal-user.js @@ -26,15 +26,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/portal-user', 'controllers/record', function (Dep) { +define('controllers/portal-user', ['controllers/record'], function (Dep) { - return Dep.extend({ + /** + * @class + * @name Class + * @extends module:controllers/record.Class + * @memberOf module:controllers/portal-user + */ + return Dep.extend(/** @lends module:controllers/portal-user.Class# */{ entityType: 'User', getCollection: function (callback, context, usePreviouslyFetched) { - context = context || this; - Dep.prototype.getCollection.call(this, function (collection) { + return Dep.prototype.getCollection.call(this, (collection) => { collection.data.userType = 'portal'; callback.call(context, collection); @@ -45,11 +50,15 @@ define('controllers/portal-user', 'controllers/record', function (Dep) { if (!model.isPortal()) { if (model.isApi()) { this.getRouter().dispatch('ApiUser', 'view', {id: model.id, model: model}); + return; } + this.getRouter().dispatch('User', 'view', {id: model.id, model: model}); + return; } + Dep.prototype.createViewView.call(this, options, model, view); }, @@ -57,16 +66,15 @@ define('controllers/portal-user', 'controllers/record', function (Dep) { options = options || {}; options.attributes = options.attributes || {}; options.attributes.type = 'portal'; + Dep.prototype.actionCreate.call(this, options); }, checkAccess: function (action) { - if (this.getAcl().get('portalPermission') === 'yes') return true; return false; }, - }); }); diff --git a/client/src/controllers/preferences.js b/client/src/controllers/preferences.js index e3762000e9..58ff93b2bd 100644 --- a/client/src/controllers/preferences.js +++ b/client/src/controllers/preferences.js @@ -34,8 +34,10 @@ define('controllers/preferences', ['controllers/record', 'models/preferences'], getModel: function (callback) { var model = new Preferences(); + model.settings = this.getConfig(); model.defs = this.getMetadata().get('entityDefs.Preferences'); + if (callback) { callback.call(this, model); } @@ -54,6 +56,6 @@ define('controllers/preferences', ['controllers/record', 'models/preferences'], }); }, - actionList: function () {} + actionList: function () {}, }); }); diff --git a/client/src/controllers/record-tree.js b/client/src/controllers/record-tree.js index e712624e9b..e8c15dc8de 100644 --- a/client/src/controllers/record-tree.js +++ b/client/src/controllers/record-tree.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/record-tree', 'controllers/record', function (Dep) { +define('controllers/record-tree', ['controllers/record'], function (Dep) { return Dep.extend({ @@ -34,7 +34,9 @@ define('controllers/record-tree', 'controllers/record', function (Dep) { beforeView: function (options) { Dep.prototype.beforeView.call(this, options); + options = options || {}; + if (options.model) { options.model.unset('childCollection'); options.model.unset('childList'); @@ -53,7 +55,6 @@ define('controllers/record-tree', 'controllers/record', function (Dep) { collection: collection }); }); - } - + }, }); }); diff --git a/client/src/controllers/record.js b/client/src/controllers/record.js index 48a80e166a..04d9f8e45d 100644 --- a/client/src/controllers/record.js +++ b/client/src/controllers/record.js @@ -26,14 +26,33 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/record', 'controller', function (Dep) { +define('controllers/record', ['controller'], function (Dep) { - return Dep.extend({ + /** + * A record controller. + * + * @class + * @name Class + * @extends module:controller.Class + * @memberOf module:controllers/record + */ + return Dep.extend(/** @lends module:controllers/record.Class# */{ + /** + * A type => view-name map. + * @protected + * @type {Object.} + */ viewMap: null, + /** + * @inheritDoc + */ defaultAction: 'list', + /** + * @inheritDoc + */ checkAccess: function (action) { if (this.getAcl().check(this.name, action)) { return true; @@ -42,12 +61,32 @@ define('controllers/record', 'controller', function (Dep) { return false; }, + /** + * @inheritDoc + */ initialize: function () { + /** + * A type => view-name map. + * @protected + * @type {Object.} + */ this.viewMap = this.viewMap || {}; this.viewsMap = this.viewsMap || {}; + + /** + * @private + * @type {Object} + */ this.collectionMap = {}; }, + /** + * Get a view name/path. + * + * @protected + * @param {'list'|'detail'|'edit'|'create'} type A type. + * @returns {string} + */ getViewName: function (type) { return this.viewMap[type] || this.getMetadata().get(['clientDefs', this.name, 'views', type]) || @@ -93,7 +132,7 @@ define('controllers/record', 'controller', function (Dep) { }, createViewView: function (options, model, view) { - var view = view || this.getViewName('detail'); + view = view || this.getViewName('detail'); this.main(view, { scope: this.name, @@ -104,6 +143,11 @@ define('controllers/record', 'controller', function (Dep) { }); }, + /** + * @protected + * @param {module:model.Class} model + * @param {Object} options + */ prepareModelView: function (model, options) {}, actionView: function (options) { @@ -182,8 +226,13 @@ define('controllers/record', 'controller', function (Dep) { this.handleCheckAccess('create'); }, + /** + * @protected + * @param {module:model.Class} model + * @param {Object} options + */ prepareModelCreate: function (model, options) { - this.listenToOnce(model, 'before:save', function () { + this.listenToOnce(model, 'before:save', () => { var key = this.name + 'List'; var stored = this.getStoredMainView(key); @@ -191,7 +240,7 @@ define('controllers/record', 'controller', function (Dep) { if (stored && !stored.storeViewAfterCreate) { this.clearStoredMainView(key); } - }, this); + }); this.listenToOnce(model, 'after:save', () => { var key = this.name + 'List'; @@ -246,6 +295,11 @@ define('controllers/record', 'controller', function (Dep) { this.handleCheckAccess('edit'); }, + /** + * @protected + * @param {module:model.Class} model + * @param {Object} options + */ prepareModelEdit: function (model, options) { this.listenToOnce(model, 'before:save', () => { var key = this.name + 'List'; @@ -344,8 +398,13 @@ define('controllers/record', 'controller', function (Dep) { }, /** - * Get collection for the current controller. - * @param {collection}. + * Get a collection for the current controller. + * + * @protected + * @param {Function|null} [callback] + * @param {Object|null} [context] + * @param {boolean} [usePreviouslyFetched=false] Use a previously fetched. + * @return {Promise} */ getCollection: function (callback, context, usePreviouslyFetched) { context = context || this; @@ -354,34 +413,38 @@ define('controllers/record', 'controller', function (Dep) { throw new Error('No collection for unnamed controller'); } - var collectionName = this.entityType || this.name; + let collectionName = this.entityType || this.name; if (usePreviouslyFetched) { if (collectionName in this.collectionMap) { - var collection = this.collectionMap[collectionName]; + let collection = this.collectionMap[collectionName]; callback.call(context, collection); - return; + return Promise.resolve(collection); } } - return this.collectionFactory.create(collectionName, function (collection) { + return this.collectionFactory.create(collectionName, (collection) => { this.collectionMap[collectionName] = collection; - this.listenTo(collection, 'sync', function () { + this.listenTo(collection, 'sync', () => { collection.isFetched = true; - }, this); + }); if (callback) { callback.call(context, collection); } - }, context); + }); }, /** - * Get model for the current controller. - * @param {model}. + * Get a model for the current controller. + * + * @protected + * @param {Function} [callback] + * @param {Object} [context] + * @return {Promise} */ getModel: function (callback, context) { context = context || this; @@ -390,14 +453,13 @@ define('controllers/record', 'controller', function (Dep) { throw new Error('No collection for unnamed controller'); } - var modelName = this.entityType || this.name; + let modelName = this.entityType || this.name; - return this.modelFactory.create(modelName, function (model) { + return this.modelFactory.create(modelName, (model) => { if (callback) { callback.call(context, model); } - }, context); + }); }, - }); }); diff --git a/client/src/controllers/role.js b/client/src/controllers/role.js index 1babbaad6b..590247b7e7 100644 --- a/client/src/controllers/role.js +++ b/client/src/controllers/role.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/role', 'controllers/record', function (Dep) { +define('controllers/role', ['controllers/record'], function (Dep) { return Dep.extend({ @@ -34,8 +34,8 @@ define('controllers/role', 'controllers/record', function (Dep) { if (this.getUser().isAdmin()) { return true; } - return false; - } + return false; + }, }); }); diff --git a/client/src/controllers/stream.js b/client/src/controllers/stream.js index 4e520cd938..55c3b2d5d1 100644 --- a/client/src/controllers/stream.js +++ b/client/src/controllers/stream.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/stream', 'controller', function (Dep) { +define('controllers/stream', ['controller'], function (Dep) { return Dep.extend({ @@ -57,6 +57,5 @@ define('controllers/stream', 'controller', function (Dep) { view.render(); }); }, - }); }); diff --git a/client/src/controllers/team.js b/client/src/controllers/team.js index c31b27453e..ddee86fd75 100644 --- a/client/src/controllers/team.js +++ b/client/src/controllers/team.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/team', 'controllers/record', function (Dep) { +define('controllers/team', ['controllers/record'], function (Dep) { return Dep.extend({ @@ -34,10 +34,10 @@ define('controllers/team', 'controllers/record', function (Dep) { if (action == 'read') { return true; } + if (this.getUser().isAdmin()) { return true; } - } - + }, }); }); diff --git a/client/src/controllers/user.js b/client/src/controllers/user.js index f2e356247d..f7a3b28e54 100644 --- a/client/src/controllers/user.js +++ b/client/src/controllers/user.js @@ -26,13 +26,18 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('controllers/user', 'controllers/record', function (Dep) { +define('controllers/user', ['controllers/record'], function (Dep) { - return Dep.extend({ + /** + * @class + * @name Class + * @extends module:controllers/record.Class + * @memberOf module:controllers/user + */ + return Dep.extend(/** @lends module:controllers/user.Class */{ getCollection: function (callback, context, usePreviouslyFetched) { - context = context || this; - Dep.prototype.getCollection.call(this, function (collection) { + return Dep.prototype.getCollection.call(this, (collection) => { collection.data.userType = 'internal'; callback.call(context, collection); @@ -43,18 +48,23 @@ define('controllers/user', 'controllers/record', function (Dep) { if (model.get('deleted')) { view = 'views/deleted-detail'; Dep.prototype.createViewView.call(this, options, model, view); + return; } + if (model.isPortal()) { this.getRouter().dispatch('PortalUser', 'view', {id: model.id, model: model}); + return; } + if (model.isApi()) { this.getRouter().dispatch('ApiUser', 'view', {id: model.id, model: model}); + return; } + Dep.prototype.createViewView.call(this, options, model, view); }, - }); }); diff --git a/client/src/helpers/export.js b/client/src/helpers/export.js index 42531c7541..25f1867d24 100644 --- a/client/src/helpers/export.js +++ b/client/src/helpers/export.js @@ -26,15 +26,37 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('helpers/export', ['lib!espo'], function (Espo) { +define('helpers/export', [], function () { - return class { + /** + * An export helper. + * + * @memberOf module:helpers/export + */ + class Class { + /** + * @param {module:view.Class} view A view. + */ constructor(view) { + /** + * @private + * @type {module:view.Class} + */ this.view = view; + /** + * @private + * @type {module:models/settings.Class} + */ this.config = view.getConfig(); } + /** + * Check whether an export should be run in idle. + * + * @param {number} totalCount A total record count. + * @returns {boolean} + */ checkIsIdle(totalCount) { if (this.view.getUser().isPortal()) { return false; @@ -47,10 +69,17 @@ define('helpers/export', ['lib!espo'], function (Espo) { return totalCount === -1 || totalCount > this.config.get('exportIdleCountThreshold'); } + /** + * Process export. + * + * @param {string} id An ID. + * @returns {Promise} Resolves with a dialog view. + * The view emits the 'close:success' event. + */ process(id) { Espo.Ui.notify(false); - return new Promise((resolve) => { + return new Promise(resolve => { this.view .createView('dialog', 'views/export/modals/idle', { id: id, @@ -70,5 +99,7 @@ define('helpers/export', ['lib!espo'], function (Espo) { }); }); } - }; + } + + return Class; }); diff --git a/client/src/helpers/file-upload.js b/client/src/helpers/file-upload.js index 92eb9e89d8..a992495009 100644 --- a/client/src/helpers/file-upload.js +++ b/client/src/helpers/file-upload.js @@ -26,13 +26,41 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('helpers/file-upload', ['lib!espo'], function (Espo) { +define('helpers/file-upload', [], function () { - return class { + /** + * A file-upload helper. + * + * @memberOf module:helpers/file-upload + */ + class Class { + /** + * @param {module:models/settings.Class} config A config. + */ constructor(config) { + /** + * @private + * @type {module:models/settings.Class} + */ this.config = config; } + /** + * @typedef {Object} module:helpers/file-upload~Options + * + * @property {Function} [afterChunkUpload] After every chunk is uploaded. + * @property {Function} [afterAttachmentSave] After an attachment is saved. + * @property {{isCanceled?: boolean}} [mediator] A mediator. + */ + + /** + * Upload. + * + * @param {File} file A file. + * @param {module:model.Class} attachment An attachment model. + * @param {module:helpers/file-upload~Options} [options] Options. + * @returns {Promise} + */ upload(file, attachment, options) { options = options || {}; @@ -64,11 +92,13 @@ define('helpers/file-upload', ['lib!espo'], function (Espo) { }); } + /** + * @private + */ _uploadByChunks(file, attachment, options) { return new Promise((resolve, reject) => { attachment.set('isBeingUploaded', true); - // todo test catching attachment .save() .then(() => { @@ -86,6 +116,9 @@ define('helpers/file-upload', ['lib!espo'], function (Espo) { }); } + /** + * @private + */ _uploadChunks(file, attachment, resolve, reject, options, start) { start = start || 0; let end = start + this._getChunkSize() + 1; @@ -139,6 +172,9 @@ define('helpers/file-upload', ['lib!espo'], function (Espo) { fileReader.readAsDataURL(blob); } + /** + * @private + */ _useChunks(file) { let chunkSize = this._getChunkSize(); @@ -153,8 +189,13 @@ define('helpers/file-upload', ['lib!espo'], function (Espo) { return false; } + /** + * @private + */ _getChunkSize() { return (this.config.get('attachmentUploadChunkSize') || 0) * 1024 * 1024; } - }; + } + + return Class; }); diff --git a/client/src/helpers/mass-action.js b/client/src/helpers/mass-action.js index dcdb3e3bf4..7e24b58435 100644 --- a/client/src/helpers/mass-action.js +++ b/client/src/helpers/mass-action.js @@ -26,15 +26,37 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('helpers/mass-action', ['lib!espo'], function (Espo) { +define('helpers/mass-action', [], function () { - return class { + /** + * A mass-action helper. + * + * @memberOf module:helpers/mass-action + */ + class Class { + /** + * @param {module:view.Class} view A view. + */ constructor(view) { + /** + * @private + * @type {module:view.Class} + */ this.view = view; + /** + * @private + * @type {module:models/settings.Class} + */ this.config = view.getConfig(); } + /** + * Check whether an action should be run in idle. + * + * @param {number} totalCount A total record count. + * @returns {boolean} + */ checkIsIdle(totalCount) { if (this.view.getUser().isPortal()) { return false; @@ -47,10 +69,18 @@ define('helpers/mass-action', ['lib!espo'], function (Espo) { return totalCount === -1 || totalCount > this.config.get('massActionIdleCountThreshold'); } + /** + * Process. + * + * @param {string} id An ID. + * @param {string} action An action. + * @returns {Promise} Resolves with a dialog view. + * The view emits the 'close:success' event. + */ process(id, action) { Espo.Ui.notify(false); - return new Promise((resolve) => { + return new Promise(resolve => { this.view .createView('dialog', 'views/modals/mass-action', { id: id, @@ -71,5 +101,7 @@ define('helpers/mass-action', ['lib!espo'], function (Espo) { }); }); } - }; + } + + return Class; }); diff --git a/client/src/models/email.js b/client/src/models/email.js index e8ee6df347..af4f6487b0 100644 --- a/client/src/models/email.js +++ b/client/src/models/email.js @@ -26,9 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('models/email', 'model', function (Dep) { +define('models/email', ['model'], function (Dep) { - return Dep.extend({ - - }); + return Dep.extend({}); }); diff --git a/client/src/models/preferences.js b/client/src/models/preferences.js index c6e2804dbf..3d0a6d2211 100644 --- a/client/src/models/preferences.js +++ b/client/src/models/preferences.js @@ -28,18 +28,39 @@ define('models/preferences', ['model'], function (Dep) { - return Dep.extend({ + /** + * User preferences. + * + * @class + * @name Class + * @extends module:model.Class + * + * @memberOf module:models/preferences + */ + return Dep.extend(/** @lends module:models/preferences.Class# */{ + /** + * @inheritDoc + */ name: 'Preferences', - settings: null, - + /** + * Get dashlet options. + * + * @param {string} id A dashlet ID. + * @returns {Object|null} + */ getDashletOptions: function (id) { - var value = this.get('dashletsOptions') || {}; + let value = this.get('dashletsOptions') || {}; - return value[id] || false; + return value[id] || null; }, + /** + * Whether a user is portal. + * + * @returns {boolean} + */ isPortal: function () { return this.get('isPortalUser'); }, diff --git a/client/src/models/user.js b/client/src/models/user.js index 4a7261677f..1cf0dab7f8 100644 --- a/client/src/models/user.js +++ b/client/src/models/user.js @@ -26,34 +26,76 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('models/user', 'model', function (Dep) { +define('models/user', ['model'], function (Dep) { - return Dep.extend({ + /** + * A user. + * + * @class + * @name Class + * @extends module:model.Class + * + * @memberOf module:models/user + */ + return Dep.extend({/** @lends module:models/user.Class# */ + /** + * @inheritDoc + */ name: 'User', + /** + * Is admin. + * + * @returns {boolean} + */ isAdmin: function () { - return this.get('type') == 'admin' || this.isSuperAdmin(); + return this.get('type') === 'admin' || this.isSuperAdmin(); }, + /** + * Is portal. + * + * @returns {boolean} + */ isPortal: function () { - return this.get('type') == 'portal'; + return this.get('type') === 'portal'; }, + /** + * Is API. + * + * @returns {boolean} + */ isApi: function () { - return this.get('type') == 'api'; + return this.get('type') === 'api'; }, + /** + * Is regular. + * + * @returns {boolean} + */ isRegular: function () { - return this.get('type') == 'regular'; + return this.get('type') === 'regular'; }, + /** + * Is system. + * + * @returns {boolean} + */ isSystem: function () { - return this.get('type') == 'system'; + return this.get('type') === 'system'; }, + /** + * Is super-admin. + * + * @returns {boolean} + */ isSuperAdmin: function () { - return this.get('type') == 'super-admin'; + return this.get('type') === 'super-admin'; }, }); });