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.

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