diff options
| author | Géry Debongnie <ged@odoo.com> | 2015-12-29 10:13:55 +0100 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2015-12-29 14:47:40 +0100 |
| commit | cc8c355ecb2ac3daa4ef7ea76707e84828185d85 (patch) | |
| tree | e19f409e1d3d67d5feaedb1d8d643f73d2273db1 /addons/bus/static/src | |
| parent | 04fce958757b2907f97d6360cb3aa32cdb9fd23d (diff) | |
[IMP] mail, bus: display native notifications if user away
This commit introduces native notifications (if available) to the
discuss application.
Those notifications will only appear if the user grants the permission
for that. A notification bar will appear in the discuss application if
necessary to prompt the user.
Also, it always is the master bus that will be the one sending the
notification.
For this change, it was necessary to be able to detect if the user has
the focus on some other odoo tabs. For this reason, the bus was
extended.
Diffstat (limited to 'addons/bus/static/src')
| -rw-r--r-- | addons/bus/static/src/js/bus.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/addons/bus/static/src/js/bus.js b/addons/bus/static/src/js/bus.js index 58ff9c216ea..b36a620afb3 100644 --- a/addons/bus/static/src/js/bus.js +++ b/addons/bus/static/src/js/bus.js @@ -32,8 +32,9 @@ bus.Bus = Widget.extend({ this.trigger('window_focus', this.is_master); } }); - $(window).on("focus", _.bind(this.window_focus, this)); - $(window).on("blur", _.bind(this.window_blur, this)); + $(window).on("focus", _.bind(this.focus_change, this, true)); + $(window).on("blur", _.bind(this.focus_change, this, false)); + $(window).on("unload", _.bind(this.focus_change, this, false)); _.each('click,keydown,keyup'.split(','), function(evtype) { $(window).on(evtype, function() { self.last_presence = new Date().getTime(); @@ -93,11 +94,8 @@ bus.Bus = Widget.extend({ this.channels = _.without(this.channels, channel); }, // bus presence : window focus/unfocus - window_focus: function() { - this.set("window_focus", true); - }, - window_blur: function() { - this.set("window_focus", false); + focus_change: function(focus) { + this.set("window_focus", focus); }, is_odoo_focused: function () { return this.get("window_focus"); @@ -211,6 +209,10 @@ var CrossTabBus = bus.Bus.extend({ if(e.key === 'bus.options'){ this.options = JSON.parse(value); } + // update focus + if(e.key === 'bus.focus'){ + this.set('window_focus', JSON.parse(value)); + } }, add_channel: function(){ this._super.apply(this, arguments); @@ -231,6 +233,10 @@ var CrossTabBus = bus.Bus.extend({ this._super.apply(this, arguments); setItem('bus.options', this.options); }, + focus_change: function(focus) { + this._super.apply(this, arguments); + setItem('bus.focus', focus); + }, }); |
