[IMP] mail: move _onChatterRendered to community

This will reduce the overrides in enterprise.

Part of task-2871070

Part-of: odoo/odoo#95218
This commit is contained in:
Sébastien Theys
2022-07-04 18:53:20 +02:00
parent b9abc680d9
commit 9c0a2df0ff
@@ -1,6 +1,7 @@
/** @odoo-module **/
import { ChatterContainer } from '@mail/components/chatter_container/chatter_container';
import { AttachmentViewer } from '@mail/widgets/attachment_viewer/attachment_viewer';
import dom from 'web.dom';
import FormRenderer from 'web.FormRenderer';
@@ -47,6 +48,7 @@ FormRenderer.include({
* when applying the rendering into the DOM.
*/
this.chatterContainerTargetPlaceholder = undefined;
this.attachmentViewer = undefined;
this.attachmentViewerTarget = undefined;
if (this.hasAttachmentViewerFeature) {
this.attachmentViewerTarget = document.createElement("div");
@@ -238,12 +240,51 @@ FormRenderer.include({
}
},
/**
* @abstract
* @private
* @param {OdooEvent} ev
* @param {Object} ev.data
* @param {Attachment[]} ev.data.attachments
* @param {Thread} ev.data.thread
*/
_onChatterRendered(ev) {},
_onChatterRendered(ev) {
if (!this.hasAttachmentViewer()) {
if (this.attachmentViewer) {
this.attachmentViewer.destroy();
this.attachmentViewer = undefined;
this._interchangeChatter();
}
return;
}
var self = this;
const thread = ev.data.thread;
const attachments = thread.attachmentsInWebClientView;
if (attachments.length || this.attachmentViewer) {
if (this.attachmentViewer) {
// FIXME should be improved : what if somehow an attachment is replaced in a thread ?
if (
this.attachmentViewer.thread !== thread ||
this.attachmentViewer.attachments.length !== attachments.length
) {
if (attachments.length) {
this.attachmentViewer.updateContents(thread);
}
} else {
// The attachmentViewer lose its event listeners when it is reused,
// we just need to reregister them.
if (this.attachmentViewer.$el) {
this.attachmentViewer._undelegateEvents();
this.attachmentViewer._delegateEvents();
}
}
this.trigger_up('preview_attachment_validation');
this._updateChatterContainerTarget();
} else {
this.attachmentViewer = new AttachmentViewer(this, thread);
this.attachmentViewer.appendTo($(this.attachmentViewerTarget)).then(function () {
self.trigger_up('preview_attachment_validation');
self._interchangeChatter();
});
}
}
},
});