preliminary support for home menu

This commit is contained in:
Géry Debongnie
2019-01-31 10:55:41 +01:00
parent 25da2b2230
commit bac075dbbd
7 changed files with 105 additions and 41 deletions
+50 -27
View File
@@ -1,50 +1,69 @@
import { Widget } from "./core/widget";
import { Navbar } from "./widgets/navbar";
import { ActionWidget } from "./services/action_manager";
import { INotification } from "./services/notifications";
import { Notification } from "./widgets/notification";
import { Env } from "./env";
import { INotification } from "./services/notifications";
import { Action } from "./widgets/action";
import { HomeMenu } from "./widgets/home_menu";
import { Navbar } from "./widgets/navbar";
import { Notification } from "./widgets/notification";
const template = `
<div class="o_web_client">
<t t-widget="Navbar"/>
<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"/>
</t>
</div>
<t t-widget="Navbar" t-props="{toggleHomeMenu:toggleHomeMenu,inMenu:state.inMenu}"/>
<t t-if="state.inMenu">
<t t-widget="HomeMenu" t-props="{toggleHomeMenu:toggleHomeMenu}"/>
</t>
<t t-else="1">
<t t-widget="Action" t-keep-alive="1"/>
</t>
<div class="o_notification_container">
<t t-foreach="state.notifications" t-as="notif">
<t t-widget="Notification" t-props="notif"/>
</t>
</div>
</div>
`;
interface State {
notifications: INotification[];
inMenu: boolean;
}
export class Root extends Widget<Env, {}> {
name = "root";
template = template;
widgets = { Navbar, Notification };
widgets = { Navbar, Notification, HomeMenu, Action };
content: Widget<Env, {}> | null = null;
state: { notifications: INotification[] } = { notifications: [] };
state: State = {
notifications: [],
inMenu: false
};
constructor(env: Env) {
super(env);
this.toggleHomeMenu = this.toggleHomeMenu.bind(this);
}
mounted() {
this.env.actionManager.on("action_ready", this, this.setContentWidget);
// this.env.actionManager.on("action_ready", this, this.setContentWidget);
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);
}
// const actionWidget = this.env.actionManager.getCurrentAction();
// if (actionWidget) {
// this.setContentWidget(actionWidget);
// }
}
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;
}
// 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;
// }
addNotif(notif: INotification) {
const notifications = this.state.notifications.concat(notif);
@@ -54,4 +73,8 @@ export class Root extends Widget<Env, {}> {
const notifs = this.state.notifications.filter(f => f.id !== notif.id);
this.updateState({ notifications: notifs });
}
toggleHomeMenu() {
this.updateState({ inMenu: !this.state.inMenu });
}
}