You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

  1. odoo.define('web_notify.WebClient', function (require) {
  2. "use strict";
  3. var WebClient = require('web.WebClient');
  4. var base_bus = require('bus.bus');
  5. WebClient.include({
  6. init: function(parent, client_options){
  7. this._super(parent, client_options);
  8. },
  9. show_application: function() {
  10. var res = this._super();
  11. this.start_polling();
  12. return res
  13. },
  14. on_logout: function() {
  15. var self = this;
  16. base_bus.bus.off('notification', this, this.bus_notification);
  17. this._super();
  18. },
  19. start_polling: function() {
  20. this.channel_warning = 'notify_warning_' + this.session.uid;
  21. this.channel_info = 'notify_info_' + this.session.uid;
  22. base_bus.bus.add_channel(this.channel_warning);
  23. base_bus.bus.add_channel(this.channel_info);
  24. base_bus.bus.on('notification', this, this.bus_notification);
  25. base_bus.bus.start_polling();
  26. },
  27. bus_notification: function(notifications) {
  28. var self = this;
  29. _.each(notifications, function (notification) {
  30. var channel = notification[0];
  31. var message = notification[1];
  32. if (channel === self.channel_warning) {
  33. self.on_message_warning(message);
  34. } else if (channel == self.channel_info) {
  35. self.on_message_info(message);
  36. }
  37. });
  38. },
  39. on_message_warning: function(message){
  40. if(this.notification_manager) {
  41. this.notification_manager.do_warn(message.title, message.message, message.sticky);
  42. }
  43. },
  44. on_message_info: function(message){
  45. if(this.notification_manager) {
  46. this.notification_manager.do_notify(message.title, message.message, message.sticky);
  47. }
  48. }
  49. });
  50. });