From 3d2fe2f2d85dacb0be1a948687fb6a6d2572a3ae Mon Sep 17 00:00:00 2001 From: Hardik Prajapati Date: Thu, 30 Sep 2021 06:55:23 +0000 Subject: [PATCH] [FIX] website_forum: fix forum back button url from backend Currently, when user open the question from helpdesk ticket and user clicks on the back button of the forum page, it redirects the user to the app switcher. It happens because the back button contains the homepage URL as httprequest.referrer does not support the fragment url with hash(#). so this commit fixes the issue by binding the onclick event on the back button so clicking on the back button redirects the user to the helpdesk ticket. task-2602604 closes odoo/odoo#77458 Signed-off-by: Laurent Stukkens (ltu) --- addons/website_forum/controllers/main.py | 2 +- .../static/src/js/website_forum.js | 18 ++++++++++++++++++ addons/website_forum/views/website_forum.xml | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index e6b08e253be..70d76cd8654 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -261,7 +261,7 @@ class WebsiteForum(WebsiteProfile): 'reversed': reversed, }) if (request.httprequest.referrer or "").startswith(request.httprequest.url_root): - values['back_button_url'] = request.httprequest.referrer + values['has_back_button_url'] = True # increment view counter question.sudo()._set_viewed() diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 83b94424dd7..167f08958a2 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -634,4 +634,22 @@ publicWidget.registry.websiteForumSpam = publicWidget.Widget.extend({ }, }); +publicWidget.registry.WebsiteForumBackButton = publicWidget.Widget.extend({ + selector: '.o_back_button', + events: { + 'click': '_onBackButtonClick', + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onBackButtonClick() { + window.history.back(); + }, +}); + }); diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 200c50958f9..93692cb3cf4 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -128,7 +128,7 @@