diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2020-06-11 15:08:34 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2020-06-12 08:26:40 +0000 |
| commit | eaa37eaf84ebbe540f4e78b94540a1e2f6c88c07 (patch) | |
| tree | 0684c00b437b45ab0dd12c3f66b997b3fb83ce01 /addons/web/static/src/js/chrome | |
| parent | 07a3d7f31e5a77b9ff65c52d0292d7ee4595e5e4 (diff) | |
[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>
Diffstat (limited to 'addons/web/static/src/js/chrome')
| -rw-r--r-- | addons/web/static/src/js/chrome/abstract_web_client.js | 27 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/action_manager.js | 2 |
2 files changed, 20 insertions, 9 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index 7c48784bd39..0cabba1d23d 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -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; diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index 92c090827d8..7c6193be6cb 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -171,7 +171,7 @@ var ActionManager = Widget.extend({ return action; }); }).then(function(action) { - odoo.isReady = true; + self.trigger_up('webclient_started'); return action; }); }, |
