improve notification system

This commit is contained in:
Géry Debongnie
2019-01-29 16:13:05 +01:00
parent d029f87a0f
commit 0bbeabd55c
6 changed files with 62 additions and 11 deletions
+9 -3
View File
@@ -8,7 +8,7 @@ import { Env } from "./env";
const template = `
<div class="o_web_client">
<t t-widget="Navbar"/>
<div class="o_content" t-ref="content"></div>
<div class="o_content" t-ref="content"/>
<div class="o_notification_container">
<t t-foreach="state.notifications" t-as="notif">
<t t-widget="Notification" t-props="notif"/>
@@ -27,7 +27,9 @@ export class Root extends Widget<Env, {}> {
mounted() {
this.env.actionManager.on("action_ready", this, this.setContentWidget);
this.env.notifications.on("notification_added", this, this.addNotification);
this.env.notifications.on("notification_added", this, this.addNotif);
this.env.notifications.on("notification_removed", this, this.removeNotif);
const actionWidget = this.env.actionManager.getCurrentAction();
if (actionWidget) {
this.setContentWidget(actionWidget);
@@ -44,8 +46,12 @@ export class Root extends Widget<Env, {}> {
this.content = newWidget;
}
addNotification(notif: INotification) {
addNotif(notif: INotification) {
const notifications = this.state.notifications.concat(notif);
this.updateState({ notifications });
}
removeNotif(notif: INotification) {
const notifs = this.state.notifications.filter(f => f.id !== notif.id);
this.updateState({ notifications: notifs });
}
}