From a535d7c6fb5a6abe083e7d665d7243f5061a4773 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 24 Jun 2022 07:49:01 +0000 Subject: [PATCH] [FIX] web_tour: native events + better error messages This commit is two-fold: 1) events triggered with jQuery do not go through the native layer, so if an handler has been bound natively, it won't be called. Since our new code no longer uses jQuery, this caused issue in some tours. 2) this commit explicitely logs the failing step when a tour crashes, which helps debugging. Part-of: odoo/odoo#92475 --- .../web_tour/static/src/js/running_tour_action_helper.js | 2 +- addons/web_tour/static/src/js/tour_manager.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/web_tour/static/src/js/running_tour_action_helper.js b/addons/web_tour/static/src/js/running_tour_action_helper.js index cee5a221cc4..f0c27750b4a 100644 --- a/addons/web_tour/static/src/js/running_tour_action_helper.js +++ b/addons/web_tour/static/src/js/running_tour_action_helper.js @@ -110,7 +110,7 @@ var RunningTourActionHelper = core.Class.extend({ values.$element.focusInEnd(); values.$element.trigger($.Event( "keyup", {key: '_', keyCode: 95})); } - values.$element.trigger("change"); + values.$element[0].dispatchEvent(new Event("change", { bubbles: true, cancelable: false })); }, _text_blur: function (values, text) { this._text(values, text); diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index 8e180c96150..a6b35709cce 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -189,7 +189,7 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { // redirect to its starting point (or /web by default) window.location.href = window.location.origin + (tour.url || '/web'); }, - run: function (tour_name, step_delay) { + run: async function (tour_name, step_delay) { console.log(_.str.sprintf("Preparing tour %s", tour_name)); if (this.running_tour) { this._deactivate_tip(this.active_tooltips[this.running_tour]); @@ -534,7 +534,12 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { tip.run.call(tip.widget, action_helper); } else if (tip.run !== undefined) { var m = tip.run.match(/^([a-zA-Z0-9_]+) *(?:\(? *(.+?) *\)?)?$/); - action_helper[m[1]](m[2]); + try { + action_helper[m[1]](m[2]); + } catch (e) { + console.error(`Tour ${tour_name} failed at step ${self._describeTip(tip)}: ${e.message}`); + throw e; + } } else if (tour.current_step === tour.steps.length - 1) { console.log('Tour %s: ignoring action (auto) of last step', tour_name); } else {