From cd58f04bea1f491555b314d99c8804d9a40b05c9 Mon Sep 17 00:00:00 2001 From: "Robin Lejeune (role)" Date: Tue, 11 Jul 2023 14:04:29 +0200 Subject: [PATCH] [REF] web_editor: move logic from SnippetOptionWidget to SnippetMove The logic done in the `_computeWidgetVisibility()` method of the main `SnippetOptionWidget` should have been placed in the `SnippetMove` sub-widget as an override method. This commit moves the logic at its right place and removes an unneeded condition. task-3097045 Part-of: odoo/odoo#117562 --- .../static/src/js/editor/snippets.options.js | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) 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 0c71c8411b1..b9d5c3357a3 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -4006,19 +4006,6 @@ const SnippetOptionWidget = Widget.extend({ * @returns {Promise|boolean} */ _computeWidgetVisibility: async function (widgetName, params) { - const moveUpOrLeft = widgetName === 'move_up_opt' || widgetName === 'move_left_opt'; - const moveDownOrRight = widgetName === 'move_down_opt' || widgetName === 'move_right_opt'; - - if (moveUpOrLeft || moveDownOrRight) { - // The arrows are not displayed if the target is in a grid and if - // not in mobile view. - const isMobileView = weUtils.isMobileView(this.$target[0]); - if (this.$target[0].classList.contains('o_grid_item') && !isMobileView) { - return false; - } - const firstOrLastChild = moveUpOrLeft ? ':first-child' : ':last-child'; - return !this.$target.is(firstOrLastChild); - } return true; }, /** @@ -4699,16 +4686,6 @@ registry.sizing = SnippetOptionWidget.extend({ const moveHandleEl = this.$overlay[0].querySelector('.o_move_handle'); moveHandleEl.classList.toggle('d-none', isMobileView); - // Hiding/showing the arrows. - if (isGrid) { - const moveLeftArrowEl = this.$overlay[0].querySelector('.fa-angle-left'); - const moveRightArrowEl = this.$overlay[0].querySelector('.fa-angle-right'); - const showLeft = await this._computeWidgetVisibility('move_left_opt'); - const showRight = await this._computeWidgetVisibility('move_right_opt'); - moveLeftArrowEl.classList.toggle('d-none', !showLeft); - moveRightArrowEl.classList.toggle('d-none', !showRight); - } - // Show/hide the buttons to send back/front a grid item. const bringFrontBackEls = this.$overlay[0].querySelectorAll('.o_front_back'); bringFrontBackEls.forEach(button => button.classList.toggle('d-none', !isGrid || isMobileView)); @@ -5578,6 +5555,30 @@ registry.SnippetMove = SnippetOptionWidget.extend({ // snippets could have changed on the page. this.trigger_up("update_invisible_dom"); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + async _computeWidgetVisibility(widgetName, params) { + const moveUpOrLeft = widgetName === "move_up_opt" || widgetName === "move_left_opt"; + const moveDownOrRight = widgetName === "move_down_opt" || widgetName === "move_right_opt"; + + if (moveUpOrLeft || moveDownOrRight) { + // The arrows are not displayed if the target is in a grid and if + // not in mobile view. + const isMobileView = weUtils.isMobileView(this.$target[0]); + if (!isMobileView && this.$target[0].classList.contains("o_grid_item")) { + return false; + } + const firstOrLastChild = moveUpOrLeft ? ":first-child" : ":last-child"; + return !this.$target.is(firstOrLastChild); + } + return this._super(...arguments); + }, }); /**