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.

52 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. this._super();
  11. this.start_polling();
  12. },
  13. on_logout: function() {
  14. var self = this;
  15. base_bus.bus.off('notification', this, this.bus_notification);
  16. this._super();
  17. },
  18. start_polling: function() {
  19. this.channel_warning = 'notify_warning_' + this.session.uid;
  20. this.channel_info = 'notify_info_' + this.session.uid;
  21. base_bus.bus.add_channel(this.channel_warning);
  22. base_bus.bus.add_channel(this.channel_info);
  23. base_bus.bus.on('notification', this, this.bus_notification);
  24. base_bus.bus.start_polling();
  25. },
  26. bus_notification: function(notifications) {
  27. var self = this;
  28. _.each(notifications, function (notification) {
  29. var channel = notification[0];
  30. var message = notification[1];
  31. if (channel === self.channel_warning) {
  32. self.on_message_warning(message);
  33. } else if (channel == self.channel_info) {
  34. self.on_message_info(message);
  35. }
  36. });
  37. },
  38. on_message_warning: function(message){
  39. if(this.notification_manager) {
  40. this.notification_manager.do_warn(message.title, message.message, message.sticky);
  41. }
  42. },
  43. on_message_info: function(message){
  44. if(this.notification_manager) {
  45. this.notification_manager.do_notify(message.title, message.message, message.sticky);
  46. }
  47. }
  48. });
  49. });