From b96354fa5569bf12b9dad29f839e26286ec2c20e Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 12 Dec 2023 18:02:35 +0100 Subject: [PATCH] [FIX] web_editor, website: remove clone button on mega menu block Step to reproduce: - Create a mega menu - Enter edit mode and select it - You can duplicate the top level block (but not remove it) - If you duplicate it, you end up with a second top level block that you can't delete ever, even by deleting inner elements one by one. Technical details: 1. The remove button of the mega menu is already hidden thanks to commit [1] which used the `forceNoDeleteButton` editor option introduced with commit [2]. 2. The table of content snippet also need to hide both the delete and clone button. It was done in an "non-ideal" way with commit [3]. 3. The delete button removal for table of content snippet was actually improved to use the `forceNoDeleteButton` option of commit [2]. 4. It's also commit [1] which prevent the deletion of the top level block when deleting inner elements one by one: when the last one is deleted, it regenerates the whole block. This commit thus simply makes it so `forceNoDeleteButton` also hides the clone button. A first solution was made by introducing a new `forceNoCloneButton` option, but there is good chances that you always want to either hide both or show both, so merging those options for now is the simplest solution. It also takes the opportunity to remove the (now) useless code in the table of content snippet. [1]: https://github.com/odoo/odoo/commit/97810a9c40396bb27cb5779937734849d185cf1f [2]: https://github.com/odoo/odoo/commit/7ef484377a493ebe558242480d0da6b542d6c247 [3]: https://github.com/odoo/odoo/commit/9fb2dad97cfbd412bee3cb5d1358a9835e721f60#diff-ea32a091d6b1a47aeea680fa39bbc9111260cbdaf07e9f388a9d04741806ea8fR128-R129 opw-3604033 opw-3627319 closes odoo/odoo#146745 X-original-commit: 44b006778df913b847c58b3e405d2a177fcb1a7c Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Romain Derie (rde) --- .../web_editor/static/src/js/editor/snippets.editor.js | 1 + .../web_editor/static/src/js/editor/snippets.options.js | 3 ++- addons/website/static/src/js/editor/snippets.options.js | 2 +- .../static/src/snippets/s_table_of_content/options.js | 9 --------- 4 files changed, 4 insertions(+), 11 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 cbf53477829..cc8db13d61a 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -780,6 +780,7 @@ var SnippetEditor = Widget.extend({ if (option.forceNoDeleteButton) { this.$el.add($optionsSection).find('.oe_snippet_remove').addClass('d-none'); + this.$el.add($optionsSection).find('.oe_snippet_clone').addClass('d-none'); } if (option.displayOverlayOptions) { diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index c59a820068e..6fa396b3aa3 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -3253,7 +3253,8 @@ const SnippetOptionWidget = Widget.extend({ */ isTopFirstOption: false, /** - * Forces the target to not be possible to remove. + * Forces the target to not be possible to remove. It will also hide the + * clone button. * * @type {boolean} */ diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index cb1dc759999..b769c6775e1 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -3882,7 +3882,7 @@ options.registry.MegaMenuLayout = options.registry.SelectTemplate.extend({ }); /** - * Hides delete button for Mega Menu block. + * Hides delete and clone buttons for Mega Menu block. */ options.registry.MegaMenuNoDelete = options.Class.extend({ forceNoDeleteButton: true, diff --git a/addons/website/static/src/snippets/s_table_of_content/options.js b/addons/website/static/src/snippets/s_table_of_content/options.js index 9fb04952dde..1b15cf441a7 100644 --- a/addons/website/static/src/snippets/s_table_of_content/options.js +++ b/addons/website/static/src/snippets/s_table_of_content/options.js @@ -192,13 +192,4 @@ options.registry.TableOfContentNavbar = options.Class.extend({ options.registry.TableOfContentMainColumns = options.Class.extend({ forceNoDeleteButton: true, - - /** - * @override - */ - start: function () { - const leftPanelEl = this.$overlay.data('$optionsSection')[0]; - leftPanelEl.querySelector('.oe_snippet_clone').classList.add('d-none'); // TODO improve the way to do that - return this._super.apply(this, arguments); - }, });