EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Task complete action use first completed status
Yuriic54948a9162a
diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Task.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Task.jsonindex 42d7f3f814..d7ab81d191 100644--- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Task.json+++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Task.json@@ -26,13 +26,24 @@"name": "setCompletedMain","iconHtml": "<span class=\"fas fa-check fa-sm\"></span>","acl": "edit",- "handler": "crm:handlers/task/menu",+ "handler": "modules/crm/handlers/task/menu","actionFunction": "complete","checkVisibilityFunction": "isCompleteAvailable"}]}},+ "detailActionList": [+ {+ "name": "complete",+ "labelTranslation": "Task.labels.Complete",+ "acl": "edit",+ "handler": "modules/crm/handlers/task/detail-actions",+ "actionFunction": "complete",+ "checkVisibilityFunction": "isCompleteAvailable",+ "iconClass": "fas fa-check"+ }+ ],"modalDetailActionList": [{"name": "complete",diff --git a/client/modules/crm/src/handlers/task/detail-actions.js b/client/modules/crm/src/handlers/task/detail-actions.jsindex 4be81cd98a..f5a1e4288f 100644--- a/client/modules/crm/src/handlers/task/detail-actions.js+++ b/client/modules/crm/src/handlers/task/detail-actions.js@@ -27,31 +27,61 @@************************************************************************/import ActionHandler from 'action-handler';+import {inject} from 'di';+import Metadata from 'metadata';+import Ui from 'ui';class DetailActions extends ActionHandler {- complete() {+ /**+ * @type {string[]}+ * @private+ */+ historyStatusList++ /**+ * @private+ * @type {string|null}+ */+ completedStatusValue++ @inject(Metadata)+ metadata++ constructor(view) {+ super(view);++ /** @var string[]*/+ const completedStatusList = this.metadata.get(`scopes.Task.completedStatusList`, []);++ this.historyStatusList = [+ ...completedStatusList,+ ...this.metadata.get(`scopes.Task.canceledStatusList`, []),+ ];++ this.completedStatusValue = completedStatusList[0] ?? null;+ }++ async complete() {const model = this.view.model;- model- .save({status: 'Completed'}, {patch: true})- .then(() => {- Espo.Ui.success(this.view.getLanguage().translateOption('Completed', 'status', 'Task'));- });+ Ui.notifyWait();+ await model.save({status: this.completedStatusValue}, {patch: true});- // Needed for calendar update.- this.view.trigger('after:save', model);+ Ui.success(this.view.getLanguage().translateOption('Completed', 'status', 'Task'));}// noinspection JSUnusedGlobalSymbols+ /**+ * @return {boolean}+ */isCompleteAvailable() {- const status = this.view.model.get('status');+ const status = this.view.model.attributes.status;- /** @type {string[]} */- const notActualStatuses = this.view.getMetadata().get('entityDefs.Task.fields.status.notActualOptions') || [];+ const view = /** @type {import('views/detail').default} */this.view;- return !notActualStatuses.includes(status);+ return !this.historyStatusList.includes(status);}}diff --git a/client/modules/crm/src/handlers/task/menu.js b/client/modules/crm/src/handlers/task/menu.jsindex f211836c70..e58ed9bae4 100644--- a/client/modules/crm/src/handlers/task/menu.js+++ b/client/modules/crm/src/handlers/task/menu.js@@ -27,34 +27,64 @@************************************************************************/import ActionHandler from 'action-handler';+import {inject} from 'di';+import Metadata from 'metadata';+import Ui from 'ui';-class TaskMenuHandler extends ActionHandler {+export default class TaskMenuHandler extends ActionHandler {- complete() {+ /**+ * @type {string[]}+ * @private+ */+ historyStatusList++ /**+ * @private+ * @type {string|null}+ */+ completedStatusValue++ @inject(Metadata)+ metadata++ constructor(view) {+ super(view);++ /** @var string[]*/+ const completedStatusList = this.metadata.get(`scopes.Task.completedStatusList`, []);++ this.historyStatusList = [+ ...completedStatusList,+ ...this.metadata.get(`scopes.Task.canceledStatusList`, []),+ ];++ this.completedStatusValue = completedStatusList[0] ?? null;+ }++ async complete() {const model = this.view.model;- model- .save({status: 'Completed'}, {patch: true})- .then(() => {- Espo.Ui.success(this.view.getLanguage().translateOption('Completed', 'status', 'Task'));- });+ Ui.notifyWait();++ await model.save({status: this.completedStatusValue}, {patch: true});++ Ui.success(this.view.getLanguage().translateOption('Completed', 'status', 'Task'));}// noinspection JSUnusedGlobalSymbols+ /**+ * @return {boolean}+ */isCompleteAvailable() {- const status = this.view.model.get('status');+ const status = this.view.model.attributes.status;- const view = /** @type {module:views/detail} */this.view;+ const view = /** @type {import('views/detail').default} */this.view;if (view.getRecordView().isEditMode()) {return false;}- /** @type {string[]} */- const notActualStatuses = this.view.getMetadata().get('entityDefs.Task.fields.status.notActualOptions') || [];-- return !notActualStatuses.includes(status);+ return !this.historyStatusList.includes(status);}}--export default TaskMenuHandler;diff --git a/client/modules/crm/src/views/task/record/detail.js b/client/modules/crm/src/views/task/record/detail.jsindex 2a993ddce2..f40dc0509b 100644--- a/client/modules/crm/src/views/task/record/detail.js+++ b/client/modules/crm/src/views/task/record/detail.js@@ -27,47 +27,5 @@************************************************************************/import DetailRecordView from 'views/record/detail';-import Ui from 'ui';-export default class TaskDetailRecordView extends DetailRecordView {-- setupActionItems() {- super.setupActionItems();-- this.dropdownItemList.push({- label: 'Complete',- name: 'setCompleted',- onClick: () => this.actionSetCompleted(),- iconClass: 'fas fa-check',- });-- const historyStatusList = [- ...this.getMetadata().get(`scopes.${this.entityType}.completedStatusList`, []),- ...this.getMetadata().get(`scopes.${this.entityType}.canceledStatusList`, []),- ]-- const control = () => {- if (- historyStatusList.includes(this.model.attributes.status) ||- !this.getAcl().checkModel(this.model, 'edit')- ) {- this.hideActionItem('setCompleted');- } else {- this.showActionItem('setCompleted');- }- };-- control();-- this.model.onSync({- owner: this,- callback: () => control(),- });- }-- async actionSetCompleted() {- await this.model.save({status: 'Completed'}, {patch: true});-- Ui.success(this.translate('Saved'));- }-}+export default class TaskDetailRecordView extends DetailRecordView {}