From d3ac066ee58b175ca62a0c6402a6f85a41bcf244 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 9 Jan 2020 12:33:11 +0000 Subject: [PATCH] [REF] web_editor, *: allow to simulate notification of a widget * website This commit is simply about making the related method public instead of private (allow to better see the diff in upcoming improvement commits). Part of https://github.com/odoo/odoo/pull/42986 --- .../static/src/js/editor/snippets.options.js | 69 +++++++++---------- .../static/src/js/editor/snippets.options.js | 2 +- 2 files changed, 35 insertions(+), 36 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 fb2d2fe716f..e1dc69628a7 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -316,6 +316,31 @@ const UserValueWidget = Widget.extend({ this._methodsParams.optionsPossibleValues[methodName] = uniqArr; } }, + /** + * @param {boolean} [previewMode=false] + */ + notifyValueChange: function (previewMode) { + if (!this._methodsNames.length) { + return; + } + + const data = { + widget: this, + previewMode: previewMode || false, + }; + // TODO improve this. The preview state has to be updated only when the + // actual option _select is gonna be called... but this is delayed by a + // mutex. So, during test tours, we would notify both 'preview' and + // 'reset' before the 'preview' handling is done: and so the widget + // would be considered not in preview during that 'preview' handling. + if (previewMode === true) { + data.prepare = () => this.el.classList.add('o_we_preview'); + } else if (previewMode === 'reset') { + data.prepare = () => this.el.classList.remove('o_we_preview'); + } + + this.trigger_up('user_value_update', data); + }, /** * Adds the given widget to the known list of user value sub-widgets (useful * for container widgets). @@ -372,32 +397,6 @@ const UserValueWidget = Widget.extend({ // Private //-------------------------------------------------------------------------- - /** - * @private - * @param {boolean} [previewMode=false] - */ - _notifyValueChange: function (previewMode) { - if (!this._methodsNames.length) { - return; - } - - const data = { - widget: this, - previewMode: previewMode || false, - }; - // TODO improve this. The preview state has to be updated only when the - // actual option _select is gonna be called... but this is delayed by a - // mutex. So, during test tours, we would notify both 'preview' and - // 'reset' before the 'preview' handling is done: and so the widget - // would be considered not in preview during that 'preview' handling. - if (previewMode === true) { - data.prepare = () => this.el.classList.add('o_we_preview'); - } else if (previewMode === 'reset') { - data.prepare = () => this.el.classList.remove('o_we_preview'); - } - - this.trigger_up('user_value_update', data); - }, /** * Updates the UI to match the user value the widget currently holds (this * method is called by @see updateUI and does not perform a check to verify @@ -432,7 +431,7 @@ const UserValueWidget = Widget.extend({ } ev.preventDefault(); - this._notifyValueChange(false); + this.notifyValueChange(false); }, /** * Allows container widgets to add additional data if needed. @@ -456,7 +455,7 @@ const UserValueWidget = Widget.extend({ } ev.preventDefault(); - this._notifyValueChange(true); + this.notifyValueChange(true); }, /** * Should be called when an user event on the widget indicates a value @@ -474,7 +473,7 @@ const UserValueWidget = Widget.extend({ } ev.preventDefault(); - this._notifyValueChange('reset'); + this.notifyValueChange('reset'); }, }); @@ -1018,7 +1017,7 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({ _onColorPicked: function (ev) { this._previewColor = false; this._value = ev.data.color; - this._notifyValueChange(false); + this.notifyValueChange(false); }, /** * Called when a color button is entered -> previews the background color. @@ -1028,7 +1027,7 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({ */ _onColorHovered: function (ev) { this._previewColor = ev.data.color; - this._notifyValueChange(true); + this.notifyValueChange(true); }, /** * Called when a color button is left -> cancels the preview. @@ -1038,7 +1037,7 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({ */ _onColorLeft: function (ev) { this._previewColor = false; - this._notifyValueChange('reset'); + this.notifyValueChange('reset'); }, /** * Called when the color reset button is clicked -> removes all color @@ -1048,7 +1047,7 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({ */ _onColorReset: function () { this._value = ''; - this._notifyValueChange(false); + this.notifyValueChange(false); }, }); @@ -1135,7 +1134,7 @@ const ImagepickerUserValueWidget = UserValueWidget.extend({ this._value = dummyEl.getAttribute('src'); this.isVideo = false; } - this._notifyValueChange(false); + this.notifyValueChange(false); }); }, /** @@ -1146,7 +1145,7 @@ const ImagepickerUserValueWidget = UserValueWidget.extend({ _onRemoveImage: function (ev) { this._value = ''; this.isVideo = false; - this._notifyValueChange(false); + this.notifyValueChange(false); }, }); diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index d370e79aabe..b712081ff20 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -1220,7 +1220,7 @@ const UrlPickerUserValueWidget = InputUserValueWidget.extend({ */ _onWebsiteURLChosen: function () { $(this.inputEl).trigger('input'); - this._notifyValueChange(false); + this.notifyValueChange(false); }, });