From a30cc3402d1ba2678bf2219a33972aff3ef65592 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 17 Jul 2020 08:45:06 +0000 Subject: [PATCH] [FIX] web_editor: restore background videos (new imagepicker UI) Commit [1] broke the background videos feature. This is because the 'we-imagepicker' widget is now a sub-widget of a new 'we-button-group' widget, acting as a selection choice (same as we-button in a we-select). When selecting a selection choice, the appropriate option method is called, with the selection value and params... but the params were actually the ones of the 'we-button-group' element and not the ones of the chosen widget 'we-imagepicker'. This has never been important for we-select widgets but it could have been. The problem is only solved here in master, generically for all selection widgets (currently only 'we-select' and 'we-button-group'). The params received are the ones of the active sub-widget combined with the ones of the selection widget. [1]: https://github.com/odoo/odoo/commit/bb0cd4d5c82a9c2311f8c45ced0e9fdc0397d292 closes odoo/odoo#54629 Signed-off-by: Quentin Smetz (qsm) --- .../static/src/js/editor/snippets.options.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 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 eb36cc762ff..deeb85dbceb 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -700,11 +700,19 @@ const BaseSelectionUserValueWidget = UserValueWidget.extend({ /** * @override */ - getValue(methodName) { - let activeWidget = this._userValueWidgets.find(widget => widget.isPreviewed()); + getMethodsParams(methodName) { + const params = this._super(...arguments); + const activeWidget = this._getActiveSubWidget(); if (!activeWidget) { - activeWidget = this._userValueWidgets.find(widget => widget.isActive()); + return params; } + return Object.assign(activeWidget.getMethodsParams(...arguments), params); + }, + /** + * @override + */ + getValue(methodName) { + const activeWidget = this._getActiveSubWidget(); if (activeWidget) { return activeWidget.getActiveValue(methodName); } @@ -733,6 +741,22 @@ const BaseSelectionUserValueWidget = UserValueWidget.extend({ } this._super(...arguments); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @returns {UserValueWidget|undefined} + */ + _getActiveSubWidget() { + const previewedWidget = this._userValueWidgets.find(widget => widget.isPreviewed()); + if (previewedWidget) { + return previewedWidget; + } + return this._userValueWidgets.find(widget => widget.isActive()); + }, }); const SelectUserValueWidget = BaseSelectionUserValueWidget.extend({