[FIX] web_editor: remove useless snippet preview notification

Before this commit, the 'snippet_option_update' event was triggered
whether or not it was a preview update. In the preview update case,
nothing was done, ever. This commit removes the preview notification.
If it ever becomes useful, it can be restored at that moment.

This commit actually solves a bug introduced by [1]: that snippet update
notification is now triggered after a setTimeout delay to allow events
to bubble before the UI update it will trigger (in non preview mode).
The side effect this had was that, between each preview, the execution
chain was deferred of a setTimeout delay between each step (even though
previews do not update the UI). This was enough to allow for a paint
refresh.
So before this commit, if option C was selected, then the user hovered
option A then option B, the option C was visually re-enabled between A
and B. This won't be the case anymore after this commit.

Long story short: restore no-flickering when previewing options.

[1]: https://github.com/odoo/odoo/commit/2616c8950fd615561e720660bcc39e018f4061e4

Part of https://github.com/odoo/odoo/pull/55588

closes odoo/odoo#55588

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2020-08-07 08:52:19 +00:00
parent 315ba1cfeb
commit 201e10b338
2 changed files with 5 additions and 17 deletions
@@ -760,11 +760,6 @@ var SnippetEditor = Widget.extend({
* @param {OdooEvent} ev
*/
_onSnippetOptionUpdate: async function (ev) {
if (ev.data.previewMode) {
ev.data.onSuccess();
return;
}
const proms1 = Object.keys(this.styles).map(key => {
return this.styles[key].updateUI({
noVisibility: true,
@@ -2464,12 +2464,14 @@ const SnippetOptionWidget = Widget.extend({
// Call widget option methods and update $target
await this._select(previewMode, widget);
if (previewMode) {
return;
}
await new Promise(resolve => setTimeout(() => {
// Will update the UI of the correct widgets for all options
// related to the same $target/editor if necessary
// related to the same $target/editor
this.trigger_up('snippet_option_update', {
previewMode: previewMode,
onSuccess: () => resolve(),
});
// Set timeout needed so that the user event which triggered the
@@ -3210,16 +3212,7 @@ registry.BackgroundImage = SnippetOptionWidget.extend({
this.$target.removeClass('oe_img_bg');
}
if (previewMode === 'reset') {
return new Promise(resolve => {
// Will update the UI of the correct widgets for all options
// related to the same $target/editor
this.trigger_up('snippet_option_update', {
previewMode: 'reset',
onSuccess: () => resolve(),
});
});
} else {
if (previewMode !== 'reset') {
removeOnImageChangeAttrs.forEach(attr => delete this.$target[0].dataset[attr]);
this.$target.trigger('background_changed', [previewMode]);
}