|
|
@ -21,66 +21,44 @@ odoo.define('muk_web_client.channel', function (require) { |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
var WebClient = require('web.WebClient'); |
|
|
|
var session = require('web.session'); |
|
|
|
var bus = require('bus.bus'); |
|
|
|
var BusService = require('bus.BusService'); |
|
|
|
|
|
|
|
WebClient.include({ |
|
|
|
init: function(parent, client_options){ |
|
|
|
this._super.apply(this, arguments); |
|
|
|
this.bus_channels = []; |
|
|
|
this.bus_events = []; |
|
|
|
}, |
|
|
|
show_application: function() { |
|
|
|
var res = this._super(); |
|
|
|
bus.bus.on('notification', this, this.bus_notification); |
|
|
|
bus.bus.start_polling(); |
|
|
|
return res; |
|
|
|
}, |
|
|
|
destroy: function() { |
|
|
|
var self = this; |
|
|
|
bus.bus.off('notification', this, this.bus_notification); |
|
|
|
$.each(this.bus_channels, function(index, channel) { |
|
|
|
self.bus_delete_channel(channel); |
|
|
|
}); |
|
|
|
$.each(this.bus_events, function(index, event) { |
|
|
|
self.bus_off(event[0], event[1]); |
|
|
|
}); |
|
|
|
this._super.apply(this, arguments); |
|
|
|
this.bus_channels = {}; |
|
|
|
}, |
|
|
|
bus_declare_channel: function(channel, method) { |
|
|
|
if($.inArray(channel, this.bus_channels) === -1) { |
|
|
|
this.bus_on(channel, method); |
|
|
|
this.bus_channels.push(channel); |
|
|
|
bus.bus.add_channel(channel); |
|
|
|
if(!(channel in this.bus_channels)) { |
|
|
|
this.bus_channels[channel] = method; |
|
|
|
this.call('bus_service', 'addChannel', channel); |
|
|
|
} |
|
|
|
}, |
|
|
|
bus_delete_channel: function(channel) { |
|
|
|
var index = $.inArray(channel, this.bus_channels); |
|
|
|
bus.bus.delete_channel(channel); |
|
|
|
this.bus_channels.splice(index, 1); |
|
|
|
this.call('bus_service', 'deleteChannel', channel); |
|
|
|
this.bus_channels = _.omit(this.bus_channels, channel); |
|
|
|
}, |
|
|
|
show_application: function() { |
|
|
|
var res = this._super.apply(this, arguments); |
|
|
|
this.call('bus_service', 'onNotification', this, this.bus_notification); |
|
|
|
this.call('bus_service', 'startPolling'); |
|
|
|
return res; |
|
|
|
}, |
|
|
|
bus_notification: function(notifications) { |
|
|
|
var self = this; |
|
|
|
$.each(notifications, function(index, notification) { |
|
|
|
_.each(notifications, function(notification, index) { |
|
|
|
var channel = notification[0]; |
|
|
|
var message = notification[1]; |
|
|
|
if($.inArray(channel, self.bus_channels) !== -1) { |
|
|
|
bus.bus.trigger(channel, message); |
|
|
|
} |
|
|
|
}); |
|
|
|
if(channel in this.bus_channels) { |
|
|
|
this.bus_channels[channel](message); |
|
|
|
} |
|
|
|
}, this); |
|
|
|
}, |
|
|
|
bus_on: function(name, event) { |
|
|
|
bus.bus.on(name, this, event); |
|
|
|
this.bus_events.push([name, event]); |
|
|
|
}, |
|
|
|
bus_off: function(name, event) { |
|
|
|
var index = $.map(this.bus_events, function(tuple, index) { |
|
|
|
if(tuple[0] === name && tuple[1] === event) { |
|
|
|
return index; |
|
|
|
} |
|
|
|
}); |
|
|
|
bus.bus.off(name, this, event); |
|
|
|
this.bus_events.splice(index, 1); |
|
|
|
destroy: function() { |
|
|
|
_.each(this.bus_channels, function(method, channel) { |
|
|
|
this.bus_delete_channel(channel); |
|
|
|
}, this); |
|
|
|
this.call('bus_service', 'stopPolling'); |
|
|
|
this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|