From 4cb228d823e0346e6052091d397249b8e39d576b Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 28 Jan 2019 10:15:50 +0000 Subject: [PATCH] [IMP] portal,website_rating: new popup composer to submit rating Rating document available on a website will become more common, but we want to do it with different UI widget. This commit introduces a new "popup rating composer": the idea is the rating average is displayed with stars, and when clicking on it, a popup with the composer appears. The user can so submit its review. To do so, we factorize the Portal Composer into a dedicated widget (instead of natively inside Portal Chatter). Task-1902304 --- addons/portal/static/src/js/portal_chatter.js | 86 +++++-- .../portal/static/src/xml/portal_chatter.xml | 19 +- .../static/src/js/website_mail.js | 217 ++++++++++++------ .../static/src/scss/website_rating.scss | 12 + .../static/src/xml/portal_chatter.xml | 71 ++++++ .../static/src/xml/website_mail.xml | 32 +-- .../views/website_rating_templates.xml | 15 ++ 7 files changed, 326 insertions(+), 126 deletions(-) create mode 100644 addons/website_rating/static/src/xml/portal_chatter.xml diff --git a/addons/portal/static/src/js/portal_chatter.js b/addons/portal/static/src/js/portal_chatter.js index 7f4ba583036..5a56a35bed9 100644 --- a/addons/portal/static/src/js/portal_chatter.js +++ b/addons/portal/static/src/js/portal_chatter.js @@ -12,6 +12,43 @@ var time = require('web.time'); var qweb = core.qweb; var _t = core._t; +/** + * Widget PortalComposer + * + * Display the composer (according to access right) + * + */ +var PortalComposer = Widget.extend({ + template: 'portal.Composer', + events: { + 'click .o_portal_chatter_composer_btn': '_onSubmitButtonClick', + }, + init: function(parent, options){ + this._super.apply(this, arguments); + this.options = _.defaults(options || {}, { + 'allow_composer': true, + 'display_composer': false, + 'csrf_token': odoo.csrf_token, + 'token': false, + 'res_model': false, + 'res_id': false, + }); + + // TODO simplify this using the 'async' keyword in the events + // property definition as soon as this widget is converted in + // frontend widget. + this._onSubmitButtonClick = dom.makeButtonHandler(this._onSubmitButtonClick); + }, + /** + * @private + */ + _onSubmitButtonClick: function () { + return $.Deferred(); + }, +}); + + + /** * Widget PortalChatter * @@ -20,15 +57,23 @@ var _t = core._t; * - Provider API to filter displayed messages */ var PortalChatter = Widget.extend({ - template: 'portal.chatter', + template: 'portal.Chatter', events: { "click .o_portal_chatter_pager_btn": '_onClickPager', - 'click .o_portal_chatter_composer_btn': '_onSubmitButtonClick', }, + xmlDependencies: ['/portal/static/src/xml/portal_chatter.xml'], init: function(parent, options){ + var self = this; + this.options = {}; this._super.apply(this, arguments); - this.options = _.defaults(options || {}, { + + // 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, @@ -45,20 +90,16 @@ var PortalChatter = Widget.extend({ this.set('pager', {}); this.set('domain', this.options['domain']); this._current_page = this.options['pager_start']; - - // TODO simplify this using the 'async' keyword in the events - // property definition as soon as this widget is converted in - // frontend widget. - this._onSubmitButtonClick = dom.makeButtonHandler(this._onSubmitButtonClick); }, willStart: function(){ var self = this; // load qweb template and init data return $.when( + this._super.apply(this, arguments), rpc.query({ route: '/mail/chatter_init', params: this._messageFetchPrepareParams() - }), this._loadTemplates() + }), ).then(function(result){ self.result = result; self.options = _.extend(self.options, self.result['options'] || {}); @@ -80,7 +121,18 @@ var PortalChatter = Widget.extend({ // set options and parameters this.set('message_count', this.options['message_count']); this.set('messages', this.preprocessMessages(this.result['messages'])); - return this._super.apply(this, arguments); + + + var defs = []; + defs.push(this._super.apply(this, arguments)); + + // instanciate and insert composer widget + if (this.options['display_composer']) { + this._composer = new PortalComposer(this, this.options); + defs.push(this._composer.replace(this.$('.o_portal_chatter_composer'))); + } + + return $.when.apply($, defs); }, //-------------------------------------------------------------------------- @@ -134,13 +186,6 @@ var PortalChatter = Widget.extend({ var d = domain ? domain : _.clone(this.get('domain')); this.set('domain', d); // trigger fetch message }, - /** - * @private - * @returns {Deferred} - */ - _loadTemplates: function(){ - return ajax.loadXML('/portal/static/src/xml/portal_chatter.xml', qweb); - }, _messageFetchPrepareParams: function(){ var self = this; var data = { @@ -234,12 +279,6 @@ var PortalChatter = Widget.extend({ var page = $(ev.currentTarget).data('page'); this._changeCurrentPage(page); }, - /** - * @private - */ - _onSubmitButtonClick: function () { - return $.Deferred(); - }, }); base.ready().then(function () { @@ -251,6 +290,7 @@ base.ready().then(function () { }); return { + PortalComposer: PortalComposer, PortalChatter: PortalChatter, }; diff --git a/addons/portal/static/src/xml/portal_chatter.xml b/addons/portal/static/src/xml/portal_chatter.xml index a306cb246e1..f090965bde2 100644 --- a/addons/portal/static/src/xml/portal_chatter.xml +++ b/addons/portal/static/src/xml/portal_chatter.xml @@ -15,7 +15,12 @@ - + +

Leave a comment

@@ -45,13 +50,16 @@
-
+ +
- +
avatar
@@ -96,13 +104,14 @@
- +
+
+

-