[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
This commit is contained in:
committed by
qsm-odoo
parent
d210af8348
commit
cd58f04bea
@@ -4006,19 +4006,6 @@ const SnippetOptionWidget = Widget.extend({
|
||||
* @returns {Promise<boolean>|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);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user