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.

65 lines
2.4 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.all_channels = [
  20. this.channel_success,
  21. this.channel_danger,
  22. this.channel_warning,
  23. this.channel_info,
  24. this.channel_default,
  25. ];
  26. this.call('bus_service', 'addChannel', this.channel_success);
  27. this.call('bus_service', 'addChannel', this.channel_danger);
  28. this.call('bus_service', 'addChannel', this.channel_warning);
  29. this.call('bus_service', 'addChannel', this.channel_info);
  30. this.call('bus_service', 'addChannel', this.channel_default);
  31. this.call(
  32. 'bus_service', 'on', 'notification',
  33. this, this.bus_notification);
  34. this.call('bus_service', 'startPolling');
  35. },
  36. bus_notification: function (notifications) {
  37. var self = this;
  38. _.each(notifications, function (notification) {
  39. var channel = notification[0];
  40. var message = notification[1];
  41. if (
  42. self.all_channels != null &&
  43. self.all_channels.indexOf(channel) > -1
  44. ) {
  45. self.on_message(message);
  46. }
  47. });
  48. },
  49. on_message: function (message) {
  50. return this.call(
  51. 'notification', 'notify', {
  52. type: message.type,
  53. title: message.title,
  54. message: message.message,
  55. sticky: message.sticky,
  56. className: message.className,
  57. }
  58. );
  59. },
  60. });
  61. });