From 450c6853503b5d504235cd736775b641c067b381 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 25 Aug 2016 12:28:05 +0200 Subject: [PATCH] [FIX] web_tour: make sure tips are consumed before redirections If a tour step action induces a direct redirection the _consume_tip method was called while the redirection was being done. Now, _consume_tip is always called before any redirection really begins. Note: as the run method also has to detect redirections and do actions according to if there is one or not, a function has been created to implement the redirection detection. --- addons/web_tour/static/src/js/tour_manager.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index 4c55d8f35d5..e9b4400b434 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -21,6 +21,24 @@ function get_running_delay_key() { return get_running_key() + "_delay"; } +function do_before_unload(if_unload_callback, if_not_unload_callback) { + if_unload_callback = if_unload_callback || function () {}; + if_not_unload_callback = if_not_unload_callback || if_unload_callback; + + var old_before = window.onbeforeunload; + var reload_timeout; + window.onbeforeunload = function () { + clearTimeout(reload_timeout); + window.onbeforeunload = old_before; + if_unload_callback(); + if (old_before) return old_before.apply(this, arguments); + }; + reload_timeout = _.defer(function () { + window.onbeforeunload = old_before; + if_not_unload_callback(); + }); +} + var RunningTourActionHelper = core.Class.extend({ init: function (tip_widget) { this.tip_widget = tip_widget; @@ -173,13 +191,7 @@ return core.Class.extend({ if (tour.url) { this.pause(); - var old_before = window.onbeforeunload; - var reload_timeout; - window.onbeforeunload = function () { - clearTimeout(reload_timeout); - }; - reload_timeout = _.defer((function () { - window.onbeforeunload = old_before; + do_before_unload(null, (function () { this.play(); this.update(); }).bind(this)); @@ -350,6 +362,8 @@ return core.Class.extend({ var action_helper = new RunningTourActionHelper(tip.widget); _.delay((function () { + do_before_unload(this._consume_tip.bind(this, tip, tour_name)); + if (typeof tip.run === "function") { tip.run.call(tip.widget, action_helper); } else if (tip.run !== undefined) { @@ -358,7 +372,6 @@ return core.Class.extend({ } else { action_helper.auto(); } - this._consume_tip(tip, tour_name); }).bind(this), this.running_step_delay); },