Files
owl/web/static/src/ts/widgets/root_widget.ts
T

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-01-24 10:33:11 +01:00
import { Widget } from "../core/widget";
import { Navbar } from "./navbar";
import { Action } from "../services/actions";
2019-01-23 14:28:41 +01:00
import { Env } from "../env";
const template = `
<div class="o_web_client">
<t t-widget="Navbar"/>
<div class="o_content">
<t t-widget="Content"/>
</div>
</div>
`;
2019-01-24 10:33:11 +01:00
export class RootWidget extends Widget<Env> {
name = "root";
template = template;
widgets = { Navbar };
constructor(env: Env) {
super(env);
this.setMainWidget();
}
mounted() {
2019-01-23 11:12:54 +01:00
this.env.router.register(this, this.onUrlChange);
}
setMainWidget() {
const action = this.getAction();
(<any>this.widgets).Content = action.Widget;
}
onUrlChange() {
this.setMainWidget();
// notice that this can only be safely done because the root widget is
// mounted now.
this.render();
}
getAction(): Action {
2019-01-23 14:28:41 +01:00
const routeInfo = this.env.router.getRoute();
const actionID = parseInt(routeInfo.query.action_id);
2019-01-23 14:28:41 +01:00
let actions: Action[] = this.env.actions;
let action = actions.find(a => a.id === actionID);
if (!action) {
action = actions.find(a => a.default === true);
if (!action) {
throw new Error("No valid action!");
}
}
return action;
}
}