[IMP] project: update chatter when create/change task
Before this commit, when the user changes the task, the chatter is not updated so we keep the messages of the previous task. Same thing when the portal user wants to create a new task. This commit updates the chatter to allow to fetch the messages when the user changes the task and also disables the chatter when the user is creating a new task. task-2379518 closes #73341
This commit is contained in:
@@ -34,27 +34,7 @@ var PortalChatter = publicWidget.Widget.extend({
|
||||
this.options = {};
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// underscorize the camelcased option keys
|
||||
_.each(options, function (val, key) {
|
||||
self.options[_.str.underscored(key)] = val;
|
||||
});
|
||||
// set default options
|
||||
this.options = _.defaults(this.options, {
|
||||
'allow_composer': true,
|
||||
'display_composer': false,
|
||||
'csrf_token': odoo.csrf_token,
|
||||
'message_count': 0,
|
||||
'pager_step': 10,
|
||||
'pager_scope': 5,
|
||||
'pager_start': 1,
|
||||
'is_user_public': true,
|
||||
'is_user_employee': false,
|
||||
'is_user_publisher': false,
|
||||
'hash': false,
|
||||
'pid': false,
|
||||
'domain': [],
|
||||
'two_columns': false,
|
||||
});
|
||||
this._setOptions(options);
|
||||
|
||||
this.set('messages', []);
|
||||
this.set('message_count', this.options['message_count']);
|
||||
@@ -135,6 +115,38 @@ var PortalChatter = publicWidget.Widget.extend({
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*
|
||||
* @param {Array<string>} options: new options to set
|
||||
*/
|
||||
_setOptions: function (options) {
|
||||
// underscorize the camelcased option keys
|
||||
const defaultOptions = {
|
||||
'allow_composer': true,
|
||||
'display_composer': false,
|
||||
'csrf_token': odoo.csrf_token,
|
||||
'message_count': 0,
|
||||
'pager_step': 10,
|
||||
'pager_scope': 5,
|
||||
'pager_start': 1,
|
||||
'is_user_public': true,
|
||||
'is_user_employee': false,
|
||||
'is_user_publisher': false,
|
||||
'hash': false,
|
||||
'pid': false,
|
||||
'domain': [],
|
||||
'two_columns': false,
|
||||
};
|
||||
|
||||
this.options = Object.entries(options).reduce(
|
||||
(acc, [key, value]) => {
|
||||
acc[_.str.underscored(key)] = value;
|
||||
return acc;
|
||||
},
|
||||
defaultOptions);
|
||||
},
|
||||
|
||||
/**
|
||||
* Reloads chatter and message count after posting message
|
||||
*
|
||||
|
||||
@@ -4,6 +4,19 @@ import { PortalChatter } from 'portal.chatter';
|
||||
import Composer from './composer';
|
||||
|
||||
export default PortalChatter.extend({
|
||||
messageFetch(domain) {
|
||||
if (!this.options.res_id) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
_chatterInit() {
|
||||
if (!this.options.res_id) {
|
||||
this.result = { messages: [] };
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
_messageFetchPrepareParams() {
|
||||
const data = this._super.apply(this, arguments);
|
||||
if (this.options.project_sharing_id) {
|
||||
@@ -14,4 +27,8 @@ export default PortalChatter.extend({
|
||||
_createComposerWidget() {
|
||||
return new Composer(this, this.options);
|
||||
},
|
||||
update(props) {
|
||||
this._setOptions(props);
|
||||
this._reloadChatterContent();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-extend="portal.chatter_messages">
|
||||
<t t-jquery="t[t-as='message']" t-operation="attributes">
|
||||
<attribute name="t-foreach">!!widget.options.res_id && widget.get('messages') || []</attribute>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -20,7 +20,7 @@ export default FormRenderer.extend({
|
||||
hash: '',
|
||||
res_id: this.state.res_id,
|
||||
pager_step: 10,
|
||||
allow_composer: true,
|
||||
allow_composer: !!this.state.res_id,
|
||||
two_columns: false,
|
||||
project_sharing_id: session.project_id,
|
||||
};
|
||||
@@ -33,5 +33,4 @@ export default FormRenderer.extend({
|
||||
_mountChatterContainerComponent() {
|
||||
this._chatterContainerComponent.appendTo(this._chatterContainerTarget);
|
||||
},
|
||||
_updateChatterContainerComponent() {},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user