Skip to content
Snippets Groups Projects
Commit 9e48950e authored by Louis (loco)'s avatar Louis (loco)
Browse files

[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#119596

Signed-off-by: default avatarBenoit Socias (bso) <bso@odoo.com>
parent c06f39e3
No related branches found
No related tags found
No related merge requests found
......@@ -1314,6 +1314,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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment