[FIX] web: fix issue with initial action in web client

Here is a scenario that could happen before this commit:
1. web client is started
2. it binds a callback on hashchange
3. it performs some async work (read initial action for user)
4. the user (or more likely, a tour) changes the url
5. the hashchange handler is called, and it starts a new action
6. the async work for the web client is over, it then executes the
default action and/or clicks on the first menu
7. we are now in the default action state, instead of the desired action
state (the one from the new url)

With this fix, we simply do nothing when there was an hashchange before
the initial action was done.
This commit is contained in:
Géry Debongnie
2018-04-17 09:21:18 +02:00
parent d1c873e754
commit 03d74531a3
@@ -91,6 +91,10 @@ return AbstractWebClient.extend({
bind_hashchange: function() {
var self = this;
$(window).bind('hashchange', this.on_hashchange);
var didHashChanged = false;
$(window).one('hashchange', function () {
didHashChanged = true;
});
var state = $.bbq.getState(true);
if (_.isEmpty(state) || state.action === "login") {
@@ -101,6 +105,9 @@ return AbstractWebClient.extend({
args: [[session.uid], ['action_id']],
})
.done(function(result) {
if (didHashChanged) {
return;
}
var data = result[0];
if(data.action_id) {
self.action_manager.doAction(data.action_id[0]);