diff --git a/web/static/src/ts/registries.ts b/web/static/src/ts/registries.ts index 287284c3..81c4d918 100644 --- a/web/static/src/ts/registries.ts +++ b/web/static/src/ts/registries.ts @@ -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 = new Registry(); -actionRegistry.add("discuss", Discuss).add("crm", CRM); +actionRegistry.add("mail.discuss", Discuss); diff --git a/web/static/src/ts/store/action_manager_mixin.ts b/web/static/src/ts/store/action_manager_mixin.ts index 385c6117..559eb00f 100644 --- a/web/static/src/ts/store/action_manager_mixin.ts +++ b/web/static/src/ts/store/action_manager_mixin.ts @@ -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>; 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>( actionCache: { [key: number]: Promise } = {}; 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 { if (id in this.actionCache) { return this.actionCache[id]; diff --git a/web/static/src/ts/widgets/CRM.ts b/web/static/src/ts/widgets/CRM.ts deleted file mode 100644 index b8912398..00000000 --- a/web/static/src/ts/widgets/CRM.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Widget } from "./widget"; - -export class CRM extends Widget<{}, {}> { - template = "web.crm"; -} diff --git a/web/static/src/ts/widgets/action_container.ts b/web/static/src/ts/widgets/action_container.ts index 8f9b7059..9ad3fde3 100644 --- a/web/static/src/ts/widgets/action_container.ts +++ b/web/static/src/ts/widgets/action_container.ts @@ -38,7 +38,7 @@ export class ActionContainer extends Widget { 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")); diff --git a/web/static/src/ts/widgets/view.ts b/web/static/src/ts/widgets/view.ts new file mode 100644 index 00000000..f7f93623 --- /dev/null +++ b/web/static/src/ts/widgets/view.ts @@ -0,0 +1,5 @@ +import { Widget } from "./widget"; + +export class View extends Widget<{}, {}> { + inlineTemplate = "
some view
"; +} diff --git a/web/static/src/xml/templates.xml b/web/static/src/xml/templates.xml index 68909d76..78e8c415 100644 --- a/web/static/src/xml/templates.xml +++ b/web/static/src/xml/templates.xml @@ -73,10 +73,6 @@
-
- CRM!!!! -
-
DISCUSS!! diff --git a/web/static/tests/widgets/__snapshots__/root.test.ts.snap b/web/static/tests/widgets/__snapshots__/root.test.ts.snap index 8dfb87d7..c08b188b 100644 --- a/web/static/tests/widgets/__snapshots__/root.test.ts.snap +++ b/web/static/tests/widgets/__snapshots__/root.test.ts.snap @@ -39,69 +39,41 @@ exports[`if url has action_id, will render action and navigate to proper menu_id - CRM + Discuss
-
- CRM!!!! +
+ DISCUSS!! + + + + + + + +
+ + Value: 4 + +
+
+ + Value: 400 + +
+ +
+ Current Color: + red +
+ +
diff --git a/web/static/tests/widgets/root.test.ts b/web/static/tests/widgets/root.test.ts index eb54055a..37c4a26e 100644 --- a/web/static/tests/widgets/root.test.ts +++ b/web/static/tests/widgets/root.test.ts @@ -38,7 +38,7 @@ test("can be rendered (in home menu)", async () => { }); test("if url has action_id, will render action and navigate to proper menu_id", async () => { - const router = new helpers.MockRouter({ action_id: "595" }); + const router = new helpers.MockRouter({ action_id: "131" }); store = helpers.makeTestStore({ router }); env = makeEnv(store, templates); await helpers.nextTick(); @@ -46,8 +46,8 @@ test("if url has action_id, will render action and navigate to proper menu_id", const root = new Root(env, store); await root.mount(fixture); expect(env.services.router.getQuery()).toEqual({ - action_id: "595", - menu_id: "409" + action_id: "131", + menu_id: "96" }); expect(fixture.innerHTML).toMatchSnapshot(); // we check here that the url was changed to set app id as menu_id