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,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@@ -366,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:5939f6a4cc411dab0ff9e45a43676cbcf8ecafcd7718961aee386fefc24e189d
|
||||
!! source digest: sha256:1a956defc8dc9d2b860d2c19783b48bc95edb7578e8178737badb6bae2b29cf6
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/15.0/web_notify"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_notify"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>Send instant notification messages to the user in live.</p>
|
||||
@@ -419,6 +420,21 @@ Two kinds of notification are supported.</p>
|
||||
<pre class="code python literal-block">
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_default</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My default message'</span><span class="p">)</span>
|
||||
</pre>
|
||||
<p>The notifications can bring interactivity with some buttons.</p>
|
||||
<ul class="simple">
|
||||
<li>One allowing to refresh the active view</li>
|
||||
<li>Another allowing to send a window / client action</li>
|
||||
</ul>
|
||||
<p>The reload button is activated when sending the notification with:</p>
|
||||
<p>The action can be used using the <tt class="docutils literal">action</tt> keyword:</p>
|
||||
<pre class="code python literal-block">
|
||||
<span class="n">action</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"ir.actions.act_window"</span><span class="p">]</span><span class="o">.</span><span class="n">_for_xml_id</span><span class="p">(</span><span class="s1">'sale.action_orders'</span><span class="p">)</span><span class="w">
|
||||
</span> <span class="n">action</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="w">
|
||||
</span> <span class="s1">'res_id'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">,</span><span class="w">
|
||||
</span> <span class="s1">'views'</span><span class="p">:</span> <span class="p">[(</span><span class="kc">False</span><span class="p">,</span> <span class="s1">'form'</span><span class="p">)],</span><span class="w">
|
||||
</span> <span class="p">})</span><span class="w">
|
||||
</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_info</span><span class="p">(</span><span class="s1">'My information message'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="n">action</span><span class="p">)</span>
|
||||
</pre>
|
||||
<div class="figure">
|
||||
<img alt="Sample notifications" src="https://raw.githubusercontent.com/OCA/web/15.0/web_notify/static/description/notifications_screenshot.gif" />
|
||||
</div>
|
||||
|
||||
@@ -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