2019-01-29 10:00:33 +01:00
|
|
|
import { Widget } from "./core/widget";
|
|
|
|
|
import { Navbar } from "./widgets/navbar";
|
|
|
|
|
import { ActionWidget } from "./services/action_manager";
|
2019-01-29 15:19:02 +01:00
|
|
|
import { INotification } from "./services/notifications";
|
|
|
|
|
import { Notification } from "./widgets/notification";
|
2019-01-29 10:00:33 +01:00
|
|
|
import { Env } from "./env";
|
2019-01-22 10:38:44 +01:00
|
|
|
|
|
|
|
|
const template = `
|
|
|
|
|
<div class="o_web_client">
|
|
|
|
|
<t t-widget="Navbar"/>
|
2019-01-29 16:13:05 +01:00
|
|
|
<div class="o_content" t-ref="content"/>
|
2019-01-29 15:19:02 +01:00
|
|
|
<div class="o_notification_container">
|
|
|
|
|
<t t-foreach="state.notifications" t-as="notif">
|
|
|
|
|
<t t-widget="Notification" t-props="notif"/>
|
|
|
|
|
</t>
|
2019-01-22 10:38:44 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
2019-01-29 14:41:12 +01:00
|
|
|
export class Root extends Widget<Env, {}> {
|
2019-01-22 10:38:44 +01:00
|
|
|
name = "root";
|
|
|
|
|
template = template;
|
2019-01-29 15:19:02 +01:00
|
|
|
widgets = { Navbar, Notification };
|
2019-01-28 21:32:21 +01:00
|
|
|
content: Widget<Env, {}> | null = null;
|
2019-01-22 10:38:44 +01:00
|
|
|
|
2019-01-29 15:19:02 +01:00
|
|
|
state: { notifications: INotification[] } = { notifications: [] };
|
|
|
|
|
|
2019-01-22 10:38:44 +01:00
|
|
|
mounted() {
|
2019-01-24 10:58:46 +01:00
|
|
|
this.env.actionManager.on("action_ready", this, this.setContentWidget);
|
2019-01-29 16:13:05 +01:00
|
|
|
this.env.notifications.on("notification_added", this, this.addNotif);
|
|
|
|
|
this.env.notifications.on("notification_removed", this, this.removeNotif);
|
|
|
|
|
|
2019-01-24 10:58:46 +01:00
|
|
|
const actionWidget = this.env.actionManager.getCurrentAction();
|
|
|
|
|
if (actionWidget) {
|
|
|
|
|
this.setContentWidget(actionWidget);
|
|
|
|
|
}
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-24 10:58:46 +01:00
|
|
|
async setContentWidget(actionWidget: ActionWidget) {
|
|
|
|
|
const currentWidget = this.content;
|
|
|
|
|
const newWidget = new actionWidget.Widget(this, actionWidget.props);
|
|
|
|
|
await newWidget.mount(<HTMLElement>this.refs.content);
|
|
|
|
|
if (currentWidget) {
|
|
|
|
|
currentWidget.destroy();
|
|
|
|
|
}
|
|
|
|
|
this.content = newWidget;
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|
2019-01-29 15:19:02 +01:00
|
|
|
|
2019-01-29 16:13:05 +01:00
|
|
|
addNotif(notif: INotification) {
|
2019-01-29 15:19:02 +01:00
|
|
|
const notifications = this.state.notifications.concat(notif);
|
|
|
|
|
this.updateState({ notifications });
|
|
|
|
|
}
|
2019-01-29 16:13:05 +01:00
|
|
|
removeNotif(notif: INotification) {
|
|
|
|
|
const notifs = this.state.notifications.filter(f => f.id !== notif.id);
|
|
|
|
|
this.updateState({ notifications: notifs });
|
|
|
|
|
}
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|