From a4b96962a1b4b3d06bad7a61474430151e93367d Mon Sep 17 00:00:00 2001 From: "Louis (loco)" <loco@odoo.com> Date: Mon, 15 May 2023 13:36:37 +0000 Subject: [PATCH] [FIX] web_editor: remove incorrect data attributes in current databases Steps to reproduce the bug (before the commits of this PR): - Drop a Cover snippet on the website. - Change the parallax to "None". - Save and edit. - Modify an option (for example, add a filter) to add the `o_modified_image_to_save` class to the image. - Change the parallax to "Fixed". - Save. - Inspect the Cover snippet. => The `span` element has the attributes `data-snippet="s_cover"` and `data-name="Cover"`. Note that this could lead to problem during the migration process. Let's analyze the process in order to better understand the problem: - At the change of the parallax to "None", there is a change of the target thanks to the call to `setTarget()`. The new target is now the `section` element. - At the save and edit, there is a call to `_loadImageInfo()`. All the dataset (including `data-snippet` and `data-name`) of the new target is copied in `this.img`. - At the modify of an option, the `o_modified_image_to_save` class is added to `this.img`. - At the change of the parallax to "Fixed", there is a change of the target thanks to the call to `setTarget()`. The new target is now the `span` element. - At the save, `cleanForSave()` is called and because there is the `o_modified_image_to_save` on `this.img`, all the dataset of `this.img` (including `data-snippet` and `data-name`) is copied on the new target (the `span` element). Note that this problem is resolved by the second commit of this PR. Indeed, the dataset of the target is first filtered by `_whiteListAttributes` before being copied into `this.img`. However, databases that already have the problem will not be fixed by. The goal of this commit is to remove the `data-snippet="s_cover"` and the `data-name="Cover"` from the `span` elements in those existing databases. task-3287330 closes odoo/odoo#121682 X-original-commit: https://github.com/odoo/odoo/commit/9e48950e0c1268cfb2f5855861e7e95fd7a4abcd Signed-off-by: Benoit Socias (bso) <bso@odoo.com> Signed-off-by: loco-odoo <loco@odoo.com> --- .../web_editor/static/src/js/editor/snippets.editor.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 20ea753b0a51..bfb458ba0dd6 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1597,6 +1597,16 @@ var SnippetsMenu = Widget.extend({ * - Remove the 'contentEditable' attributes */ cleanForSave: async function () { + // TODO remove me in master. This was added as a fix in stable to remove + // the "data-snippet" attribute that was added on the "span" element of + // the "Cover" snippet when modifying the "Parallax" of the snippet. + window.document.querySelectorAll("span[data-snippet='s_cover'][data-name='Cover']") + .forEach(el => { + delete el.dataset["snippet"]; + delete el.dataset["name"]; + const dirty = el.closest(".o_editable") || el; + dirty.classList.add("o_dirty"); + }); // First disable the snippet selection, calling options onBlur, closing // widgets, etc. Then wait for full resolution of the mutex as widgets // may have triggered some final edition requests that need to be -- GitLab