[IMP] mail, project: move chatter container setup code in init

Setup was conditionally done in render lifecycle methods, but it could be moved
to init instead, allowing to simplify the code and remove unnecessary methods
and overrides.

Part of task-2871070

closes odoo/odoo#94307

Related: odoo/enterprise#28893
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2022-06-27 15:11:13 +02:00
parent 055f95ddfe
commit 9de429e747
2 changed files with 39 additions and 45 deletions
@@ -33,6 +33,7 @@ FormRenderer.include({
if (this.hasChatter) {
this._chatterContainerTarget = document.createElement("div");
this._chatterContainerTarget.classList.add("o_FormRenderer_chatterContainer");
this.initChatter();
}
/**
* This element will be set when rendering the form view, and
@@ -40,6 +41,15 @@ FormRenderer.include({
* when applying the rendering into the DOM.
*/
this.chatterContainerTargetPlaceholder = undefined;
this.on('o_chatter_rendered', this, ev => this._onChatterRendered(ev));
},
async initChatter() {
this._chatterContainerComponent = new ChatterContainerWrapperComponent(
this,
ChatterContainer,
this._makeChatterContainerProps(),
);
await this._chatterContainerComponent.mount(this._chatterContainerTarget);
},
/**
* @override
@@ -63,12 +73,7 @@ FormRenderer.include({
async __renderView() {
await this._super(...arguments);
if (this.hasChatter) {
if (!this._chatterContainerComponent) {
this._makeChatterContainerComponent();
} else {
return this._updateChatterContainerComponent();
}
await this._mountChatterContainerComponent();
await this._updateChatterContainerComponent();
}
},
/**
@@ -111,20 +116,6 @@ FormRenderer.include({
_isChatterAside() {
return false;
},
/**
* @private
*/
_makeChatterContainerComponent() {
const props = this._makeChatterContainerProps();
this._chatterContainerComponent = new ChatterContainerWrapperComponent(
this,
ChatterContainer,
props
);
// Not in custom_events because other modules may remove this listener
// while attempting to extend them.
this.on('o_chatter_rendered', this, ev => this._onChatterRendered(ev));
},
/**
* @private
* @returns {Object}
@@ -145,24 +136,6 @@ FormRenderer.include({
threadModel: this.state.model,
};
},
/**
* Mount the chatter
*
* Force re-mounting chatter component in DOM. This is necessary
* because each time `_renderView` is called, it puts old content
* in a fragment.
*
* @private
*/
async _mountChatterContainerComponent() {
try {
await this._chatterContainerComponent.mount(this._chatterContainerTarget);
} catch (error) {
if (error.message !== "Mounting operation cancelled") {
throw error;
}
}
},
/**
* @private
*/
@@ -1,15 +1,39 @@
/** @odoo-module **/
import '@mail/widgets/form_renderer/form_renderer'; // ensure mail overrides are applied first
import FormRenderer from 'web.FormRenderer';
import Chatter from '@project/project_sharing/components/chatter';
import { session } from '@web/session';
export default FormRenderer.extend({
_makeChatterContainerComponent() {
const props = this._makeChatterContainerProps();
this._chatterContainerComponent = new Chatter(this, props);
/**
* Creates the portal chatter instead of the standard chatter.
*
* This overridden method is expected to be called from proper lifecycle
* method of mail form renderer, when `this._chatterContainerTarget` is set.
*
* @override
*/
initChatter() {
const options = this.makePortalChatterOptions();
this.portalChatter = new Chatter(this, options);
this.portalChatter.appendTo(this._chatterContainerTarget);
},
_makeChatterContainerProps() {
/**
* Updates the options of the portal chatter instead of the props of the
* standard chatter.
*
* This overridden method is expected to be called from proper lifecycle
* method of mail form renderer.
*
* @override
*/
_updateChatterContainerComponent() {
const options = this.makePortalChatterOptions();
this.portalChatter.update(options);
},
makePortalChatterOptions() {
// FIXME: perhaps check if we have a parent in the window ?
// Call the parent window to get the url displayed in the browser since we are in an iframe
const query = new URLSearchParams(window.parent.location.search);
@@ -25,7 +49,4 @@ export default FormRenderer.extend({
project_sharing_id: session.project_id,
};
},
_mountChatterContainerComponent() {
this._chatterContainerComponent.appendTo(this._chatterContainerTarget);
},
});