From 1f670ad81fb258228e657c0a6e7d9eb48d80aed0 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Wed, 20 Feb 2019 09:28:49 +0000 Subject: [PATCH] [FIX] bus: longpolling clears its handlers correctly `this._id` is overriden by the crosstab_bus, so the event handlers weren't unbound at destroy. closes odoo/odoo#31578 Signed-off-by: "Aaron Bohy (aab)" --- addons/bus/static/src/js/longpolling_bus.js | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/bus/static/src/js/longpolling_bus.js b/addons/bus/static/src/js/longpolling_bus.js index a24dcb593fd..750db65eba2 100644 --- a/addons/bus/static/src/js/longpolling_bus.js +++ b/addons/bus/static/src/js/longpolling_bus.js @@ -32,31 +32,34 @@ var LongpollingBus = Bus.extend(ServicesMixin, { init: function (parent, params) { this._super.apply(this, arguments); this._id = _.uniqueId('bus'); + + // the _id is modified by crosstab_bus, so we can't use it to unbind the events in the destroy. + this._longPollingBusId = this._id; this._options = {}; this._channels = []; // bus presence this._lastPresenceTime = new Date().getTime(); this._lastPartnersPresenceCheck = this._lastPresenceTime; - $(window).on("focus." + this._id, this._onFocusChange.bind(this, {focus: true})); - $(window).on("blur." + this._id, this._onFocusChange.bind(this, {focus: false})); - $(window).on("unload." + this._id, this._onFocusChange.bind(this, {focus: false})); + $(window).on("focus." + this._longPollingBusId, this._onFocusChange.bind(this, {focus: true})); + $(window).on("blur." + this._longPollingBusId, this._onFocusChange.bind(this, {focus: false})); + $(window).on("unload." + this._longPollingBusId, this._onFocusChange.bind(this, {focus: false})); - $(window).on("click." + this._id, this._onPresence.bind(this)); - $(window).on("keydown." + this._id, this._onPresence.bind(this)); - $(window).on("keyup." + this._id, this._onPresence.bind(this)); + $(window).on("click." + this._longPollingBusId, this._onPresence.bind(this)); + $(window).on("keydown." + this._longPollingBusId, this._onPresence.bind(this)); + $(window).on("keyup." + this._longPollingBusId, this._onPresence.bind(this)); }, /** * @override */ destroy: function () { this.stopPolling(); - $(window).off("focus." + this._id); - $(window).off("blur." + this._id); - $(window).off("unload." + this._id); - $(window).off("click." + this._id); - $(window).off("keydown." + this._id); - $(window).off("keyup." + this._id); + $(window).off("focus." + this._longPollingBusId); + $(window).off("blur." + this._longPollingBusId); + $(window).off("unload." + this._longPollingBusId); + $(window).off("click." + this._longPollingBusId); + $(window).off("keydown." + this._longPollingBusId); + $(window).off("keyup." + this._longPollingBusId); this._super(); }, //--------------------------------------------------------------------------