From c28ba84f032f85ca334f6b7ee4a6a66895ea4555 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 27 Sep 2024 19:20:38 +0300 Subject: [PATCH] email: fix collection trash/archive sync --- client/src/views/email/list.js | 4 ++ client/src/views/email/record/detail.js | 6 +-- client/src/views/email/record/list.js | 53 ++++++++++++++++++++----- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/client/src/views/email/list.js b/client/src/views/email/list.js index 77d1d006fd..9179703629 100644 --- a/client/src/views/email/list.js +++ b/client/src/views/email/list.js @@ -374,6 +374,10 @@ class EmailListView extends ListView { this.applyRoutingParams(params); this.initDroppable(); this.initStickableFolders(); + + const recordView = /** @type {import('views/email/record/list').default} */this.getRecordView(); + + recordView.removeQueuedRecord(); } /** diff --git a/client/src/views/email/record/detail.js b/client/src/views/email/record/detail.js index 67e3ecd4cf..34e80c62c6 100644 --- a/client/src/views/email/record/detail.js +++ b/client/src/views/email/record/detail.js @@ -300,7 +300,7 @@ class EmailDetailRecordView extends DetailRecordView { this.model.set('inTrash', true); if (this.model.collection) { - this.model.collection.trigger('moving-to-trash', this.model.id); + this.model.collection.trigger('moving-to-trash', this.model.id, true); } } @@ -313,7 +313,7 @@ class EmailDetailRecordView extends DetailRecordView { this.model.set('inTrash', false); if (this.model.collection) { - this.model.collection.trigger('retrieving-from-trash', this.model.id); + this.model.collection.trigger('retrieving-from-trash', this.model.id, true); } } @@ -352,7 +352,7 @@ class EmailDetailRecordView extends DetailRecordView { Espo.Ui.info(this.translate('Moved to Archive', 'labels', 'Email')); if (this.model.collection) { - this.model.collection.trigger('moving-to-archive', this.model.id); + this.model.collection.trigger('moving-to-archive', this.model.id, true); } }); } diff --git a/client/src/views/email/record/list.js b/client/src/views/email/record/list.js index c6a24fb48b..7caa79761c 100644 --- a/client/src/views/email/record/list.js +++ b/client/src/views/email/record/list.js @@ -40,6 +40,12 @@ class EmailListRecordView extends ListRecordView { 'massUpdate', ] + /** + * @type {string[]} + * @private + */ + toRemoveIdList + setup() { super.setup(); @@ -64,7 +70,7 @@ class EmailListRecordView extends ListRecordView { this.listenTo(this.collection, 'select-folder', () => this.controlEmailMassActionsVisibility()); } - this.listenTo(this.collection, 'moving-to-trash', (id) => { + this.listenTo(this.collection, 'moving-to-trash', (id, keep) => { const model = this.collection.get(id); if (model) { @@ -72,11 +78,17 @@ class EmailListRecordView extends ListRecordView { } if (this.collection.selectedFolderId !== 'trash' && this.collection.selectedFolderId !== 'all') { + if (keep) { + this.toRemoveIdList.push(id); + + return; + } + this.removeRecordFromList(id); } }); - this.listenTo(this.collection, 'retrieving-from-trash', (id) => { + this.listenTo(this.collection, 'retrieving-from-trash', (id, keep) => { const model = this.collection.get(id); if (model) { @@ -84,11 +96,17 @@ class EmailListRecordView extends ListRecordView { } if (this.collection.selectedFolderId === 'trash') { + if (keep) { + this.toRemoveIdList.push(id); + + return; + } + this.removeRecordFromList(id); } }); - this.listenTo(this.collection, 'moving-to-archive', id => { + this.listenTo(this.collection, 'moving-to-archive', (id, keep) => { const model = this.collection.get(id); if (model) { @@ -96,9 +114,24 @@ class EmailListRecordView extends ListRecordView { } if (this.collection.selectedFolderId !== 'archive') { + if (keep) { + this.toRemoveIdList.push(id); + + return; + } + this.removeRecordFromList(id); } }); + + this.toRemoveIdList = []; + } + + /** + * @internal + */ + removeQueuedRecord() { + this.toRemoveIdList.forEach(id => this.removeRecordFromList(id)); } // noinspection JSUnusedGlobalSymbols @@ -194,7 +227,7 @@ class EmailListRecordView extends ListRecordView { } ids.forEach(id => { - this.collection.trigger('moving-to-trash', id, this.collection.get(id)); + this.collection.trigger('moving-to-trash', id); this.uncheckRecord(id, null, true); }); @@ -219,7 +252,7 @@ class EmailListRecordView extends ListRecordView { } ids.forEach(id => { - this.collection.trigger('retrieving-from-trash', id, this.collection.get(id)); + this.collection.trigger('retrieving-from-trash', id); this.uncheckRecord(id, null, true); }); @@ -259,7 +292,7 @@ class EmailListRecordView extends ListRecordView { if (folderId === 'archive') { [...this.checkedList].forEach(id => { - this.collection.trigger('moving-to-archive', id, this.collection.get(id)); + this.collection.trigger('moving-to-archive', id); this.uncheckRecord(id, null, true); }); @@ -358,7 +391,7 @@ class EmailListRecordView extends ListRecordView { .then(() => { Espo.Ui.warning(this.translate('Moved to Trash', 'labels', 'Email')); - this.collection.trigger('moving-to-trash', id, this.collection.get(id)); + this.collection.trigger('moving-to-trash', id); }); } @@ -372,7 +405,7 @@ class EmailListRecordView extends ListRecordView { .then(() => { Espo.Ui.warning(this.translate('Retrieved from Trash', 'labels', 'Email')); - this.collection.trigger('retrieving-from-trash', id, this.collection.get(id)); + this.collection.trigger('retrieving-from-trash', id); }); } @@ -395,7 +428,7 @@ class EmailListRecordView extends ListRecordView { .deleteRequest('Email/inbox/inTrash', {ids: ids}) .then(() => { ids.forEach(id => { - this.collection.trigger('retrieving-from-trash', id, this.collection.get(id)); + this.collection.trigger('retrieving-from-trash', id); }); return Espo.Ajax @@ -446,7 +479,7 @@ class EmailListRecordView extends ListRecordView { this.moveToFolder(id, folderId) .then(() => { if (folderId === 'archive') { - this.collection.trigger('moving-to-archive', id, this.collection.get(id)); + this.collection.trigger('moving-to-archive', id); Espo.Ui.info(this.translate('Moved to Archive', 'labels', 'Email'));