Files
Odoo-18.0-20251222/web_notify/static/src/js/services/notification_services.esm.js
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

53 lines
1.9 KiB
JavaScript
Executable File

import {markup} from "@odoo/owl";
import {registry} from "@web/core/registry";
export const webNotificationService = {
dependencies: ["bus_service", "notification", "action"],
start(env, {bus_service, notification: notificationService, action}) {
function displayWebNotification(notification) {
let buttons = [];
if (notification.action) {
const params = notification.action.context?.params || {};
buttons = [
{
name: params.button_name || env._t("Open"),
primary: true,
onClick: async () => {
await action.doAction(notification.action);
},
...(params.button_icon && {icon: params.button_icon}),
},
];
}
const notificationRemove = notificationService.add(
markup(notification.message),
{
title: notification.title,
type: notification.type,
sticky: notification.sticky,
className: notification.className,
messageIsHtml: notification.html,
buttons: buttons.map((button) => {
const onClick = button.onClick;
button.onClick = async () => {
await onClick();
notificationRemove();
};
return button;
}),
}
);
}
bus_service.subscribe("web_notify", (payload) => {
displayWebNotification(payload);
});
bus_service.start();
},
};
registry.category("services").add("webNotification", webNotificationService);