2019-01-24 10:33:11 +01:00
|
|
|
import { Widget } from "../core/widget";
|
|
|
|
|
import { Navbar } from "./navbar";
|
2019-01-22 10:38:44 +01:00
|
|
|
import { Action } from "../services/actions";
|
2019-01-23 14:28:41 +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"/>
|
|
|
|
|
<div class="o_content">
|
|
|
|
|
<t t-widget="Content"/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
2019-01-24 10:33:11 +01:00
|
|
|
export class RootWidget extends Widget<Env> {
|
2019-01-22 10:38:44 +01:00
|
|
|
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);
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2019-01-22 10:38:44 +01:00
|
|
|
const actionID = parseInt(routeInfo.query.action_id);
|
2019-01-23 14:28:41 +01:00
|
|
|
let actions: Action[] = this.env.actions;
|
2019-01-22 10:38:44 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|