From 31db5fbe6e8632cfac504bef6809022dbdc5c93a Mon Sep 17 00:00:00 2001
From: Romain Derie <rde@odoo.com>
Date: Fri, 19 May 2023 16:05:39 +0000
Subject: [PATCH] [FIX] website: correctly target footer on popup options

The code was assuming there would be only one `<footer/>` element in the
dom but it's not always true.
Our `Blockquote` snippet also contains a `<footer/>` element.

While this has no impact on Odoo 14 and Odoo 15, it will crash in Odoo
16 when trying to select "On all pages" on a popup option when there is
a blockquote snippet on a page.
The reason it breaks in 16 is because it uses javascript instead of
jquery, finding only one element (the footer of the blockquote) and not
all. The jQuery usage was then filtering out to only keep the correct
footer due to some extra selector looked for in the elements
(`.oe_structure:o_editable`).

Still, the fix is made in Odoo 14 because it's likely that we will have
another fix later in the snippet options, and it's also likely that
someone will replace the jQuery usage by javascript while doing so,
which would reveal the bug.

opw-3283140

closes odoo/odoo#122119

X-original-commit: ca3d6e09c57683de028f5cf4a2baafa5af624e4d
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
---
 addons/website/static/src/snippets/s_popup/options.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/website/static/src/snippets/s_popup/options.js b/addons/website/static/src/snippets/s_popup/options.js
index 867de61bedc2..8c865cc58b15 100644
--- a/addons/website/static/src/snippets/s_popup/options.js
+++ b/addons/website/static/src/snippets/s_popup/options.js
@@ -101,7 +101,7 @@ options.registry.SnippetPopup = options.Class.extend({
      * @see this.selectClass for parameters
      */
     moveBlock: function (previewMode, widgetValue, params) {
-        const containerEl = this.$target[0].ownerDocument.querySelector(widgetValue === 'moveToFooter' ? 'footer' : 'main');
+        const containerEl = this.$target[0].ownerDocument.querySelector(widgetValue === 'moveToFooter' ? 'footer#bottom' : 'main');
         const whereEl = $(containerEl).find('.oe_structure:o_editable')[0];
         const popupEl = this.$target[0].closest('.s_popup');
         whereEl.prepend(popupEl);
@@ -132,7 +132,7 @@ options.registry.SnippetPopup = options.Class.extend({
     _computeWidgetState: function (methodName, params) {
         switch (methodName) {
             case 'moveBlock':
-                return this.$target.closest('footer').length ? 'moveToFooter' : 'moveToBody';
+                return this.$target.closest('footer#bottom').length ? 'moveToFooter' : 'moveToBody';
         }
         return this._super(...arguments);
     },
-- 
GitLab