1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
odoo.define('mail/static/src/widgets/form_renderer/form_renderer.js', function (require) {
"use strict";
const components = {
ChatterContainer: require('mail/static/src/components/chatter_container/chatter_container.js'),
};
const FormRenderer = require('web.FormRenderer');
const { ComponentWrapper } = require('web.OwlCompatibility');
class ChatterContainerWrapperComponent extends ComponentWrapper {}
/**
* Include the FormRenderer to instantiate the chatter area containing (a
* subset of) the mail widgets (mail_thread, mail_followers and mail_activity).
*/
FormRenderer.include({
/**
* @override
*/
init(parent, state, params) {
this._super(...arguments);
this.chatterFields = params.chatterFields;
this.mailFields = params.mailFields;
this._chatterContainerComponent = undefined;
/**
* The target of chatter, if chatter has to be appended to the DOM.
* This is set when arch contains `div.oe_chatter`.
*/
this._chatterContainerTarget = undefined;
// Do not load chatter in form view dialogs
this._isFromFormViewDialog = params.isFromFormViewDialog;
},
/**
* @override
*/
destroy() {
this._super(...arguments);
this._chatterContainerComponent = undefined;
this.off('o_attachments_changed', this);
this.off('o_chatter_rendered', this);
this.off('o_message_posted', this);
owl.Component.env.bus.off('mail.thread:promptAddFollower-closed', this);
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Returns whether the form renderer has a chatter to display or not.
* This is based on arch, which should have `div.oe_chatter`.
*
* @private
* @returns {boolean}
*/
_hasChatter() {
return !!this._chatterContainerTarget;
},
/**
* @private
*/
_makeChatterContainerComponent() {
const props = this._makeChatterContainerProps();
this._chatterContainerComponent = new ChatterContainerWrapperComponent(
this,
components.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));
if (this.chatterFields.hasRecordReloadOnMessagePosted) {
this.on('o_message_posted', this, ev => {
this.trigger_up('reload', { keepChanges: true });
});
}
if (this.chatterFields.hasRecordReloadOnAttachmentsChanged) {
this.on('o_attachments_changed', this, ev => this.trigger_up('reload', { keepChanges: true }));
}
if (this.chatterFields.hasRecordReloadOnFollowersUpdate) {
owl.Component.env.bus.on('mail.thread:promptAddFollower-closed', this, ev => this.trigger_up('reload', { keepChanges: true }));
}
},
/**
* @private
* @returns {Object}
*/
_makeChatterContainerProps() {
return {
hasActivities: this.chatterFields.hasActivityIds,
hasFollowers: this.chatterFields.hasMessageFollowerIds,
hasMessageList: this.chatterFields.hasMessageIds,
isAttachmentBoxVisibleInitially: this.chatterFields.isAttachmentBoxVisibleInitially,
threadId: this.state.res_id,
threadModel: this.state.model,
};
},
/**
* Create the DOM element that will contain the chatter. This is made in
* a separate method so it can be overridden (like in mail_enterprise for
* example).
*
* @private
* @returns {jQuery.Element}
*/
_makeChatterContainerTarget() {
const $el = $('<div class="o_FormRenderer_chatterContainer"/>');
this._chatterContainerTarget = $el[0];
return $el;
},
/**
* 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;
}
}
},
/**
* @override
*/
_renderNode(node) {
if (node.tag === 'div' && node.attrs.class === 'oe_chatter') {
if (this._isFromFormViewDialog) {
return $('<div/>');
}
return this._makeChatterContainerTarget();
}
return this._super(...arguments);
},
/**
* Overrides the function to render the chatter once the form view is
* rendered.
*
* @override
*/
async __renderView() {
await this._super(...arguments);
if (this._hasChatter()) {
if (!this._chatterContainerComponent) {
this._makeChatterContainerComponent();
} else {
await this._updateChatterContainerComponent();
}
await this._mountChatterContainerComponent();
}
},
/**
* @private
*/
async _updateChatterContainerComponent() {
const props = this._makeChatterContainerProps();
try {
await this._chatterContainerComponent.update(props);
} catch (error) {
if (error.message !== "Mounting operation cancelled") {
throw error;
}
}
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @abstract
* @private
* @param {OdooEvent} ev
* @param {Object} ev.data
* @param {mail.attachment[]} ev.data.attachments
* @param {mail.thread} ev.data.thread
*/
_onChatterRendered(ev) {},
});
});
|