2019-02-05 16:04:02 +01:00
|
|
|
import { debounce } from "../core/utils";
|
2019-02-19 20:47:21 +01:00
|
|
|
import { Env } from "../env";
|
2019-03-07 12:15:12 +01:00
|
|
|
import { Controller } from "../store/action_manager_mixin";
|
2019-02-27 13:48:36 +01:00
|
|
|
import { State, Store } from "../store/store";
|
2019-03-07 12:15:12 +01:00
|
|
|
import { Widget } from "../widget";
|
2019-02-02 16:51:24 +01:00
|
|
|
import { HomeMenu } from "./home_menu";
|
|
|
|
|
import { Navbar } from "./navbar";
|
|
|
|
|
import { Notification } from "./notification";
|
2019-01-31 10:55:41 +01:00
|
|
|
|
2019-01-31 13:19:30 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Root Widget
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
export class Root extends Widget<Store, State> {
|
2019-02-03 14:07:25 +01:00
|
|
|
template = "web.web_client";
|
2019-03-04 15:47:51 +01:00
|
|
|
widgets = { Navbar, HomeMenu, Notification };
|
2019-01-22 10:38:44 +01:00
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
store: Store;
|
2019-02-18 11:51:01 +01:00
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
constructor(env: Env, store: Store) {
|
|
|
|
|
super(env, store);
|
|
|
|
|
this.store = store;
|
|
|
|
|
this.state = store.state;
|
2019-02-04 13:23:41 +01:00
|
|
|
}
|
2019-03-04 15:47:51 +01:00
|
|
|
|
2019-01-22 10:38:44 +01:00
|
|
|
mounted() {
|
2019-03-06 09:56:39 +01:00
|
|
|
this.store.on("state_updated", this, this.updateState);
|
2019-03-06 14:28:41 +01:00
|
|
|
this.store.on("rpc_status", this, this.toggleLoadingIndicator);
|
2019-03-06 14:59:17 +01:00
|
|
|
this.store.on("update_action", this, this.applyController);
|
|
|
|
|
if (this.store.lastController) {
|
|
|
|
|
this.applyController(this.store.lastController);
|
2019-03-04 12:52:14 +01:00
|
|
|
}
|
2019-03-06 14:28:41 +01:00
|
|
|
|
|
|
|
|
// adding reactiveness to mobile/non mobile
|
|
|
|
|
window.addEventListener("resize", <any>(
|
|
|
|
|
debounce(this.applyMobileInterface.bind(this), 50)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyMobileInterface() {
|
|
|
|
|
const isMobile = window.innerWidth <= 768;
|
|
|
|
|
if (isMobile !== this.env.isMobile) {
|
|
|
|
|
this.env.isMobile = isMobile;
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleLoadingIndicator(status: "loading" | "notloading") {
|
|
|
|
|
const method = status === "loading" ? "remove" : "add";
|
|
|
|
|
(<any>this.refs.loading_indicator).classList[method]("d-none");
|
2019-03-04 12:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 14:59:17 +01:00
|
|
|
async applyController(controller: Controller) {
|
|
|
|
|
const widget = await controller.create(this);
|
2019-03-04 12:52:14 +01:00
|
|
|
if (widget) {
|
|
|
|
|
// to do: call some public method of widget instead...
|
|
|
|
|
(<HTMLElement>this.refs.content).appendChild(widget.el!);
|
|
|
|
|
widget.__mount();
|
2019-03-08 11:59:02 +01:00
|
|
|
widget.el!.classList.add("o_action_controller");
|
2019-03-06 14:59:17 +01:00
|
|
|
this.store.activateController(controller);
|
2019-03-04 12:52:14 +01:00
|
|
|
}
|
2019-02-04 13:23:41 +01:00
|
|
|
}
|
2019-01-22 10:38:44 +01:00
|
|
|
}
|