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
2.0 KiB

  1. odoo.define('web_notify.WebClient', function (require) {
  2. "use strict";
  3. var WebClient = require('web.WebClient');
  4. var base_bus = require('bus.Longpolling');
  5. var session = require('web.session');
  6. require('bus.BusService');
  7. WebClient.include({
  8. show_application: function () {
  9. var res = this._super();
  10. this.start_polling();
  11. return res;
  12. },
  13. start_polling: function () {
  14. this.channel_success = 'notify_success_' + session.uid;
  15. this.channel_danger = 'notify_danger_' + session.uid;
  16. this.channel_warning = 'notify_warning_' + session.uid;
  17. this.channel_info = 'notify_info_' + session.uid;
  18. this.channel_default = 'notify_default_' + session.uid;
  19. this.call('bus_service', 'addChannel', this.channel_success);
  20. this.call('bus_service', 'addChannel', this.channel_danger);
  21. this.call('bus_service', 'addChannel', this.channel_warning);
  22. this.call('bus_service', 'addChannel', this.channel_info);
  23. this.call('bus_service', 'addChannel', this.channel_default);
  24. this.call(
  25. 'bus_service', 'on', 'notification',
  26. this, this.bus_notification);
  27. this.call('bus_service', 'startPolling');
  28. },
  29. bus_notification: function (notifications) {
  30. var self = this;
  31. _.each(notifications, function (notification) {
  32. // Not used: var channel = notification[0];
  33. var message = notification[1];
  34. self.on_message(message);
  35. });
  36. },
  37. on_message: function (message) {
  38. return this.call(
  39. 'notification', 'notify', {
  40. type: message.type,
  41. title: message.title,
  42. message: message.message,
  43. sticky: message.sticky,
  44. className: message.className,
  45. }
  46. );
  47. },
  48. });
  49. });