[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) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2019-10-22 11:35:38 +00:00
committed by fw-bot
parent c8dca514e6
commit 7f60eaa2a4
2 changed files with 10 additions and 9 deletions
@@ -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);
},
//--------------------------------------------------------------------------
+6 -1
View File
@@ -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;
});
});
},
/**