From 5c7b674b60d4bb52288e96b6c664e5fa548d1cce Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 3 Aug 2022 11:25:46 +0300 Subject: [PATCH] ref --- .../crm/src/views/record/panels/activities.js | 206 +++++++++--------- 1 file changed, 105 insertions(+), 101 deletions(-) diff --git a/client/modules/crm/src/views/record/panels/activities.js b/client/modules/crm/src/views/record/panels/activities.js index 76ef024c7d..8a62302392 100644 --- a/client/modules/crm/src/views/record/panels/activities.js +++ b/client/modules/crm/src/views/record/panels/activities.js @@ -26,9 +26,8 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define( - 'crm:views/record/panels/activities', - ['views/record/panels/relationship', 'multi-collection'], function (Dep, MultiCollection) { +define('crm:views/record/panels/activities', +['views/record/panels/relationship', 'multi-collection'], function (Dep, MultiCollection) { return Dep.extend({ @@ -49,8 +48,8 @@ define( action: 'composeEmail', label: 'Compose Email', acl: 'create', - aclScope: 'Email' - } + aclScope: 'Email', + }, ], listLayout: {}, @@ -59,12 +58,12 @@ define( rows: [ [ {name: 'ico', view: 'crm:views/fields/ico'}, - {name: 'name', link: true, view: 'views/event/fields/name-for-history'} + {name: 'name', link: true, view: 'views/event/fields/name-for-history'}, ], [ {name: 'assignedUser'}, - {name: 'dateStart'} - ] + {name: 'dateStart'}, + ], ] }, @@ -85,9 +84,9 @@ define( this.setupSorting(); - var actionList = []; + let actionList = []; - this.actionList.forEach(function (o) { + this.actionList.forEach(o => { if (o.aclScope) { if (this.getMetadata().get(['scopes', o.aclScope, 'disabled'])) { return; @@ -95,15 +94,15 @@ define( } actionList.push(o); - }, this); + }); this.actionList = actionList; - this.scopeList.forEach(function (item) { + this.scopeList.forEach(item => { if (!(item in this.listLayout)) { this.listLayout[item] = this.defaultListLayout; } - }, this); + }); this.url = this.serviceName + '/' + this.model.name + '/' + this.model.id + '/' + this.name; @@ -111,27 +110,27 @@ define( this.wait(true); - var i = 0; + let i = 0; - this.scopeList.forEach(function (scope) { - this.getModelFactory().getSeed(scope, function (seed) { + this.scopeList.forEach(scope => { + this.getModelFactory().getSeed(scope, seed => { this.seeds[scope] = seed; i++; - if (i == this.scopeList.length) { + if (i === this.scopeList.length) { this.wait(false); } - }.bind(this)); - }.bind(this)); + }); + }); - if (this.scopeList.length == 0) { + if (this.scopeList.length === 0) { this.wait(false); } this.filterList = []; - this.scopeList.forEach(function (item) { + this.scopeList.forEach(item => { if (!this.getAcl().check(item)) { return; } @@ -145,7 +144,7 @@ define( } this.filterList.push(item); - }, this); + }); if (this.filterList.length) { this.filterList.unshift('all'); @@ -168,11 +167,11 @@ define( this.setFilter(this.filter); - this.once('show', function () { + this.once('show', () => { if (!this.isRendered() && !this.isBeingRendered()) { this.collection.fetch(); } - }, this); + }); }, translateFilter: function (name) { @@ -188,7 +187,7 @@ define( }, setupActionList: function () { - this.scopeList.forEach(function (scope) { + this.scopeList.forEach(scope => { if (!this.getMetadata().get(['clientDefs', scope, 'activityDefs', this.name + 'Create'])) { return; } @@ -197,15 +196,15 @@ define( return; } - var o = { + let o = { action: 'createActivity', - html: this.translate((this.name === 'history' ? 'Log' : 'Schedule') + ' ' + scope, 'labels', scope), + html: this.translate((this.name === 'history' ?'Log' : 'Schedule') + ' ' + scope, 'labels', scope), data: {}, acl: 'create', aclScope: scope, }; - var link = this.getMetadata().get(['clientDefs', scope, 'activityDefs', 'link']) + let link = this.getMetadata().get(['clientDefs', scope, 'activityDefs', 'link']) if (link) { o.data.link = link; @@ -215,12 +214,11 @@ define( if (!this.model.hasLink(link)) { return; } - } else { o.data.scope = scope; + if ( - this.model.name !== 'User' - && + this.model.name !== 'User' && !this.checkParentTypeAvailability(scope, this.model.name) ) { return; @@ -230,20 +228,22 @@ define( this.createAvailabilityHash[scope] = true; o.data = o.data || {}; + if (!o.data.status) { - var statusList = this.getMetadata().get(['scopes', scope, this.name + 'StatusList']); + let statusList = this.getMetadata().get(['scopes', scope, this.name + 'StatusList']); + if (statusList && statusList.length) { o.data.status = statusList[0]; } } + this.createEntityTypeStatusMap[scope] = o.data.status; this.actionList.push(o); - }, this); - + }); }, setupFinalActionList: function () { - this.scopeList.forEach(function (scope, i) { + this.scopeList.forEach((scope, i) => { if (i === 0 && this.actionList.length) { this.actionList.push(false); } @@ -252,7 +252,7 @@ define( return; } - var o = { + let o = { action: 'viewRelatedList', html: this.translate('View List') + ' · ' + this.translate(scope, 'scopeNamesPlural') + '', data: { @@ -263,7 +263,7 @@ define( }; this.actionList.push(o); - }, this); + }); }, setFilter: function (filter) { @@ -277,7 +277,7 @@ define( }, afterRender: function () { - this.listenToOnce(this.collection, 'sync', function () { + let afterFetch = () => { this.createView('list', 'views/record/list-expanded', { el: this.getSelector() + ' > .list-container', pagination: false, @@ -285,33 +285,37 @@ define( rowActionsView: this.rowActionsView, checkboxes: false, collection: this.collection, - listLayout: this.listLayout - }, function (view) { + listLayout: this.listLayout, + }, (view) => { view.render(); - this.listenTo(view, 'after:save', function (m) { + this.listenTo(view, 'after:save', () => { this.fetchActivities(); this.fetchHistory(); - }, this); - }, this); - }, this); + }); + }); + }; if (!this.disabled) { - this.collection.fetch(); + this.collection + .fetch() + .then(() => afterFetch()); } else { - this.once('show', function () { - this.collection.fetch(); - }, this); + this.once('show', () => { + this.collection + .fetch() + .then(() => afterFetch()) + }); } }, fetchHistory: function () { - var parentView = this.getParentView(); + let parentView = this.getParentView(); if (parentView) { if (parentView.hasView('history')) { - var collection = parentView.getView('history').collection; + let collection = parentView.getView('history').collection; if (collection) { collection.fetch(); @@ -418,17 +422,18 @@ define( if (this.createEntityTypeStatusMap[data.scope]) { data.status = this.createEntityTypeStatusMap[data.scope]; } + this.actionCreateActivity(data); }, actionCreateActivity: function (data) { - var link = data.link; - var foreignLink; - var scope; + let link = data.link; + let foreignLink; + let scope; if (link) { - var scope = this.model.getLinkParam(link, 'entity'); - var foreignLink = this.model.getLinkParam(link, 'foreign'); + scope = this.model.getLinkParam(link, 'entity'); + foreignLink = this.model.getLinkParam(link, 'foreign'); } else { scope = data.scope; @@ -450,30 +455,31 @@ define( var viewName = this.getMetadata().get('clientDefs.' + scope + '.modalViews.edit') || 'views/modals/edit'; - this.getCreateActivityAttributes(scope, data, function (attributes) { + this.getCreateActivityAttributes(scope, data, attributes => { o.attributes = attributes; - this.createView('quickCreate', viewName, o , function (view) { + this.createView('quickCreate', viewName, o, (view) => { view.render(); view.notify(false); - this.listenToOnce(view, 'after:save', function () { + + this.listenToOnce(view, 'after:save', () => { this.model.trigger('after:relate'); this.collection.fetch(); this.fetchHistory(); - }, this); - }, this); + }); + }); }); - }, getComposeEmailAttributes: function (scope, data, callback) { data = data || {}; - var attributes = { + + let attributes = { status: 'Draft', to: this.model.get('emailAddress') }; - if (this.model.name == 'Contact') { + if (this.model.name === 'Contact') { if (this.getConfig().get('b2cMode')) { attributes.parentType = 'Contact'; attributes.parentName = this.model.get('name'); @@ -487,7 +493,7 @@ define( } } } - else if (this.model.name == 'Lead') { + else if (this.model.name === 'Lead') { attributes.parentType = 'Lead', attributes.parentId = this.model.id attributes.parentName = this.model.get('name'); @@ -515,39 +521,41 @@ define( } } - var emailKeepParentTeamsEntityList = this.getConfig().get('emailKeepParentTeamsEntityList') || []; + let emailKeepParentTeamsEntityList = this.getConfig().get('emailKeepParentTeamsEntityList') || []; if ( - attributes.parentType - && - attributes.parentType === this.model.name - && - ~emailKeepParentTeamsEntityList.indexOf(attributes.parentType) - && this.model.get('teamsIds') && this.model.get('teamsIds').length + attributes.parentType && + attributes.parentType === this.model.name && + ~emailKeepParentTeamsEntityList.indexOf(attributes.parentType) && + this.model.get('teamsIds') && + this.model.get('teamsIds').length ) { attributes.teamsIds = Espo.Utils.clone(this.model.get('teamsIds')); attributes.teamsNames = Espo.Utils.clone(this.model.get('teamsNames') || {}); - var defaultTeamId = this.getUser().get('defaultTeamId'); + let defaultTeamId = this.getUser().get('defaultTeamId'); if (defaultTeamId && !~attributes.teamsIds.indexOf(defaultTeamId)) { attributes.teamsIds.push(defaultTeamId); attributes.teamsNames[defaultTeamId] = this.getUser().get('defaultTeamName'); } - attributes.teamsIds = attributes.teamsIds.filter(function (teamId) { - return this.getAcl().checkTeamAssignmentPermission(teamId); - }, this); + attributes.teamsIds = attributes.teamsIds + .filter(teamId => { + return this.getAcl().checkTeamAssignmentPermission(teamId); + }); } + callback.call(this, attributes); }, actionComposeEmail: function (data) { - var self = this; - var link = 'emails'; - var scope = 'Email'; + let self = this; + let link = 'emails'; + let scope = 'Email'; + + let relate = null; - var relate = null; if ('emails' in this.model.defs['links']) { relate = { model: this.model, @@ -557,21 +565,21 @@ define( this.notify('Loading...'); - this.getComposeEmailAttributes(scope, data, function (attributes) { + this.getComposeEmailAttributes(scope, data, attributes => { this.createView('quickCreate', 'views/modals/compose-email', { relate: relate, - attributes: attributes - }, function (view) { + attributes: attributes, + }, (view) => { view.render(); view.notify(false); - this.listenToOnce(view, 'after:save', function () { + + this.listenToOnce(view, 'after:save', () => { this.collection.fetch(); this.model.trigger('after:relate'); this.fetchHistory(); - }, this); - }, this); + }); + }); }); - }, actionRefresh: function () { @@ -579,42 +587,38 @@ define( }, actionSetHeld: function (data) { - var id = data.id; + let id = data.id; if (!id) { return; } - var model = this.collection.get(id); + let model = this.collection.get(id); - model.save({ - status: 'Held' - }, { + model.save({status: 'Held'}, { patch: true, - success: function () { + success: () => { this.collection.fetch(); this.fetchHistory(); - }.bind(this) + }, }); }, actionSetNotHeld: function (data) { - var id = data.id; + let id = data.id; if (!id) { return; } - var model = this.collection.get(id); + let model = this.collection.get(id); - model.save({ - status: 'Not Held' - }, { + model.save({status: 'Not Held'}, { patch: true, - success: function () { + success: () => { this.collection.fetch(); this.fetchHistory(); - }.bind(this) + }, }); }, @@ -623,7 +627,7 @@ define( this.model.id + '/' + this.name + '/list/' + data.scope; data.title = this.translate(this.defs.label) + - ' @right ' + this.translate(data.scope, 'scopeNamesPlural'); + ' @right ' + this.translate(data.scope, 'scopeNamesPlural'); data.viewOptions = data.viewOptions || {}; data.viewOptions.massUnlinkDisabled = true;