mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
preliminary support for home menu
This commit is contained in:
+50
-27
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user