From f6fccdbdced3de86bce14794e70f952df2eae587 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 23 Mar 2022 16:26:43 +0000 Subject: [PATCH] [FIX] website: propagate action_demand onFailure to promises Before this commit The code called `action_demand` without specifying a failure method. In website, there is bug arising where a promises is not rejected causing spinner of the sidebar of the website builder to never stop. After this commit Failure is propagated and the website builder bug does not prevent the user from continuing to work. closes odoo/odoo#87125 Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet --- .../static/src/js/editor/snippets.options.js | 18 ++++++++++++------ addons/website/static/src/js/menu/customize.js | 1 + .../website/static/src/js/menu/new_content.js | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 12fe10b2859..093c762f16e 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -2067,11 +2067,12 @@ const VisibilityPageOptionUpdate = options.Class.extend({ */ async visibility(previewMode, widgetValue, params) { const show = (widgetValue !== 'hidden'); - await new Promise(resolve => { + await new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'toggle_page_option', params: [{name: this.pageOptionName, value: show}], onSuccess: () => resolve(), + onFailure: reject, }); }); this.trigger_up('snippet_option_visibility_update', {show: show}); @@ -2096,11 +2097,12 @@ const VisibilityPageOptionUpdate = options.Class.extend({ * @returns {boolean} */ async _isShown() { - return new Promise(resolve => { + return new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'get_page_option', params: [this.pageOptionName], onSuccess: v => resolve(!!v), + onFailure: reject, }); }); }, @@ -2141,21 +2143,23 @@ options.registry.TopMenuVisibility = VisibilityPageOptionUpdate.extend({ return; } const transparent = (widgetValue === 'transparent'); - await new Promise(resolve => { + await new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'toggle_page_option', params: [{name: 'header_overlay', value: transparent}], onSuccess: () => resolve(), + onFailure: reject, }); }); if (!transparent) { return; } - await new Promise(resolve => { + await new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'toggle_page_option', params: [{name: 'header_color', value: ''}], onSuccess: () => resolve(), + onFailure: reject, }); }); }, @@ -2165,11 +2169,12 @@ options.registry.TopMenuVisibility = VisibilityPageOptionUpdate.extend({ async _computeWidgetState(methodName, params) { const _super = this._super.bind(this); if (methodName === 'visibility') { - this.shownValue = await new Promise(resolve => { + this.shownValue = await new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'get_page_option', params: ['header_overlay'], onSuccess: v => resolve(v ? 'transparent' : 'regular'), + onFailure: reject, }); }); } @@ -2207,11 +2212,12 @@ options.registry.topMenuColor = options.Class.extend({ if (!show) { return false; } - return new Promise(resolve => { + return new Promise((resolve, reject) => { this.trigger_up('action_demand', { actionName: 'get_page_option', params: ['header_overlay'], onSuccess: value => resolve(!!value), + onFailure: reject, }); }); }, diff --git a/addons/website/static/src/js/menu/customize.js b/addons/website/static/src/js/menu/customize.js index a82572f00eb..f2d8e923fdf 100644 --- a/addons/website/static/src/js/menu/customize.js +++ b/addons/website/static/src/js/menu/customize.js @@ -180,6 +180,7 @@ var AceEditorMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ self.trigger_up('action_demand', { actionName: 'close_all_widgets', onSuccess: resolve, + onFailure: reject, }); }); prom.then(function () { diff --git a/addons/website/static/src/js/menu/new_content.js b/addons/website/static/src/js/menu/new_content.js index 3857477b804..1eac6393be9 100644 --- a/addons/website/static/src/js/menu/new_content.js +++ b/addons/website/static/src/js/menu/new_content.js @@ -179,6 +179,7 @@ var NewContentMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ self.trigger_up('action_demand', { actionName: 'close_all_widgets', onSuccess: resolve, + onFailure: reject, }); }).then(function () { self.firstTab = true;