From 7f60eaa2a41176ed578c8dd8a28f79a3c2b37de4 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 22 Oct 2019 08:13:18 +0000 Subject: [PATCH] [FIX] website: solve asynchronous action demands in the editor Since saas-12.3, deferred actions use native promises. This has the annoying side-effect of force-deferring promises even if they are resolved at once... and we relied on the opposite behavior for some call made in _setActive or option methods. In master, we should review the async logic of snippet options. Right now we will rely on the fact those promises are resolved at once but that we need to avoid for their "async part" anyway. The _setActive method and the option methods are thus still working synchronously in stable, despite the new force-deferring promises. Also, with old promises, when we waited for the resolution of multiple deferred, the resolve handler received the multiple results as individual arguments. Now it receives all the results in an array as a single argument. The resolution of action demands had to be adapted. closes odoo/odoo#39171 X-original-commit: 30d15315a73c1fa34ada86371b06c02b6375db89 Signed-off-by: Quentin Smetz (qsm) --- .../website/static/src/js/editor/snippets.options.js | 12 ++++-------- addons/website/static/src/js/menu/navbar.js | 7 ++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 114ccb61653..8e0f4b2dc4a 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -1521,15 +1521,13 @@ options.registry.topMenuTransparency = options.Class.extend({ _setActive: function () { this._super.apply(this, arguments); - var enabled; this.trigger_up('action_demand', { actionName: 'get_page_option', params: ['header_overlay'], - onSuccess: function (value) { - enabled = value; + onSuccess: value => { + this.$el.find('[data-transparent]').toggleClass('active', !!value); }, }); - this.$el.find('[data-transparent]').toggleClass('active', !!enabled); }, }); @@ -1549,15 +1547,13 @@ options.registry.topMenuColor = options.registry.colorpicker.extend({ * @override */ onFocus: function () { - var enabled; this.trigger_up('action_demand', { actionName: 'get_page_option', params: ['header_overlay'], - onSuccess: function (value) { - enabled = value; + onSuccess: value => { + this.$el.toggleClass('d-none', !value); }, }); - this.$el.toggleClass('d-none', !enabled); }, //-------------------------------------------------------------------------- diff --git a/addons/website/static/src/js/menu/navbar.js b/addons/website/static/src/js/menu/navbar.js index 91f754d24fc..3c3f916ab18 100644 --- a/addons/website/static/src/js/menu/navbar.js +++ b/addons/website/static/src/js/menu/navbar.js @@ -110,7 +110,12 @@ var WebsiteNavbar = publicWidget.RootWidget.extend({ return self._handleAction(actionName, params, (_i || 0) + 1); }); } - return Promise.all(defs); + return Promise.all(defs).then(function (values) { + if (values.length === 1) { + return values[0]; + } + return values; + }); }); }, /**