diff --git a/web_notify/README.rst b/web_notify/README.rst index c3fb682a406c..82967c9435a2 100644 --- a/web_notify/README.rst +++ b/web_notify/README.rst @@ -7,7 +7,7 @@ Web Notify !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:2ea37128bc36b2b82559d0718dff171b9d2e3dcde596a8c8750d6926821862fc + !! source digest: sha256:967b84f947ab892f664ee846a3d5c4e59a203a30a42264fe14fc9dd300c18c07 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png @@ -91,27 +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" + self.env.user.notify_info('My information message', action=action) -.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_notify/static/description/notifications_screenshot.gif +.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_notify/static/img/notifications_screenshot.gif :scale: 80 % :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/15.0/web_notify/static/description/test_notifications_demo.png +.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_notify/static/img/test_notifications_demo.png :scale: 80 % :alt: Sample notifications diff --git a/web_notify/readme/USAGE.rst b/web_notify/readme/USAGE.rst index c86b1ad3ac27..dba527fde494 100644 --- a/web_notify/readme/USAGE.rst +++ b/web_notify/readme/USAGE.rst @@ -37,26 +37,28 @@ 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" + self.env.user.notify_info('My information message', action=action) -.. figure:: static/description/notifications_screenshot.gif +.. figure:: ../static/img/notifications_screenshot.gif :scale: 80 % :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 +.. figure:: ../static/img/test_notifications_demo.png :scale: 80 % :alt: Sample notifications diff --git a/web_notify/static/description/index.html b/web_notify/static/description/index.html index 190cb6d18790..f5ddadc354e0 100644 --- a/web_notify/static/description/index.html +++ b/web_notify/static/description/index.html @@ -1,3 +1,4 @@ + @@ -8,10 +9,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 +276,7 @@ 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 +302,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,7 +368,7 @@

Web Notify

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:2ea37128bc36b2b82559d0718dff171b9d2e3dcde596a8c8750d6926821862fc +!! source digest: sha256:967b84f947ab892f664ee846a3d5c4e59a203a30a42264fe14fc9dd300c18c07 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

Send instant notification messages to the user in live.

@@ -425,22 +427,25 @@

Usage

  • 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"
     self.env.user.notify_info('My information message', action=action)
     
    -Sample notifications +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 +Sample notifications
    @@ -477,7 +482,9 @@

    Contributors

    Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +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.

    diff --git a/web_notify/static/description/notifications_screenshot.gif b/web_notify/static/img/notifications_screenshot.gif similarity index 100% rename from web_notify/static/description/notifications_screenshot.gif rename to web_notify/static/img/notifications_screenshot.gif 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 259b1e4fc77c..f1ae5deecdbb 100644 --- a/web_notify/static/src/js/services/notification_services.esm.js +++ b/web_notify/static/src/js/services/notification_services.esm.js @@ -16,28 +16,34 @@ export const webNotificationService = { browser.clearTimeout(notif) ); webNotifTimeouts = {}; - notifications.forEach(function (notif) { - browser.setTimeout(function () { - let buttons = []; - - if (notif.action) { - buttons = [ - { - name: env._t("Open"), - primary: true, - onClick: async () => { - await action.doAction(notif.action); - }, - }, - ]; - } - notification.add(Markup(notif.message), { + notifications.forEach((notif) => { + browser.setTimeout(() => { + const notificationRemove = notification.add(Markup(notif.message), { title: notif.title, type: notif.type, sticky: notif.sticky, className: notif.className, messageIsHtml: notif.html, - buttons: buttons, + buttons: + notif.action && + notif.action.context && + notif.action.context.params + ? [ + { + name: + notif.action.context.params.button_name || + env._t("Open"), + primary: true, + onClick: async function () { + await action.doAction(notif.action); + notificationRemove(); + }, + icon: + notif.action.context.params.button_icon || + undefined, + }, + ] + : [], }); }); });