EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
before:delete event, after:delete
Yuri Kuznetsov46db6c22601b
diff --git a/client/modules/crm/src/views/calendar/calendar.js b/client/modules/crm/src/views/calendar/calendar.jsindex 02d17da495..eed91a6898 100644--- a/client/modules/crm/src/views/calendar/calendar.js+++ b/client/modules/crm/src/views/calendar/calendar.js@@ -161,6 +161,7 @@ class CalendarView extends View {* height?: number,* enabledScopeList?: string[],* header?: boolean,+ * onSave?: function(),* }} options*/constructor(options) {@@ -930,7 +931,9 @@ class CalendarView extends View {eventClick: async info => {const event = info.event;+ /** @type {string} */const scope = event.extendedProps.scope;+ /** @type {string} */const recordId = event.extendedProps.recordId;const helper = new RecordModal();@@ -942,6 +945,16 @@ class CalendarView extends View {entityType: scope,id: recordId,removeDisabled: false,+ beforeSave: () => {+ if (this.options.onSave) {+ this.options.onSave();+ }+ },+ beforeDestroy: () => {+ if (this.options.onSave) {+ this.options.onSave();+ }+ },afterSave: (model, o) => {if (!o.bypassClose) {modalView.close();@@ -970,7 +983,7 @@ class CalendarView extends View {this.fetchEvents(fromStr, toStr, callback);},- eventDrop: info => {+ eventDrop: async info => {const event = /** @type {EventImpl} */info.event;const delta = info.delta;@@ -1049,21 +1062,26 @@ class CalendarView extends View {Espo.Ui.notify(this.translate('saving', 'messages'));- this.getModelFactory().create(scope, model => {- model.id = props.recordId;+ const model = await this.getModelFactory().create(scope);+ model.id = props.recordId;- model.save(attributes, {patch: true})- .then(() => {- Espo.Ui.notify(false);+ if (this.options.onSave) {+ this.options.onSave();+ }- this.applyPropsToEvent(event, props);- })- .catch(() => {- info.revert();- });- });+ try {+ await model.save(attributes, {patch: true});+ } catch (e) {+ info.revert();++ return;+ }++ Espo.Ui.notify();++ this.applyPropsToEvent(event, props);},- eventResize: info => {+ eventResize: async info => {const event = info.event;const attributes = {@@ -1074,20 +1092,25 @@ class CalendarView extends View {Espo.Ui.notify(this.translate('saving', 'messages'));- this.getModelFactory().create(event.extendedProps.scope, model => {- model.id = event.extendedProps.recordId;+ const model = await this.getModelFactory().create(event.extendedProps.scope);+ model.id = event.extendedProps.recordId;- model.save(attributes, {patch: true})- .then(() => {- Espo.Ui.notify(false);+ if (this.options.onSave) {+ this.options.onSave();+ }- event.setExtendedProp('dateEnd', attributes.dateEnd);- event.setExtendedProp('duration', duration);- })- .catch(() => {- info.revert();- });- });+ try {+ await model.save(attributes, {patch: true})+ } catch (e) {+ info.revert();++ return;+ }++ Espo.Ui.notify();++ event.setExtendedProp('dateEnd', attributes.dateEnd);+ event.setExtendedProp('duration', duration);},eventAllow: (info, event) => {if (event.allDay && !info.allDay) {@@ -1206,7 +1229,7 @@ class CalendarView extends View {* [dateEndDate]: ?string,* }} [values]*/- createEvent(values) {+ async createEvent(values) {values = values || {};if (@@ -1228,7 +1251,7 @@ class CalendarView extends View {Espo.Ui.notifyWait();- this.createView('quickEdit', 'crm:views/calendar/modals/edit', {+ const view = await this.createView('dialog', 'crm:views/calendar/modals/edit', {attributes: attributes,enabledScopeList: this.enabledScopeList,scopeList: this.scopeList,@@ -1237,24 +1260,30 @@ class CalendarView extends View {dateEndDate: values.dateEndDate,dateStart: values.dateStart,dateEnd: values.dateEnd,- }, view => {- view.render();+ });- Espo.Ui.notify(false);+ let added = false;- let added = false;+ this.listenTo(view, 'before:save', () => {+ if (this.options.onSave) {+ this.options.onSave();+ }+ });- this.listenTo(view, 'after:save', model => {- if (!added) {- this.addModel(model);- added = true;+ this.listenTo(view, 'after:save', model => {+ if (!added) {+ this.addModel(model);+ added = true;- return;- }+ return;+ }- this.updateModel(model);- });+ this.updateModel(model);});++ await view.render();++ Espo.Ui.notify();}/**diff --git a/client/modules/crm/src/views/calendar/modals/edit.js b/client/modules/crm/src/views/calendar/modals/edit.jsindex 9af91ae9b5..01caa453e4 100644--- a/client/modules/crm/src/views/calendar/modals/edit.js+++ b/client/modules/crm/src/views/calendar/modals/edit.js@@ -264,7 +264,8 @@ class CalenderEditModalView extends EditModalView {model.destroy().then(() => {- this.trigger('after:destroy', model);+ this.trigger('after:delete', model);+this.dialog.close();}).catch(() => {diff --git a/client/modules/crm/src/views/calendar/timeline.js b/client/modules/crm/src/views/calendar/timeline.jsindex 5bb389f23d..5d416c6c12 100644--- a/client/modules/crm/src/views/calendar/timeline.js+++ b/client/modules/crm/src/views/calendar/timeline.js@@ -136,6 +136,7 @@ class TimelineView extends View {* calendarType?: string,* userList?: string[],* header?: boolean,+ * onSave?: function(),* }} options*/constructor(options) {@@ -660,7 +661,12 @@ class TimelineView extends View {});}- createEvent(dateStart, userId) {+ /**+ * @private+ * @param {string} dateStart+ * @param {string} [userId]+ */+ async createEvent(dateStart, userId) {if (!dateStart) {const time = (this.timeline.getWindow().end - this.timeline.getWindow().start) / 2 +this.timeline.getWindow().start;@@ -693,18 +699,23 @@ class TimelineView extends View {Espo.Ui.notifyWait();- this.createView('quickEdit', 'crm:views/calendar/modals/edit', {+ const view = await this.createView('dialog', 'crm:views/calendar/modals/edit', {attributes: attributes,enabledScopeList: this.enabledScopeList,scopeList: this.scopeList- }, (view) => {- view.render();- view.notify(false);+ });- this.listenTo(view, 'after:save', () => {- this.runFetch();- });+ this.listenTo(view, 'before:save', () => {+ if (this.options.onSave) {+ this.options.onSave();+ }});++ this.listenTo(view, 'after:save', () => this.runFetch());++ await view.render();++ Espo.Ui.notify();}/**@@ -722,6 +733,16 @@ class TimelineView extends View {entityType: scope,id: id,removeDisabled: false,+ beforeSave: () => {+ if (this.options.onSave) {+ this.options.onSave();+ }+ },+ beforeDestroy: () => {+ if (this.options.onSave) {+ this.options.onSave();+ }+ },afterSave: (model, o) => {if (!o.bypassClose) {modalView.close();diff --git a/client/src/helpers/record-modal.js b/client/src/helpers/record-modal.jsindex 7d505ff58f..e1e73e5b6f 100644--- a/client/src/helpers/record-modal.js+++ b/client/src/helpers/record-modal.js@@ -88,7 +88,9 @@ class RecordModalHelper {* rootUrl?: string,* fullFormUrl?: string,* layoutName?: string,+ * beforeSave?: function(import('model').default, Record),* afterSave?: function(import('model').default, {bypassClose: boolean} & Record),+ * beforeDestroy?: function(import('model').default),* afterDestroy?: function(import('model').default),* beforeRender?: function(import('views/modals/detail').default),* onClose?: function(),@@ -139,14 +141,24 @@ class RecordModalHelper {// @todo Revise.view.listenToOnce(modalView, 'remove', () => view.clearView('modal'));+ if (params.beforeSave) {+ modalView.listenTo(modalView, 'before:save', (model, o) => {+ params.beforeSave(model, o);+ });+ }+if (params.afterSave) {modalView.listenTo(modalView, 'after:save', (model, /** Record */o) => {params.afterSave(model, {...o});});}+ if (params.beforeDestroy) {+ modalView.listenToOnce(modalView, 'before:delete', model => params.beforeDestroy(model));+ }+if (params.afterDestroy) {- modalView.listenToOnce(modalView, 'after:destroy', model => params.afterDestroy(model));+ modalView.listenToOnce(modalView, 'after:delete', model => params.afterDestroy(model));}if (params.beforeRender) {@@ -177,6 +189,7 @@ class RecordModalHelper {* fullFormUrl?: string,* returnUrl?: string,* layoutName?: string,+ * beforeSave?: function(import('model').default, Record),* afterSave?: function(import('model').default, {bypassClose: boolean} & Record),* beforeRender?: function(import('views/modals/edit').default),* onClose?: function(),@@ -240,6 +253,12 @@ class RecordModalHelper {// @todo Revise.modalView.listenToOnce(modalView, 'remove', () => view.clearView('modal'));+ if (params.beforeSave) {+ modalView.listenTo(modalView, 'before:save', (model, o) => {+ params.beforeSave(model, o);+ });+ }+if (params.afterSave) {modalView.listenTo(modalView, 'after:save', (model, /** Record */o) => {params.afterSave(model, {...o});diff --git a/client/src/views/modals/detail.js b/client/src/views/modals/detail.jsindex 6a5f5b44d0..ab8bd18257 100644--- a/client/src/views/modals/detail.js+++ b/client/src/views/modals/detail.js@@ -645,6 +645,9 @@ class DetailModalView extends ModalView {id: this.id,fullFormDisabled: this.fullFormDisabled,collapseDisabled: true,+ beforeSave: (model, o) => {+ this.trigger('before:save', model, o);+ },afterSave: (model, o) => {this.model.set(model.getClonedAttributes());@@ -678,9 +681,13 @@ class DetailModalView extends ModalView {$buttons.addClass('disabled').attr('disabled', 'disabled');+ this.trigger('before:delete', model);+model.destroy().then(() => {- this.trigger('after:destroy', model);+ this.trigger('after:delete', model);+ this.trigger('after:destroy', model); // For bc.+this.dialog.close();Espo.Ui.success(this.translate('Removed'));