diff --git a/addons/portal/controllers/mail.py b/addons/portal/controllers/mail.py index 1f776bb6ab1..0869089ff69 100644 --- a/addons/portal/controllers/mail.py +++ b/addons/portal/controllers/mail.py @@ -85,6 +85,9 @@ def _message_post_helper(res_model, res_id, message, token='', _hash=False, pid= class PortalChatter(http.Controller): + def _portal_post_filter_params(self): + return ['token', 'hash', 'pid'] + @http.route(['/mail/chatter_post'], type='http', methods=['POST'], auth='public', website=True) def portal_chatter_post(self, res_model, res_id, message, redirect=None, attachment_ids='', attachment_tokens='', **kw): """Create a new `mail.message` with the given `message` and/or @@ -112,16 +115,15 @@ class PortalChatter(http.Controller): # message is received in plaintext and saved in html if message: message = plaintext2html(message) - message = _message_post_helper( - res_model=res_model, - res_id=res_id, - token=kw.get('token'), - _hash=kw.get('hash'), - pid=kw.get('pid'), - message=message, - send_after_commit=False, - attachment_ids=attachment_ids - ) + post_values = { + 'res_model': res_model, + 'res_id': res_id, + 'message': message, + 'send_after_commit': False, + 'attachment_ids': attachment_ids, + } + post_values.update((fname, kw.get(fname)) for fname in self._portal_post_filter_params()) + message = _message_post_helper(**post_values) return request.redirect(url) diff --git a/addons/website_mail/__manifest__.py b/addons/website_mail/__manifest__.py index 45571be05b3..fb4dc268da2 100644 --- a/addons/website_mail/__manifest__.py +++ b/addons/website_mail/__manifest__.py @@ -12,13 +12,10 @@ It is responsible of comments moderation for published documents (forum, slides, """, 'depends': ['website', 'mail'], 'data': [ + 'views/assets.xml', 'views/website_mail_templates.xml', - 'data/mail_channel_data.xml', 'security/website_mail_security.xml', ], - 'qweb': [ - 'static/src/xml/website_mail.xml' - ], 'installable': True, 'auto_install': True, } diff --git a/addons/website_mail/data/mail_channel_data.xml b/addons/website_mail/data/mail_channel_data.xml deleted file mode 100644 index 785a7aefd77..00000000000 --- a/addons/website_mail/data/mail_channel_data.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - Discussion Group - public - Public Discussion Group - - - - - - diff --git a/addons/website_mail/static/src/js/website_mail.js b/addons/website_mail/static/src/js/portal_chatter.js similarity index 81% rename from addons/website_mail/static/src/js/website_mail.js rename to addons/website_mail/static/src/js/portal_chatter.js index 473ed4b4128..923c17032fe 100644 --- a/addons/website_mail/static/src/js/website_mail.js +++ b/addons/website_mail/static/src/js/portal_chatter.js @@ -8,6 +8,6 @@ var portalChatter = require('portal.chatter'); */ portalChatter.PortalChatter.include({ xmlDependencies: (portalChatter.PortalChatter.prototype.xmlDependencies || []) - .concat(['/website_mail/static/src/xml/website_mail.xml']), + .concat(['/website_mail/static/src/xml/portal_chatter.xml']), }); }); diff --git a/addons/website_mail/static/src/xml/website_mail.xml b/addons/website_mail/static/src/xml/portal_chatter.xml similarity index 100% rename from addons/website_mail/static/src/xml/website_mail.xml rename to addons/website_mail/static/src/xml/portal_chatter.xml diff --git a/addons/website_mail/views/assets.xml b/addons/website_mail/views/assets.xml new file mode 100644 index 00000000000..30d581cf4a4 --- /dev/null +++ b/addons/website_mail/views/assets.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/addons/website_mail/views/website_mail_templates.xml b/addons/website_mail/views/website_mail_templates.xml index cf13c79bc04..856af90ca93 100644 --- a/addons/website_mail/views/website_mail_templates.xml +++ b/addons/website_mail/views/website_mail_templates.xml @@ -16,13 +16,4 @@ - - - - - - - - - diff --git a/addons/website_rating/__manifest__.py b/addons/website_rating/__manifest__.py index 4ef33b67977..610a61f3183 100644 --- a/addons/website_rating/__manifest__.py +++ b/addons/website_rating/__manifest__.py @@ -10,8 +10,9 @@ Bridge module for rating on website stuff. """, 'depends': ['rating', 'website_mail'], 'data': [ - 'views/website_rating_templates.xml', + 'views/assets.xml', + 'views/portal_templates.xml', + 'views/rating_templates.xml', ], - 'qweb': ['static/src/xml/*.xml'], 'auto_install': True, } diff --git a/addons/website_rating/controllers/__init__.py b/addons/website_rating/controllers/__init__.py index a8136630fc9..be30644ac93 100644 --- a/addons/website_rating/controllers/__init__.py +++ b/addons/website_rating/controllers/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import website_mail +from . import portal_chatter diff --git a/addons/website_rating/controllers/website_mail.py b/addons/website_rating/controllers/portal_chatter.py similarity index 76% rename from addons/website_rating/controllers/website_mail.py rename to addons/website_rating/controllers/portal_chatter.py index 9b56deebcd6..c252d2f73e7 100644 --- a/addons/website_rating/controllers/website_mail.py +++ b/addons/website_rating/controllers/portal_chatter.py @@ -7,11 +7,16 @@ from odoo.http import request from odoo.addons.portal.controllers.mail import PortalChatter -class WebsiteRating(PortalChatter): +class PortalChatter(PortalChatter): + + def _portal_post_filter_params(self): + fields = super(PortalChatter, self)._portal_post_filter_params() + fields.append('rating_value') + return fields @http.route() def portal_chatter_init(self, res_model, res_id, domain=False, limit=False, **kwargs): - result = super(WebsiteRating, self).portal_chatter_init(res_model, res_id, domain=domain, limit=limit, **kwargs) + result = super(PortalChatter, self).portal_chatter_init(res_model, res_id, domain=domain, limit=limit, **kwargs) # get the rating statistics about the record if kwargs.get('rating_include'): record = request.env[res_model].browse(res_id) @@ -26,4 +31,4 @@ class WebsiteRating(PortalChatter): context = dict(request.context) context['rating_include'] = True request.context = context - return super(WebsiteRating, self).portal_message_fetch(res_model, res_id, domain=domain, limit=limit, offset=offset, **kw) + return super(PortalChatter, self).portal_message_fetch(res_model, res_id, domain=domain, limit=limit, offset=offset, **kw) diff --git a/addons/website_rating/static/src/js/website_mail.js b/addons/website_rating/static/src/js/portal_chatter.js similarity index 81% rename from addons/website_rating/static/src/js/website_mail.js rename to addons/website_rating/static/src/js/portal_chatter.js index 5b4f1b04f70..d3a351ad9c1 100644 --- a/addons/website_rating/static/src/js/website_mail.js +++ b/addons/website_rating/static/src/js/portal_chatter.js @@ -2,8 +2,6 @@ odoo.define('website_rating.thread', function (require) { 'use strict'; var core = require('web.core'); -var publicWidget = require('web.public.widget'); -var session = require('web.session'); var portalChatter = require('portal.chatter'); var utils = require('web.utils'); @@ -67,7 +65,10 @@ PortalComposer.include({ // rating stars self.$input = self.$('input[name="rating_value"]'); self.$star_list = self.$('.stars').find('i'); - self.set("star_value", self.options.default_rating_value); // set the default value to trigger the display of star widget + + // set the default value to trigger the display of star widget and update the hidden input value. + self.set("star_value", self.options.default_rating_value); + self.$input.val(self.options.default_rating_value * STAR_RATING_RATIO); }); }, @@ -136,7 +137,7 @@ PortalChatter.include({ }), xmlDependencies: (PortalChatter.prototype.xmlDependencies || []) .concat([ - '/website_rating/static/src/xml/website_mail.xml', + '/website_rating/static/src/xml/portal_tools.xml', '/website_rating/static/src/xml/portal_chatter.xml' ]), @@ -291,64 +292,4 @@ PortalChatter.include({ this._changeCurrentPage(1, domain); }, }); - -/** - * RatingPopupComposer - * - * Display the rating average with a static star widget, and open - * a popup with the portal composer when clicking on it. - **/ -var RatingPopupComposer = publicWidget.Widget.extend({ - template: 'website_rating.PopupComposer', - xmlDependencies: [ - '/portal/static/src/xml/portal_chatter.xml', - '/website_rating/static/src/xml/website_mail.xml', - '/website_rating/static/src/xml/portal_chatter.xml', - ], - - init: function (parent, options) { - this._super.apply(this, arguments); - this.rating_avg = Math.round(options['ratingAvg'] / STAR_RATING_RATIO * 100) / 100 || 0.0; - this.rating_total = options['ratingTotal'] || 0.0; - - this.options = _.defaults({}, options, { - 'token': false, - 'res_model': false, - 'res_id': false, - 'pid': 0, - 'display_composer': options['disable_composer'] ? false : !session.is_website_user, - 'display_rating': true, - 'csrf_token': odoo.csrf_token, - 'user_id': session.user_id, - }); - }, - /** - * @override - */ - start: function () { - var defs = []; - defs.push(this._super.apply(this, arguments)); - - // instanciate and insert composer widget - this._composer = new PortalComposer(this, this.options); - defs.push(this._composer.replace(this.$('.o_portal_chatter_composer'))); - - return Promise.all(defs); - }, -}); - -publicWidget.registry.RatingPopupComposer = publicWidget.Widget.extend({ - selector: '.o_rating_popup_composer', - - /** - * @override - */ - start: function () { - var ratingPopup = new RatingPopupComposer(this, this.$el.data()); - return Promise.all([ - this._super.apply(this, arguments), - ratingPopup.appendTo(this.$el) - ]); - }, -}); }); diff --git a/addons/website_rating/static/src/js/portal_rating_composer.js b/addons/website_rating/static/src/js/portal_rating_composer.js new file mode 100644 index 00000000000..78e6a4d4d1d --- /dev/null +++ b/addons/website_rating/static/src/js/portal_rating_composer.js @@ -0,0 +1,71 @@ +odoo.define('portal.rating.composer', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); +var session = require('web.session'); +var portalChatter = require('portal.chatter'); + +var PortalComposer = portalChatter.PortalComposer; + +var STAR_RATING_RATIO = 2; // conversion factor from the star (1-5) to the db rating range (1-10) + +/** + * RatingPopupComposer + * + * Display the rating average with a static star widget, and open + * a popup with the portal composer when clicking on it. + **/ +var RatingPopupComposer = publicWidget.Widget.extend({ + template: 'website_rating.PopupComposer', + xmlDependencies: [ + '/portal/static/src/xml/portal_chatter.xml', + '/website_rating/static/src/xml/portal_tools.xml', + '/website_rating/static/src/xml/portal_rating_composer.xml', + ], + + init: function (parent, options) { + this._super.apply(this, arguments); + this.rating_avg = Math.round(options['ratingAvg'] / STAR_RATING_RATIO * 100) / 100 || 0.0; + this.rating_total = options['ratingTotal'] || 0.0; + + this.options = _.defaults({}, options, { + 'token': false, + 'res_model': false, + 'res_id': false, + 'pid': 0, + 'display_composer': options['disable_composer'] ? false : !session.is_website_user, + 'display_rating': true, + 'csrf_token': odoo.csrf_token, + 'user_id': session.user_id, + }); + }, + /** + * @override + */ + start: function () { + var defs = []; + defs.push(this._super.apply(this, arguments)); + + // instanciate and insert composer widget + this._composer = new PortalComposer(this, this.options); + defs.push(this._composer.replace(this.$('.o_portal_chatter_composer'))); + + return Promise.all(defs); + }, +}); + +publicWidget.registry.RatingPopupComposer = publicWidget.Widget.extend({ + selector: '.o_rating_popup_composer', + + /** + * @override + */ + start: function () { + var ratingPopup = new RatingPopupComposer(this, this.$el.data()); + return Promise.all([ + this._super.apply(this, arguments), + ratingPopup.appendTo(this.$el) + ]); + }, +}); +}); diff --git a/addons/website_rating/static/src/xml/portal_chatter.xml b/addons/website_rating/static/src/xml/portal_chatter.xml index cebaea338d5..c2bbb2781e6 100644 --- a/addons/website_rating/static/src/xml/portal_chatter.xml +++ b/addons/website_rating/static/src/xml/portal_chatter.xml @@ -1,6 +1,5 @@ - @@ -37,57 +36,4 @@ - - - - - - - - - - - - ( ratings) - - - - - - Modify your review - - - Add a review - - - - - - - - - - - - Modify your review - - - Add a review - - - - × - - - - - - - - - - diff --git a/addons/website_rating/static/src/xml/portal_rating_composer.xml b/addons/website_rating/static/src/xml/portal_rating_composer.xml new file mode 100644 index 00000000000..38d041a060e --- /dev/null +++ b/addons/website_rating/static/src/xml/portal_rating_composer.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + ( ratings) + + + + + + Modify your review + + + Add a review + + + + + + + + + + + + Modify your review + + + Add a review + + + + × + + + + + + + + + + diff --git a/addons/website_rating/static/src/xml/website_mail.xml b/addons/website_rating/static/src/xml/portal_tools.xml similarity index 99% rename from addons/website_rating/static/src/xml/website_mail.xml rename to addons/website_rating/static/src/xml/portal_tools.xml index f7a3cf3b280..07460b72f53 100644 --- a/addons/website_rating/static/src/xml/website_mail.xml +++ b/addons/website_rating/static/src/xml/portal_tools.xml @@ -1,6 +1,5 @@ - @@ -85,5 +84,4 @@ - diff --git a/addons/website_rating/views/assets.xml b/addons/website_rating/views/assets.xml new file mode 100644 index 00000000000..70ff3ed7c13 --- /dev/null +++ b/addons/website_rating/views/assets.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/addons/website_rating/views/portal_templates.xml b/addons/website_rating/views/portal_templates.xml new file mode 100644 index 00000000000..d616bc491c9 --- /dev/null +++ b/addons/website_rating/views/portal_templates.xml @@ -0,0 +1,8 @@ + + + + + display_rating or False + + + diff --git a/addons/website_rating/views/website_rating_templates.xml b/addons/website_rating/views/rating_templates.xml similarity index 55% rename from addons/website_rating/views/website_rating_templates.xml rename to addons/website_rating/views/rating_templates.xml index aedfb2f9631..8f7a287f336 100644 --- a/addons/website_rating/views/website_rating_templates.xml +++ b/addons/website_rating/views/rating_templates.xml @@ -1,43 +1,12 @@ - - - - - - - display_rating or False - - - - - - - - - - - - - - - - - - () - - - -