Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
11
web_notify/static/src/js/services/notification.esm.js
Executable file
11
web_notify/static/src/js/services/notification.esm.js
Executable file
@@ -0,0 +1,11 @@
|
||||
import {Notification} from "@web/core/notifications/notification";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
|
||||
patch(Notification.props, {
|
||||
type: {
|
||||
type: String,
|
||||
optional: true,
|
||||
validate: (t) =>
|
||||
["warning", "danger", "success", "info", "default"].includes(t),
|
||||
},
|
||||
});
|
||||
52
web_notify/static/src/js/services/notification_services.esm.js
Executable file
52
web_notify/static/src/js/services/notification_services.esm.js
Executable file
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user