diff --git a/addons/web/static/src/legacy/legacy_views.js b/addons/web/static/src/legacy/legacy_views.js index f0c02eafaf4..48876eed3e2 100644 --- a/addons/web/static/src/legacy/legacy_views.js +++ b/addons/web/static/src/legacy/legacy_views.js @@ -51,10 +51,11 @@ function registerView(name, LegacyView) { searchPanel = globalState.searchPanel; } - this.viewParams = Object.assign({}, this.props.actionFlags, { + const { actionFlags, breadcrumbs = [] } = this.env.config; + this.viewParams = Object.assign({}, actionFlags, { action: this.props.action, // legacy views automatically add the last part of the breadcrumbs - breadcrumbs: breadcrumbsToLegacy(this.props.breadcrumbs), + breadcrumbs: breadcrumbsToLegacy(breadcrumbs), modelName: this.props.resModel, currentId: this.props.resId, controllerState: { @@ -99,7 +100,7 @@ function registerView(name, LegacyView) { context: this.props.context, }; const options = { - actionId: this.props.action.id, + actionId: this.env.config.actionId, loadActionMenus: this.props.loadActionMenus, loadIrFilters: this.props.loadIrFilters, }; @@ -120,10 +121,11 @@ function registerView(name, LegacyView) { viewFields: result.fields_views.search.fields, }); } + const { viewSwitcherEntries = [] } = this.env.config; const views = this.viewParams.action.views - .filter(([vid, vtype]) => vtype !== "search") + .filter(([, vtype]) => vtype !== "search") .map(([vid, vtype]) => { - const view = this.props.viewSwitcherEntries.find((v) => v.type === vtype); + const view = viewSwitcherEntries.find((v) => v.type === vtype); if (view) { return Object.assign({}, view, { viewID: vid }); } else { diff --git a/addons/web/static/src/search/control_panel/control_panel.js b/addons/web/static/src/search/control_panel/control_panel.js index dac80643c39..28603350257 100644 --- a/addons/web/static/src/search/control_panel/control_panel.js +++ b/addons/web/static/src/search/control_panel/control_panel.js @@ -1,11 +1,11 @@ /** @odoo-module **/ +import { useService } from "@web/core/utils/hooks"; import { ComparisonMenu } from "../comparison_menu/comparison_menu"; import { FavoriteMenu } from "../favorite_menu/favorite_menu"; import { FilterMenu } from "../filter_menu/filter_menu"; import { GroupByMenu } from "../group_by_menu/group_by_menu"; import { SearchBar } from "../search_bar/search_bar"; -import { useService } from "@web/core/utils/hooks"; const { Component } = owl; @@ -21,6 +21,44 @@ export class ControlPanel extends Component { this.actionService = useService("action"); } + /** + * !!! What follows is a hack, do not copy it !!! + * + * Duplicates the slots defined for the parent s.t. they are also available + * for the current control panel. + * + * This hack is necessary since Owl does not support manual slots + * assignment/transfer yet. This must be removed as soon as Owl implements + * such a system. + * + * @strongly_discouraged_override + */ + __render() { + const { slots } = this.env.qweb.constructor; + const { __owl__ } = this; + const originalSlots = {}; + const transferredSlotNames = [ + "control-panel-top-left", + "control-panel-top-right", + "control-panel-bottom-left", + "control-panel-bottom-right", + ]; + for (const slotName of transferredSlotNames) { + const parentSlotkey = `${__owl__.parent.__owl__.slotId}_${slotName}`; + if (parentSlotkey in slots) { + const cpSlotKey = `${__owl__.slotId}_${slotName}`; + originalSlots[cpSlotKey] = slots[cpSlotKey]; + slots[cpSlotKey] = function (scope, extra) { + slots[parentSlotkey].call(this, __owl__.parent.__owl__.scope, extra); + }; + } + } + const res = super.__render(...arguments); + // Clean up + Object.assign(slots, originalSlots); + return res; + } + /** * @returns {Object} */ @@ -78,25 +116,3 @@ export class ControlPanel extends Component { ControlPanel.components = { ComparisonMenu, FavoriteMenu, FilterMenu, GroupByMenu, SearchBar }; ControlPanel.template = "web.ControlPanel"; -// ControlPanel.props = { -// breadcrumbs: { type: Array, element: { jsId: String, name: String }, optional: true }, -// display: { type: Object, optional: true }, -// displayName: { type: String, optional: true }, -// viewSwitcherEntries: { -// type: Array, -// element: { -// type: Object, -// shape: { -// active: { type: Boolean, optional: true }, -// icon: String, -// multiRecord: { type: Boolean, optional: true }, -// name: [Object, String], -// type: String, -// }, -// }, -// optional: true, -// }, -// }; -ControlPanel.defaultProps = { - breadcrumbs: [], -}; diff --git a/addons/web/static/src/search/control_panel/control_panel.xml b/addons/web/static/src/search/control_panel/control_panel.xml index 617c77b2d98..a374b9f0a19 100644 --- a/addons/web/static/src/search/control_panel/control_panel.xml +++ b/addons/web/static/src/search/control_panel/control_panel.xml @@ -30,9 +30,9 @@
- +