[FIX] web_editor: prevent removing a main editable area

When a snippet part is removed, like a column, we check that one of
its ancestor has a snippet editor attached and we remove all the empty
element up to and including that ancestor if possible. This way, if we
remove the last column of most snippet, the whole snippet is removed.

The problem is when that ancestor is a main editable area that should
not be able to be removed.

The case is currently probably never occuring but it could be backported
if needed. This is made in preparation of the mega menu task, during
whose implementation it was discovered.
This commit is contained in:
qsm-odoo
2019-09-03 15:31:42 +00:00
parent d73d7b0724
commit 2d64bb58cd
@@ -206,17 +206,17 @@ var SnippetEditor = Widget.extend({
}
if ($parent.closest(':data("snippet-editor")').length) {
while (!$parent.data('snippet-editor')) {
var editor = $parent.data('snippet-editor');
while (!editor) {
var $nextParent = $parent.parent();
if ($parent.children().length === 0 && $parent.text().trim() === '' && !$parent.hasClass('oe_structure')) {
if (isEmptyAndRemovable($parent)) {
$parent.remove();
}
$parent = $nextParent;
editor = $parent.data('snippet-editor');
}
if ($parent.children().length === 0 && $parent.text().trim() === '' && !$parent.hasClass('oe_structure')) {
_.defer(function () {
$parent.data('snippet-editor').removeSnippet();
});
if (isEmptyAndRemovable($parent, editor)) {
setTimeout(() => editor.removeSnippet());
}
}
@@ -227,6 +227,12 @@ var SnippetEditor = Widget.extend({
this.trigger_up('snippet_removed');
this.destroy();
$parent.trigger('content_changed');
function isEmptyAndRemovable($el, editor) {
editor = editor || $el.data('snippet-editor');
return $el.children().length === 0 && $el.text().trim() === ''
&& !$el.hasClass('oe_structure') && (!editor || editor.isTargetParentEditable);
}
},
/**
* Displays/Hides the editor overlay and notifies the associated snippet