mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
Add possibility to return an action in a notification
This commit is contained in:
committed by
trisdoan
parent
619b8883a0
commit
557e35203a
@@ -4,27 +4,39 @@ import {browser} from "@web/core/browser/browser";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
export const webNotificationService = {
|
||||
dependencies: ["bus_service", "notification"],
|
||||
dependencies: ["bus_service", "notification", "action"],
|
||||
|
||||
start(env, {bus_service, notification}) {
|
||||
start(env, {bus_service, notification, action}) {
|
||||
let webNotifTimeouts = {};
|
||||
/**
|
||||
* Displays the web notification on user's screen
|
||||
*/
|
||||
|
||||
function displaywebNotification(notifications) {
|
||||
Object.values(webNotifTimeouts).forEach((notif) =>
|
||||
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), {
|
||||
title: notif.title,
|
||||
type: notif.type,
|
||||
sticky: notif.sticky,
|
||||
className: notif.className,
|
||||
buttons: buttons,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user