[FIX] web_editor: disable snippets on login page

On pages without visible dropzones (including if one exists in a
currently invisible snippet), snippets should not be droppable from the
editor. Up to now, the behavior did not take into account invisible
snippets, leading to confusing situatons (cf. steps to reproduce).
This commit makes sure that the drag & drop is disabled if the only spot
available is within an invisible snippet. It reenables the D&D if an
invisible snippet is shown.

Steps to reproduce:
- Go to `/web/login` and edit the page
- Most snippets can't be dragged & dropped
=> Good. There is no dropzone for them.
- Activate the cookies bar in the settings
- Go to `/web/login` and edit the page
=> The "structure" snippets can now be dragged & dropped, even though
the only place where it is possible is the cookies bar, which is
invisible. It looks like a bug for the users who try to drop blocks on
the main page and cannot.

opw-3829660

closes odoo/odoo#161210

X-original-commit: 58af56c57ca935913e81517f4a17c6b34c262301
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
Robin Lejeune (role)
2024-04-11 13:16:56 +00:00
parent 7d8ed95d1f
commit de61ecb58f
@@ -607,6 +607,7 @@ var SnippetEditor = Widget.extend({
const proms = sortBy(styles, "__order").map((style) => {
return show ? style.onTargetShow() : style.onTargetHide();
});
this.options.wysiwyg.snippetsMenu.reload_snippet_dropzones();
await Promise.all(proms);
return show;
},
@@ -3202,11 +3203,15 @@ var SnippetsMenu = Widget.extend({
var $snippet = $(this);
var $snippetBody = $snippet.find('.oe_snippet_body');
const isSanitizeForbidden = $snippet.data('oeForbidSanitize');
const filterSanitize = isSanitizeForbidden === 'form'
? $els => $els.filter((i, el) => !el.closest('[data-oe-sanitize]:not([data-oe-sanitize="allow_form"])'))
const checkSanitize = isSanitizeForbidden === "form"
? (el) => !el.closest('[data-oe-sanitize]:not([data-oe-sanitize="allow_form"])')
: isSanitizeForbidden
? $els => $els.filter((i, el) => !el.closest('[data-oe-sanitize]'))
: $els => $els;
? (el) => !el.closest('[data-oe-sanitize]')
: () => true;
const isVisible = (el) => el.closest(".o_snippet_invisible")
? !(el.offsetHeight === 0 || el.offsetWidth === 0)
: true;
const canDrop = ($els) => [...$els].some((el) => checkSanitize(el) && isVisible(el));
var check = false;
self.templateOptions.forEach((option, k) => {
@@ -3216,8 +3221,8 @@ var SnippetsMenu = Widget.extend({
k = isSanitizeForbidden ? 'forbidden/' + k : k;
cache[k] = cache[k] || {
'drop-near': option['drop-near'] ? filterSanitize(option['drop-near'].all()).length : 0,
'drop-in': option['drop-in'] ? filterSanitize(option['drop-in'].all()).length : 0,
'drop-near': option['drop-near'] ? canDrop(option['drop-near'].all()) : false,
'drop-in': option['drop-in'] ? canDrop(option['drop-in'].all()) : false,
};
check = (cache[k]['drop-near'] || cache[k]['drop-in']);
});