[IMP] web_notify: Add possibility to return an action in a notification

This commit is contained in:
Guewen Baconnier
2018-06-27 15:52:14 +02:00
committed by Laurent Stukkens
parent dac33645f2
commit 5d1c3d5fd7
6 changed files with 98 additions and 12 deletions

View File

@@ -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,
});
});
});