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
+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];