[FIX] web_editor: prevent removal of heading element

On a products category page, there is an element ready to host a heading
but it's not explicitly marked as unremovable so when the user tries to
remove any snippet inside it, the heading host is removed as well. This
fixes it by using the `isUnremovable` utility function instead of simply
checking for the `oe_unremovable` class.

Steps to reproduce the issue this commit fixes:
1. Go into the website module
2. Click "Shop"
3. Click "Furnitures"
4. Click "Edit"
5. Drop a title block in "Drag building blocks here to customize the
header for "Furnitures" category."
6. Click the trash bin on your snippet to remove it.

It doesn't get removed. Well now it does.

task-3383348

closes odoo/odoo#128744

X-original-commit: d1836d2830d098e2c29cca2643b0b354859daeca
Signed-off-by: Antoine Guenet (age) <age@odoo.com>
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Antoine Guenet
2023-07-17 18:13:48 +02:00
parent 4c484a9822
commit 4f5ca706ca
@@ -13,7 +13,7 @@ import {getCSSVariableValue} from "web_editor.utils";
import * as gridUtils from "@web_editor/js/common/grid_layout_utils";
import { sprintf, escape } from "@web/core/utils/strings";
const QWeb = core.qweb;
import {closestElement} from "@web_editor/js/editor/odoo-editor/src/utils/utils";
import { closestElement, isUnremovable } from "@web_editor/js/editor/odoo-editor/src/utils/utils";
import { debounce, throttleForAnimation } from "@web/core/utils/timing";
import { uniqueId } from "@web/core/utils/functions";
import { sortBy, unique } from "@web/core/utils/arrays";
@@ -201,7 +201,7 @@ var SnippetEditor = Widget.extend({
this.isTargetParentEditable = this.$target.parent().is(':o_editable');
this.isTargetMovable = this.isTargetParentEditable && this.isTargetMovable && !this.$target.hasClass('oe_unmovable');
this.isTargetRemovable = this.isTargetParentEditable && !this.$target.parent().is('[data-oe-type="image"]') && !this.$target.hasClass('oe_unremovable');
this.isTargetRemovable = this.isTargetParentEditable && !this.$target.parent().is('[data-oe-type="image"]') && !isUnremovable(this.$target[0]);
this.displayOverlayOptions = this.displayOverlayOptions || this.isTargetMovable || !this.isTargetParentEditable;
// Initialize move/clone/remove buttons
@@ -555,9 +555,10 @@ var SnippetEditor = Widget.extend({
// Consider layout-only elements (like bg-shapes) as empty
return el.matches(this.layoutElementsSelector);
});
return isEmpty && !$el.hasClass('oe_structure') && !$el.hasClass('oe_unremovable')
return isEmpty && !$el.hasClass('oe_structure')
&& !$el.parent().hasClass('carousel-item')
&& (!editor || editor.isTargetParentEditable);
&& (!editor || editor.isTargetParentEditable)
&& !isUnremovable($el[0]);
};
var editor = $parent.data('snippet-editor');