add IAjax and IActionManager interfaces

This commit is contained in:
Géry Debongnie
2019-01-26 20:22:32 +01:00
parent 5fe72757a7
commit fe7f506fcb
3 changed files with 36 additions and 8 deletions
+12 -5
View File
@@ -1,8 +1,8 @@
import { QWeb } from "./core/qweb_vdom";
import { idGenerator } from "./core/utils";
import { WEnv } from "./core/widget";
import { ActionManager } from "./services/action_manager";
import { Ajax } from "./services/ajax";
import { ActionManager, IActionManager } from "./services/action_manager";
import { Ajax, IAjax } from "./services/ajax";
import { Router, IRouter } from "./services/router";
export interface Menu {
@@ -11,10 +11,11 @@ export interface Menu {
}
export interface Env extends WEnv {
actionManager: ActionManager;
ajax: Ajax;
actionManager: IActionManager;
ajax: IAjax;
router: IRouter;
menus: Menu[];
rpc: IAjax["rpc"];
}
export function makeEnvironment(): Env {
@@ -28,11 +29,17 @@ export function makeEnvironment(): Env {
];
return {
// Base widget requirements
qweb,
getID: idGenerator(),
// services
ajax,
router,
actionManager,
menus,
getID: idGenerator()
// helpers
rpc: ajax.rpc
};
}
+10 -2
View File
@@ -1,4 +1,4 @@
import { EventBus } from "../core/event_bus";
import { EventBus, Callback } from "../core/event_bus";
import { Widget } from "../core/widget";
import { Env } from "../env";
import { CRM } from "../widgets/crm";
@@ -19,6 +19,14 @@ interface ActWindowAction {
views: string[];
}
type ActionEvent = "action_ready";
export interface IActionManager {
doAction(actionID: number);
on(event: ActionEvent, owner: any, callback: Callback);
getCurrentAction(): ActionWidget | null;
}
export type Action = ClientAction | ActWindowAction;
export interface ActionWidget {
@@ -32,7 +40,7 @@ const actions: any[] = [
{ id: 2, title: "CRM", Widget: CRM }
];
export class ActionManager extends EventBus {
export class ActionManager extends EventBus implements IActionManager {
router: IRouter;
currentAction: ActionWidget | null = null;
+14 -1
View File
@@ -1 +1,14 @@
export class Ajax {}
export interface RPC {
model: string;
method: string;
args: any;
}
export interface IAjax {
rpc(rpc: RPC): Promise<any>;
}
export class Ajax implements IAjax {
rpc(rpc: RPC): Promise<any> {
return Promise.resolve(1);
}
}