[FIX] web_editor, website: fix ignoring unapplied device invisibility

Upon drop, the fix in [1] did consider invisible the blocks that were
visible within the current preview mode (mobile/desktop).
Because of this `onTargetHide` was be called instead of `onTargetShow`.

This commit changes that behavior so that the correct method remains
called according to the actual visibility, but the `DeviceVisibility`'s
`onTargetShow` is adapted to only add the override if it matches the
current preview mode.

No steps to reproduce for this first change, but third-party options
could have been impacted by it.

This commit also adds that condition on the cleanup that was added in
[2] to keep the `dataset.invisible` state consistent upon toggling the
preview mode.

Steps to reproduce this second issue:
- Drop a Columns snippet.
- Make a column visible only on mobile.
- Make another column visible only on desktop.
- Toggle preview mode several times.

=> `dataset.invisible` was set to `1` on all columns having
device-dependent visibility.

[1]: https://github.com/odoo/odoo/commit/acfca25e48ac9bc227234de860fe8128f0312ed4
[2]: https://github.com/odoo/odoo/commit/174e9fe0d8665d1a81c90a6f7bf5cc9e3361f161

task-3538535

closes odoo/odoo#143640

closes odoo/odoo#143875

Signed-off-by: Arthur Detroux (ard) <ard@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
This commit is contained in:
Benoit Socias
2023-11-30 07:37:13 +00:00
parent 766226df0b
commit 3fa6af39c9
2 changed files with 12 additions and 7 deletions
@@ -896,10 +896,6 @@ var SnippetEditor = Widget.extend({
if (isMobilePreview === isMobileHidden) {
// Preview mode and hidden type are the same.
show = false;
} else {
// Preview mode is not related to hidden type.
delete this.$target[0].dataset.invisible;
return false;
}
}
}
@@ -4473,9 +4469,15 @@ var SnippetsMenu = Widget.extend({
gridUtils._reloadLazyImages(gridItemEl);
}
const isMobilePreview = weUtils.isMobileView(this.$body[0]);
for (const invisibleOverrideEl of this.getEditableArea().find('.o_snippet_mobile_invisible, .o_snippet_desktop_invisible')) {
const isMobileHidden = invisibleOverrideEl.classList.contains("o_snippet_mobile_invisible");
invisibleOverrideEl.classList.remove('o_snippet_override_invisible');
invisibleOverrideEl.dataset.invisible = '1';
if (isMobilePreview === isMobileHidden) {
invisibleOverrideEl.dataset.invisible = '1';
} else {
delete invisibleOverrideEl.dataset.invisible;
}
}
// This is async but using the main editor mutex, currently locked.
@@ -2596,8 +2596,11 @@ options.registry.DeviceVisibility = options.Class.extend({
* @override
*/
async onTargetShow() {
if (this.$target[0].classList.contains('o_snippet_mobile_invisible')
|| this.$target[0].classList.contains('o_snippet_desktop_invisible')) {
const isMobilePreview = weUtils.isMobileView(this.$target[0]);
const isMobileHidden = this.$target[0].classList.contains("o_snippet_mobile_invisible");
if ((this.$target[0].classList.contains('o_snippet_mobile_invisible')
|| this.$target[0].classList.contains('o_snippet_desktop_invisible')
) && isMobilePreview === isMobileHidden) {
this.$target[0].classList.add('o_snippet_override_invisible');
}
},