From 1c6d6b1dccb478a5cfe0d2983710058073d5d9e7 Mon Sep 17 00:00:00 2001 From: git_admin Date: Mon, 27 Apr 2026 08:47:29 +0000 Subject: [PATCH] Tower: upload web_notify 16.0.3.2.0 (via marketplace) --- .../js/services/notification_services.esm.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 addons/web_notify/static/src/js/services/notification_services.esm.js diff --git a/addons/web_notify/static/src/js/services/notification_services.esm.js b/addons/web_notify/static/src/js/services/notification_services.esm.js new file mode 100644 index 0000000..4eed219 --- /dev/null +++ b/addons/web_notify/static/src/js/services/notification_services.esm.js @@ -0,0 +1,70 @@ +/** @odoo-module **/ +import {Markup} from "web.utils"; +import {browser} from "@web/core/browser/browser"; +import {registry} from "@web/core/registry"; + +export const webNotificationService = { + dependencies: ["bus_service", "action", "notification_sound"], + + start(env, {bus_service, action, notification_sound}) { + let webNotifTimeouts = {}; + /** + * Displays the web notification with sound on user's screen + * @param {*} notifications + */ + function displaywebNotification(notifications) { + Object.values(webNotifTimeouts).forEach((notif) => + browser.clearTimeout(notif) + ); + webNotifTimeouts = {}; + notifications.forEach((notif) => { + browser.setTimeout(() => { + var buttons = []; + if (notif.action) { + const params = + (notif.action.context && notif.action.context.params) || {}; + buttons = [ + { + name: params.button_name || env._t("Open"), + primary: true, + onClick: async () => { + await action.doAction(notif.action); + }, + ...(params.button_icon && {icon: params.button_icon}), + }, + ]; + } + const notificationRemove = notification_sound.add( + Markup(notif.message), + { + title: notif.title, + type: notif.type, + sticky: notif.sticky, + className: notif.className, + buttons: buttons.map((button) => { + const onClick = button.onClick; + button.onClick = async () => { + await onClick(); + notificationRemove(); + }; + return button; + }), + sound: notif.sound, + } + ); + }); + }); + } + + bus_service.addEventListener("notification", ({detail: notifications}) => { + for (const {payload, type} of notifications) { + if (type === "web.notify") { + displaywebNotification(payload); + } + } + }); + bus_service.start(); + }, +}; + +registry.category("services").add("webNotification", webNotificationService);