From ad3677ba03880180873f27ac18ba841b81b2db14 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Jun 2023 16:43:59 +0700 Subject: Add web_notify addons --- web_notify/static/description/icon.png | Bin 0 -> 9455 bytes web_notify/static/description/index.html | 470 +++++++++++++++++++++ .../description/notifications_screenshot.png | Bin 0 -> 56872 bytes .../static/description/test_notifications_demo.png | Bin 0 -> 63517 bytes web_notify/static/src/js/web_client.js | 61 +++ web_notify/static/src/js/widgets/notification.js | 26 ++ web_notify/static/src/scss/webclient.scss | 24 ++ 7 files changed, 581 insertions(+) create mode 100644 web_notify/static/description/icon.png create mode 100644 web_notify/static/description/index.html create mode 100644 web_notify/static/description/notifications_screenshot.png create mode 100644 web_notify/static/description/test_notifications_demo.png create mode 100644 web_notify/static/src/js/web_client.js create mode 100644 web_notify/static/src/js/widgets/notification.js create mode 100644 web_notify/static/src/scss/webclient.scss (limited to 'web_notify/static') diff --git a/web_notify/static/description/icon.png b/web_notify/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/web_notify/static/description/icon.png differ diff --git a/web_notify/static/description/index.html b/web_notify/static/description/index.html new file mode 100644 index 0000000..e10497a --- /dev/null +++ b/web_notify/static/description/index.html @@ -0,0 +1,470 @@ + + + + + + +Web Notify + + + +
+

Web Notify

+ + +

Production/Stable License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Send instant notification messages to the user in live.

+

This technical module allows you to send instant notification messages from the server to the user in live. +Two kinds of notification are supported.

+ +

Table of contents

+ +
+

Installation

+

This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.

+
+
+

Usage

+

To send a notification to the user you just need to call one of the new methods defined on res.users:

+
+self.env.user.notify_success(message='My success message')
+
+

or

+
+self.env.user.notify_danger(message='My danger message')
+
+

or

+
+self.env.user.notify_warning(message='My warning message')
+
+

or

+
+self.env.user.notify_info(message='My information message')
+
+

or

+
+self.env.user.notify_default(message='My default message')
+
+
+Sample notifications +
+

You can test the behaviour of the notifications by installing this module in a demo database. +Access the users form through Settings -> Users & Companies. You’ll see a tab called “Test web notify”, here you’ll find two buttons that’ll allow you test the module.

+
+Sample notifications +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
  • AdaptiveCity
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_notify/static/description/notifications_screenshot.png b/web_notify/static/description/notifications_screenshot.png new file mode 100644 index 0000000..1a1062c Binary files /dev/null and b/web_notify/static/description/notifications_screenshot.png differ diff --git a/web_notify/static/description/test_notifications_demo.png b/web_notify/static/description/test_notifications_demo.png new file mode 100644 index 0000000..fcb0646 Binary files /dev/null and b/web_notify/static/description/test_notifications_demo.png differ 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, + }); + }, + }); +}); diff --git a/web_notify/static/src/js/widgets/notification.js b/web_notify/static/src/js/widgets/notification.js new file mode 100644 index 0000000..0c468ff --- /dev/null +++ b/web_notify/static/src/js/widgets/notification.js @@ -0,0 +1,26 @@ +odoo.define("web_notify.Notification", function (require) { + "use strict"; + + var Notification = require("web.Notification"); + + Notification.include({ + icon_mapping: { + success: "fa-thumbs-up", + danger: "fa-exclamation-triangle", + warning: "fa-exclamation", + info: "fa-info", + default: "fa-lightbulb-o", + }, + init: function () { + this._super.apply(this, arguments); + // Delete default classes + this.className = this.className.replace(" o_error", ""); + // Add custom icon and custom class + this.icon = + this.type in this.icon_mapping + ? this.icon_mapping[this.type] + : this.icon_mapping.default; + this.className += " o_" + this.type; + }, + }); +}); diff --git a/web_notify/static/src/scss/webclient.scss b/web_notify/static/src/scss/webclient.scss new file mode 100644 index 0000000..82f3c15 --- /dev/null +++ b/web_notify/static/src/scss/webclient.scss @@ -0,0 +1,24 @@ +.o_notification_manager { + .o_notification { + &.o_success { + color: white; + background-color: theme-color("success"); + } + &.o_danger { + color: white; + background-color: theme-color("danger"); + } + &.o_warning { + color: white; + background-color: theme-color("warning"); + } + &.o_info { + color: white; + background-color: theme-color("info"); + } + &.o_default { + color: black; + background-color: theme-color("default"); + } + } +} -- cgit v1.2.3