email list detail sync

This commit is contained in:
Yuri Kuznetsov
2025-05-06 18:11:08 +03:00
parent 68f568949e
commit ffbe6f5efa
3 changed files with 38 additions and 11 deletions
+11 -11
View File
@@ -101,12 +101,12 @@ class EmailDetailRecordView extends DetailRecordView {
this.listenTo(this.model, 'change:status', () => this.controlSendButton());
if (this.model.get('status') !== 'Draft' && this.model.has('isRead') && !this.model.get('isRead')) {
this.model.set('isRead', true);
this.model.set('isRead', true, {sync: true});
}
this.listenTo(this.model, 'sync', () => {
if (!this.model.get('isRead') && this.model.get('status') !== 'Draft') {
this.model.set('isRead', true);
this.model.set('isRead', true, {sync: true});
}
});
@@ -303,13 +303,13 @@ class EmailDetailRecordView extends DetailRecordView {
actionMarkAsImportant() {
Espo.Ajax.postRequest('Email/inbox/important', {id: this.model.id});
this.model.set('isImportant', true);
this.model.set('isImportant', true, {sync: true});
}
actionMarkAsNotImportant() {
Espo.Ajax.deleteRequest('Email/inbox/important', {id: this.model.id});
this.model.set('isImportant', false);
this.model.set('isImportant', false, {sync: true});
}
actionMoveToTrash() {
@@ -318,9 +318,9 @@ class EmailDetailRecordView extends DetailRecordView {
});
if (this.model.attributes.groupFolderId) {
this.model.set('groupStatusFolder', 'Trash');
this.model.set('groupStatusFolder', 'Trash', {sync: true});
} else {
this.model.set('inTrash', true);
this.model.set('inTrash', true, {sync: true});
}
if (this.model.collection) {
@@ -334,10 +334,10 @@ class EmailDetailRecordView extends DetailRecordView {
Espo.Ui.warning(this.translate('Retrieved from Trash', 'labels', 'Email'));
});
this.model.set('inTrash', false);
this.model.set('inTrash', false, {sync: true});
if (this.model.attributes.groupFolderId) {
this.model.set('groupStatusFolder', null);
this.model.set('groupStatusFolder', null, {sync: true});
}
if (this.model.collection) {
@@ -406,8 +406,8 @@ class EmailDetailRecordView extends DetailRecordView {
Espo.Ajax.postRequest(`Email/inbox/folders/archive`, {id: this.model.id})
.then(() => {
this.model.attributes.groupFolderId ?
this.model.set('groupStatusFolder', 'Archive') :
this.model.set('inArchive', true);
this.model.set('groupStatusFolder', 'Archive', {sync: true}) :
this.model.set('inArchive', true, {sync: true});
Espo.Ui.info(this.translate('Moved to Archive', 'labels', 'Email'));
@@ -576,7 +576,7 @@ class EmailDetailRecordView extends DetailRecordView {
actionSend() {
this.send()
.then(() => {
this.model.set('status', 'Sent');
this.model.set('status', 'Sent', {sync: true});
if (this.mode !== this.MODE_DETAIL) {
this.setDetailMode();
+6
View File
@@ -46,6 +46,12 @@ class EmailListRecordView extends ListRecordView {
*/
toRemoveIdList
collectionEventSyncList = [
'moving-to-trash',
'retrieving-from-trash',
'moving-to-archive',
]
setup() {
super.setup();
+21
View File
@@ -599,6 +599,13 @@ class ListRecordView extends View {
*/
_columnResizeHelper
/**
* @protected
* @type {string[]}
* @since 9.1.1
*/
collectionEventSyncList
/** @inheritDoc */
events = {
/**
@@ -1046,6 +1053,12 @@ class ListRecordView extends View {
this.headerDisabled = this.options.headerDisabled || this.headerDisabled;
this.noDataDisabled = this.options.noDataDisabled || this.noDataDisabled;
if (!this.collectionEventSyncList) {
this.collectionEventSyncList = [];
} else {
this.collectionEventSyncList = [...this.collectionEventSyncList];
}
if (!this.headerDisabled) {
this.header = _.isUndefined(this.options.header) ? this.header : this.options.header;
} else {
@@ -2177,6 +2190,14 @@ class ListRecordView extends View {
model: collection.get(id),
};
if (this.collectionEventSyncList) {
this.listenTo(collection, 'all', (event, ...parameters) => {
if (this.collectionEventSyncList.includes(event)) {
this.collection.trigger(event, ...parameters);
}
});
}
this.listenTo(collection, 'model-sync', (/** Model */m, /** Record */o) => {
if (o.action === 'destroy') {
this.removeRecordFromList(m.id);