From b4ce395099fa4dc85d98c413bb7c787b4e27bdd9 Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" Date: Wed, 1 Mar 2023 16:29:14 +0000 Subject: [PATCH] [FIX] website, website_blog, website_sale: stay on the backend view Since [the merge of the frontend into the backend] and more precisely since [this commit], clicks on some elements makes the user switch from the backend view to the frontend view. Steps to reproduce (just an example): - Go to /blog from the backend (/@/blog) - Click on a tag (eg: adventure) => users are redirected to the frontend view, we do not want that. This commit makes the user stay in the backend. For some scenarios (like the one above), we create a fake form and submit it. The forms have a target attribute that specifies where the form response should be displayed. This commit set back the default value for the target attribute when a user clicks on a blog tag, a course tag, the pager, ... so that the response is displayed in the current context (the iframe when the user is in the backend). Note that [this commit] introduced the target attribute change to fix two issues: 1. The opening of the payment gateways in the iframe. 2. The create page from a 404 page in the backend. After [this other commit] has been merged, to prevent the first issue so here we just remove the target attribute change except for the case of the second issue. [the merge of the frontend into the backend]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b [this commit]: https://github.com/odoo/odoo/commit/2d44f2792dec0b2f205475a22dbedc97e9c54a64 [this other commit]: https://github.com/odoo/odoo/commit/3a32b9e1efa6277b345dc9239334680651690df7 task-3054970 closes odoo/odoo#114056 Signed-off-by: Romain Derie (rde) --- addons/website/static/src/js/utils.js | 5 +++-- addons/website/views/website_templates.xml | 2 +- .../website_blog/static/tests/tours/blog_tags_tour.js | 11 +++++++++++ .../tours/website_sale_add_to_cart_snippet_tour.js | 10 +++++----- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index 1b44781f47c..2eaec0c490b 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -284,8 +284,9 @@ function sendRequest(route, params) { let form = document.createElement('form'); form.setAttribute('action', route); form.setAttribute('method', params.method || 'POST'); - const isInIframe = window.frameElement && window.frameElement.classList.contains('o_iframe'); - if (isInIframe) { + // This is an exception for the 404 page create page button, in backend we + // want to open the response in the top window not in the iframe. + if (params.forceTopWindow) { form.setAttribute('target', '_top'); } diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index a69c084cbbf..3c973c0a758 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -2244,7 +2244,7 @@

This page does not exist, but you can create it as you are editor of this site.

- Create Page + Create Page
Edit the content below this line to adapt the default Page not found page.
diff --git a/addons/website_blog/static/tests/tours/blog_tags_tour.js b/addons/website_blog/static/tests/tours/blog_tags_tour.js index b560555ba86..1cfbff09411 100644 --- a/addons/website_blog/static/tests/tours/blog_tags_tour.js +++ b/addons/website_blog/static/tests/tours/blog_tags_tour.js @@ -51,5 +51,16 @@ wTourUtils.registerWebsitePreviewTour('blog_tags', { content: "Verify tag does not appear in blog post anymore", trigger: "iframe #o_wblog_post_content div:has(.badge):not(:contains(testtag))", run: () => {}, // it's a check + }, { + content: "Go back to /blog", + trigger: "iframe #top_menu a[href='/blog'] span", + }, { + content: "Click on the adventure tag", + trigger: "iframe a[href^='/blog/tag/adventure']", + }, { + content: "Verify we are still on the backend", + trigger: "iframe span:contains(adventure) i.fa-tag", + run: () => {}, // it's a check + }] ); diff --git a/addons/website_sale/static/tests/tours/website_sale_add_to_cart_snippet_tour.js b/addons/website_sale/static/tests/tours/website_sale_add_to_cart_snippet_tour.js index 83e70d6be25..e4560a6fa20 100644 --- a/addons/website_sale/static/tests/tours/website_sale_add_to_cart_snippet_tour.js +++ b/addons/website_sale/static/tests/tours/website_sale_add_to_cart_snippet_tour.js @@ -44,11 +44,11 @@ wTourUtils.registerWebsitePreviewTour('add_to_cart_snippet_tour', { ...wTourUtils.selectElementInWeSelectWidget('action_picker_opt', 'Buy Now'), ...wTourUtils.clickOnSave(), wTourUtils.clickOnElement('add to cart button', 'iframe .s_add_to_cart_btn'), - wTourUtils.assertPathName('/shop/payment', 'button[name=o_payment_submit_button]'), + wTourUtils.assertPathName('/@/shop/payment', 'iframe button[name=o_payment_submit_button]'), - wsTourUtils.goToCart({quantity: 4, backend: false}), - wsTourUtils.assertCartContains({productName: 'Acoustic Bloc Screens'}), - wsTourUtils.assertCartContains({productName: 'Conference Chair (Steel)'}), - wsTourUtils.assertCartContains({productName: 'Conference Chair (Aluminium)'}), + wsTourUtils.goToCart({quantity: 4, backend: true}), + wsTourUtils.assertCartContains({productName: 'Acoustic Bloc Screens', backend: true}), + wsTourUtils.assertCartContains({productName: 'Conference Chair (Steel)', backend: true}), + wsTourUtils.assertCartContains({productName: 'Conference Chair (Aluminium)', backend: true}), ], );