mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[IMP] web_notify: Add possibility to return an action in a notification
This commit is contained in:
committed by
Laurent Stukkens
parent
dac33645f2
commit
5d1c3d5fd7
@@ -1,30 +1,43 @@
|
||||
/** @odoo-module **/
|
||||
import {Markup} from "web.utils";
|
||||
import {browser} from "@web/core/browser/browser";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
export const webNotificationService = {
|
||||
dependencies: ["notification"],
|
||||
dependencies: ["notification", "action"],
|
||||
|
||||
start(env, {notification}) {
|
||||
start(env, {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 () {
|
||||
notification.add(notif.message, {
|
||||
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,
|
||||
messageIsHtml: notif.html,
|
||||
buttons: buttons,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user