[FIX] web: force webclient to finalize its loading

When the web client is completely ready, it triggers an event "web_client_ready" on the bus
Some Mail OWL components rely on that mechanism to be mounted
i.e. DialogManager and ChatWindowManager

When eveluating the action to display at startup, the webclient mechanism
implies that we push the location hash each time a relevant data is available
e.g. menu_id etc...

Now, before this commit, since the hashchange handler is bound before that evaluation
it is actually triggered each time the JQuery bbq pushed a url state (this is in the API)
doc: http://benalman.com/code/projects/jquery-bbq/docs/files/jquery-ba-bbq-js.html#jQuery.bbq.pushState

This undercuts the initial loading promise chain to finish and the event "web_client_ready" was never triggered
preventing everything that relied on it to be mounted

After this commit, the webclient is artificially finalized, with the help of a new custom event
"webclient_started". So the event web_client_ready is triggered,
signalling to everyone it is in the dom and usable

A lot of bug persist though: the start() of webClient sometimes returns a rejected promise

It is worth noting that the hashchange mechanism is largely outdated and will change
in a more reliable way in the near future with the conversion of the webClient to OWL
the drop of JQuery BBQ and the direct reliance on window.history.pushState
doc: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#:~:text=The%20state%20object%20is%20a,the%20history%20entry's%20state%20object.
and on the window's "popstate" event
doc: https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event

This commit must be applied on the enterprise webclient too

closes odoo/odoo#52892

Related: odoo/enterprise#11114
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2020-06-12 08:26:40 +00:00
parent 07a3d7f31e
commit eaa37eaf84
2 changed files with 20 additions and 9 deletions
@@ -89,6 +89,7 @@ var AbstractWebClient = Widget.extend(KeyboardNavigationMixin, {
getScrollPosition: '_onGetScrollPosition',
scrollTo: '_onScrollTo',
set_title_part: '_onSetTitlePart',
webclient_started: '_onWebClientStarted',
},
init: function (parent) {
// a flag to determine that odoo is fully loaded
@@ -155,14 +156,6 @@ var AbstractWebClient = Widget.extend(KeyboardNavigationMixin, {
// though it has no valid session
return Promise.resolve();
}
}).then(function () {
// Listen to 'scroll' event and propagate it on main bus
self.action_manager.$el.on('scroll', core.bus.trigger.bind(core.bus, 'scroll'));
odoo.isReady = true;
core.bus.trigger('web_client_ready');
if (session.uid === 1) {
self.$el.addClass('o_is_superuser');
}
});
},
/**
@@ -544,6 +537,24 @@ var AbstractWebClient = Widget.extend(KeyboardNavigationMixin, {
throw new Error('Unknown effect type: ' + type);
}
},
/**
* Reacts to the end of the loading of the WebClient as a whole
* It allows for signalling to the rest of the ecosystem that the interface is usable
*
* @private
*/
_onWebClientStarted: function() {
if (!this.isStarted) {
// Listen to 'scroll' event and propagate it on main bus
this.action_manager.$el.on('scroll', core.bus.trigger.bind(core.bus, 'scroll'));
odoo.isReady = true;
core.bus.trigger('web_client_ready');
if (session.uid === 1) {
this.$el.addClass('o_is_superuser');
}
this.isStarted = true;
}
}
});
return AbstractWebClient;
@@ -171,7 +171,7 @@ var ActionManager = Widget.extend({
return action;
});
}).then(function(action) {
odoo.isReady = true;
self.trigger_up('webclient_started');
return action;
});
},