diff --git a/web_notify/README.rst b/web_notify/README.rst
index 27995bd1c..0cb1e547c 100644
--- a/web_notify/README.rst
+++ b/web_notify/README.rst
@@ -91,28 +91,29 @@ The notifications can bring interactivity with some buttons.
The reload button is activated when sending the notification with:
-
-The action can be used using the ``action`` keyword:
+The action can be used using the ``action`` keyword and we can choose which name to
+give to our button with the ``button_name`` key in the action context `params` key:
.. code-block:: python
action = self.env["ir.actions.act_window"]._for_xml_id('sale.action_orders')
action.update({
- 'res_id': self.id,
- 'views': [(False, 'form')],
+ 'res_id': self.id,
+ 'views': [(False, 'form')],
})
- self.env.user.notify_info('My information message', action=action)
+ action["context"].setdefault("params", {})
+ action["context"]["params"]["button_name"] = "Sales"
+ action["context"]["params"]["button_icon"] = "fa-eye"
+ self.env.user.notify_info('My information message', action=action)
-.. figure:: https://raw.githubusercontent.com/OCA/web/16.0/web_notify/static/description/notifications_screenshot.gif
- :scale: 80 %
+.. figure:: https://raw.githubusercontent.com/OCA/web/16.0/web_notify/static/img/notifications_screenshot.gif
:alt: 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.
-.. figure:: https://raw.githubusercontent.com/OCA/web/16.0/web_notify/static/description/test_notifications_demo.png
- :scale: 80 %
+.. figure:: https://raw.githubusercontent.com/OCA/web/16.0/web_notify/static/img/test_notifications_demo.png
:alt: Sample notifications
Bug Tracker
diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py
index 19b641353..1bea86266 100644
--- a/web_notify/models/res_users.py
+++ b/web_notify/models/res_users.py
@@ -3,7 +3,7 @@
from odoo import _, api, exceptions, fields, models
from odoo.addons.bus.models.bus import channel_with_db, json_dump
-from odoo.addons.web.controllers.main import clean_action
+from odoo.addons.web.controllers.utils import clean_action
DEFAULT_MESSAGE = "Default message"
diff --git a/web_notify/readme/USAGE.rst b/web_notify/readme/USAGE.rst
index c86b1ad3a..d018bc7c8 100644
--- a/web_notify/readme/USAGE.rst
+++ b/web_notify/readme/USAGE.rst
@@ -37,26 +37,27 @@ The notifications can bring interactivity with some buttons.
The reload button is activated when sending the notification with:
-
-The action can be used using the ``action`` keyword:
+The action can be used using the ``action`` keyword and we can choose which name to
+give to our button with the ``button_name`` key in the action context `params` key:
.. code-block:: python
action = self.env["ir.actions.act_window"]._for_xml_id('sale.action_orders')
action.update({
- 'res_id': self.id,
- 'views': [(False, 'form')],
+ 'res_id': self.id,
+ 'views': [(False, 'form')],
})
- self.env.user.notify_info('My information message', action=action)
+ action["context"].setdefault("params", {})
+ action["context"]["params"]["button_name"] = "Sales"
+ action["context"]["params"]["button_icon"] = "fa-eye"
+ self.env.user.notify_info('My information message', action=action)
-.. figure:: static/description/notifications_screenshot.gif
- :scale: 80 %
+.. figure:: ../static/img/notifications_screenshot.gif
:alt: 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.
-.. figure:: static/description/test_notifications_demo.png
- :scale: 80 %
+.. figure:: ../static/img/test_notifications_demo.png
:alt: Sample notifications
diff --git a/web_notify/static/description/index.html b/web_notify/static/description/index.html
index 6476ccf3f..1f49fe295 100644
--- a/web_notify/static/description/index.html
+++ b/web_notify/static/description/index.html
@@ -8,10 +8,11 @@
/*
:Author: David Goodger (goodger@python.org)
-:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
+:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
+Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -274,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
-pre.code .ln { color: grey; } /* line numbers */
+pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@ span.option {
span.pre {
white-space: pre }
-span.problematic {
+span.problematic, pre.problematic {
color: red }
span.section-subtitle {
@@ -425,22 +426,26 @@ Two kinds of notification are supported.
Another allowing to send a window / client action
The reload button is activated when sending the notification with:
-The action can be used using the action keyword:
+The action can be used using the action keyword and we can choose which name to
+give to our button with the button_name key in the action context params key:
- action = self.env["ir.actions.act_window"]._for_xml_id('sale.action_orders')
- action.update({
- 'res_id': self.id,
- 'views': [(False, 'form')],
- })
+action = self.env["ir.actions.act_window"]._for_xml_id('sale.action_orders')
+action.update({
+ 'res_id': self.id,
+ 'views': [(False, 'form')],
+})
+action["context"].setdefault("params", {})
+action["context"]["params"]["button_name"] = "Sales"
+action["context"]["params"]["button_icon"] = "fa-eye"
self.env.user.notify_info('My information message', action=action)
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.
@@ -477,7 +482,9 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
This module is maintained by the OCA.
-

+
+
+
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.
diff --git a/web_notify/static/description/notifications_screenshot.gif b/web_notify/static/description/notifications_screenshot.gif
deleted file mode 100644
index c82aa3e7e..000000000
Binary files a/web_notify/static/description/notifications_screenshot.gif and /dev/null differ
diff --git a/web_notify/static/img/notifications_screenshot.gif b/web_notify/static/img/notifications_screenshot.gif
new file mode 100644
index 000000000..d085fcaa9
Binary files /dev/null and b/web_notify/static/img/notifications_screenshot.gif differ
diff --git a/web_notify/static/description/test_notifications_demo.png b/web_notify/static/img/test_notifications_demo.png
similarity index 100%
rename from web_notify/static/description/test_notifications_demo.png
rename to web_notify/static/img/test_notifications_demo.png
diff --git a/web_notify/static/src/js/services/notification_services.esm.js b/web_notify/static/src/js/services/notification_services.esm.js
index efec2be17..491a72f65 100644
--- a/web_notify/static/src/js/services/notification_services.esm.js
+++ b/web_notify/static/src/js/services/notification_services.esm.js
@@ -10,33 +10,43 @@ export const webNotificationService = {
let webNotifTimeouts = {};
/**
* Displays the web notification on user's screen
+ * @param {*} notifications
*/
function displaywebNotification(notifications) {
Object.values(webNotifTimeouts).forEach((notif) =>
browser.clearTimeout(notif)
);
webNotifTimeouts = {};
- notifications.forEach(function (notif) {
- browser.setTimeout(function () {
- let buttons = [];
-
+ notifications.forEach((notif) => {
+ browser.setTimeout(() => {
+ var buttons = [];
if (notif.action) {
+ const params =
+ (notif.action.context && notif.action.context.params) || {};
buttons = [
{
- name: env._t("Open"),
+ name: params.button_name || env._t("Open"),
primary: true,
onClick: async () => {
await action.doAction(notif.action);
},
+ ...(params.button_icon && {icon: params.button_icon}),
},
];
}
- notification.add(Markup(notif.message), {
+ const notificationRemove = notification.add(Markup(notif.message), {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
className: notif.className,
- buttons: buttons,
+ buttons: buttons.map((button) => {
+ const onClick = button.onClick;
+ button.onClick = async () => {
+ await onClick();
+ notificationRemove();
+ };
+ return button;
+ }),
});
});
});