work on action manager

This commit is contained in:
Géry Debongnie
2019-03-02 08:34:29 +01:00
parent 1f0ae87262
commit fec7a9caec
8 changed files with 87 additions and 97 deletions
+1 -2
View File
@@ -1,8 +1,7 @@
import { Registry } from "./core/registry";
import { ActionWidget } from "./store/store";
import { CRM } from "./widgets/crm";
import { Discuss } from "./widgets/discuss";
export const actionRegistry: Registry<ActionWidget> = new Registry();
actionRegistry.add("discuss", Discuss).add("crm", CRM);
actionRegistry.add("mail.discuss", Discuss);
+49 -26
View File
@@ -1,6 +1,7 @@
import { Type } from "../core/component";
import { rpcMixin } from "./rpc_mixin";
import { Widget } from "../widgets/widget";
import { View } from "../widgets/view";
export type Context = { [key: string]: any };
@@ -9,21 +10,19 @@ export interface CommonActionInfo {
context: Context;
title: string;
target: "current" | "new";
Widget: ActionWidget;
}
export type ActionRequest = string | number;
export type ActionRequest = number;
export type ActionWidget = Type<Widget<{}, {}>>;
export interface ClientActionInfo extends CommonActionInfo {
type: "client";
name: string;
Widget: ActionWidget;
}
export interface ActWindowInfo extends CommonActionInfo {
type: "act_window";
view: string;
}
interface BaseActionDescription {
@@ -63,31 +62,55 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
actionCache: { [key: number]: Promise<ActionDescription> } = {};
async doAction(request: ActionRequest) {
if (typeof request === "number") {
const descr = await this.loadAction(request);
// this is an action ID
let name = request === 131 ? "discuss" : "crm";
let title =
request === 131 ? "Discuss" : request === 250 ? "Notes" : "CRM";
let Widget = this.actionRegistry.get(name);
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "client",
name,
title,
Widget: Widget
}
]
});
document.title = descr.name + " - Odoo";
const descr = await this.loadAction(request);
switch (descr.type) {
case "ir.actions.client":
return this.doClientAction(descr);
case "ir.actions.act_window":
return this.doActWindowAction(descr);
default:
throw new Error("unhandled action");
}
}
doActWindowAction(descr: ActWindowActionDescription) {
let title = descr.name;
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "act_window",
title,
Widget: View
}
]
});
document.title = descr.name + " - Odoo";
}
doClientAction(descr: ClientActionDescription) {
let key = descr.tag;
let title = descr.name;
let Widget = this.actionRegistry.get(key);
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "client",
title,
Widget: Widget
}
]
});
document.title = descr.name + " - Odoo";
}
loadAction(id: number): Promise<ActionDescription> {
if (id in this.actionCache) {
return this.actionCache[id];
-5
View File
@@ -1,5 +0,0 @@
import { Widget } from "./widget";
export class CRM extends Widget<{}, {}> {
template = "web.crm";
}
@@ -38,7 +38,7 @@ export class ActionContainer extends Widget<Props, {}> {
async setContentWidget() {
const info = this.props.stack[this.props.stack.length - 1];
if (info && info.type === "client") {
if (info) {
const Widget = info.Widget;
let widget = new Widget(this, {});
await widget.mount(this.el || document.createElement("div"));
+5
View File
@@ -0,0 +1,5 @@
import { Widget } from "./widget";
export class View extends Widget<{}, {}> {
inlineTemplate = "<div>some view</div>";
}
-4
View File
@@ -73,10 +73,6 @@
<div t-name="web.action_container" class="o_content"/>
<div t-name="web.crm" class="o_crm">
<span>CRM!!!!</span>
</div>
<div t-name="web.discuss" class="o_discuss">
<span>DISCUSS!!</span>
<button t-on-click="resetCounter">Reset first counter</button>