summaryrefslogtreecommitdiff
path: root/web_notify/static/src/js/web_client.js
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-06-16 16:43:59 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-06-16 16:43:59 +0700
commitad3677ba03880180873f27ac18ba841b81b2db14 (patch)
tree27583b6e5e9c52286e2ceb2761e5c1e9fe0f5e47 /web_notify/static/src/js/web_client.js
parente6e43d9e597551be2f8a1bad3fe400b60c102361 (diff)
Add web_notify addons
Diffstat (limited to 'web_notify/static/src/js/web_client.js')
-rw-r--r--web_notify/static/src/js/web_client.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/web_notify/static/src/js/web_client.js b/web_notify/static/src/js/web_client.js
new file mode 100644
index 0000000..a576dcd
--- /dev/null
+++ b/web_notify/static/src/js/web_client.js
@@ -0,0 +1,61 @@
+odoo.define("web_notify.WebClient", function (require) {
+ "use strict";
+
+ var WebClient = require("web.WebClient");
+ var session = require("web.session");
+ require("bus.BusService");
+
+ WebClient.include({
+ show_application: function () {
+ var res = this._super();
+ this.start_polling();
+ return res;
+ },
+ start_polling: function () {
+ this.channel_success = "notify_success_" + session.uid;
+ this.channel_danger = "notify_danger_" + session.uid;
+ this.channel_warning = "notify_warning_" + session.uid;
+ this.channel_info = "notify_info_" + session.uid;
+ this.channel_default = "notify_default_" + session.uid;
+ this.all_channels = [
+ this.channel_success,
+ this.channel_danger,
+ this.channel_warning,
+ this.channel_info,
+ this.channel_default,
+ ];
+ this.call("bus_service", "startPolling");
+
+ if (this.call("bus_service", "isMasterTab")) {
+ this.call("bus_service", "addChannel", this.channel_success);
+ this.call("bus_service", "addChannel", this.channel_danger);
+ this.call("bus_service", "addChannel", this.channel_warning);
+ this.call("bus_service", "addChannel", this.channel_info);
+ this.call("bus_service", "addChannel", this.channel_default);
+ }
+ this.call("bus_service", "on", "notification", this, this.bus_notification);
+ },
+ bus_notification: function (notifications) {
+ var self = this;
+ _.each(notifications, function (notification) {
+ var channel = notification[0];
+ var message = notification[1];
+ if (
+ self.all_channels !== null &&
+ self.all_channels.indexOf(channel) > -1
+ ) {
+ self.on_message(message);
+ }
+ });
+ },
+ on_message: function (message) {
+ return this.call("notification", "notify", {
+ type: message.type,
+ title: message.title,
+ message: message.message,
+ sticky: message.sticky,
+ className: message.className,
+ });
+ },
+ });
+});