[FIX] bus: longpolling clears its handlers correctly

`this._id` is overriden by the crosstab_bus, so the event handlers
weren't unbound at destroy.

Manual forwardport of odoo/odoo#31578, as we need this for another
branch, in which it makes tests fail.

closes odoo/odoo#31579

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
This commit is contained in:
Vincent Schippefilt
2019-03-05 09:00:40 +00:00
committed by Aaron Bohy
parent 9b498247c9
commit 646db1e1b8
+15 -12
View File
@@ -32,30 +32,33 @@ 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();
$(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();
},
//--------------------------------------------------------------------------