summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorSamuel Degueldre <sad@odoo.com>2021-01-22 10:12:21 +0000
committerSamuel Degueldre <sad@odoo.com>2021-02-04 11:29:46 +0000
commit61f410b57f1c28bd6464b86d1582c22b7fd846d5 (patch)
tree7773749a9a82228b45a0949771530a524f71d556 /addons/web_editor/static/src/js
parent80f05addf48dd57da9ae78f39116a9b23f60529a (diff)
[FIX] website, web_editor: fix empty parallax snippet not being removed
Previously, when removing all the content of a snippet, that snippet would get automatically deleted. This was not the case for parallax snippets because we previously intended the user to drop the parallax snippet, empty it, and drop other content inside of it. Recently, we added the parallax option on all snippets, rendering the previous workflow obsolete. There is now no longer any reason to keep empty parallax snippets. This commit fixes that. task-2446008 closes odoo/odoo#64907 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.editor.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js
index 3437ddf78ed..cf194d45082 100644
--- a/addons/web_editor/static/src/js/editor/snippets.editor.js
+++ b/addons/web_editor/static/src/js/editor/snippets.editor.js
@@ -36,6 +36,10 @@ var SnippetEditor = Widget.extend({
'snippet_option_update': '_onSnippetOptionUpdate',
'snippet_option_visibility_update': '_onSnippetOptionVisibilityUpdate',
},
+ layoutElementsSelector: [
+ '.o_we_shape',
+ '.o_we_bg_filter',
+ ].join(','),
/**
* @constructor
@@ -326,6 +330,17 @@ var SnippetEditor = Widget.extend({
}
if ($parent.closest(':data("snippet-editor")').length) {
+ const isEmptyAndRemovable = ($el, editor) => {
+ editor = editor || $el.data('snippet-editor');
+ const isEmpty = $el.text().trim() === ''
+ && $el.children().toArray().every(el => {
+ // Consider layout-only elements (like bg-shapes) as empty
+ return el.matches(this.layoutElementsSelector);
+ });
+ return isEmpty && !$el.hasClass('oe_structure')
+ && (!editor || editor.isTargetParentEditable);
+ };
+
var editor = $parent.data('snippet-editor');
while (!editor) {
var $nextParent = $parent.parent();
@@ -349,17 +364,10 @@ var SnippetEditor = Widget.extend({
this.trigger_up('snippet_removed');
this.destroy();
$parent.trigger('content_changed');
-
// TODO Page content changed, some elements may need to be adapted
// according to it. While waiting for a better way to handle that this
// window trigger will handle most cases.
$(window).trigger('resize');
-
- 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.