From d3ecc4962ef659aa783264bec2d679b077b37142 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Wed, 14 Jul 2021 10:30:48 +0200 Subject: [PATCH] [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 --- addons/portal/static/src/js/portal_chatter.js | 54 +++++++++++-------- .../src/project_sharing/components/chatter.js | 17 ++++++ .../project_sharing/components/chatter.xml | 8 +++ .../project_sharing/views/form/renderer.js | 3 +- 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 addons/project/static/src/project_sharing/components/chatter.xml diff --git a/addons/portal/static/src/js/portal_chatter.js b/addons/portal/static/src/js/portal_chatter.js index c80a5f0de97..0f379460d06 100644 --- a/addons/portal/static/src/js/portal_chatter.js +++ b/addons/portal/static/src/js/portal_chatter.js @@ -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} 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 * diff --git a/addons/project/static/src/project_sharing/components/chatter.js b/addons/project/static/src/project_sharing/components/chatter.js index 3f85c37f935..e1ad0d48a25 100644 --- a/addons/project/static/src/project_sharing/components/chatter.js +++ b/addons/project/static/src/project_sharing/components/chatter.js @@ -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(); + }, }); diff --git a/addons/project/static/src/project_sharing/components/chatter.xml b/addons/project/static/src/project_sharing/components/chatter.xml new file mode 100644 index 00000000000..aca16ce257a --- /dev/null +++ b/addons/project/static/src/project_sharing/components/chatter.xml @@ -0,0 +1,8 @@ + + + + + !!widget.options.res_id && widget.get('messages') || [] + + + diff --git a/addons/project/static/src/project_sharing/views/form/renderer.js b/addons/project/static/src/project_sharing/views/form/renderer.js index 41105160548..1ac113fbd7f 100644 --- a/addons/project/static/src/project_sharing/views/form/renderer.js +++ b/addons/project/static/src/project_sharing/views/form/renderer.js @@ -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() {}, });