/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import VerticalLayout, { $VerticalLayoutSettings } from "sap/ui/layout/VerticalLayout"; import { ResultSetItem } from "../../ResultSetApi"; import { MetadataOptions } from "sap/ui/base/ManagedObject"; import SearchBasketModel, { SearchBasketApi } from "./SearchBasketModel"; import SearchBasketSapUiTable, { $SearchBasketSapUiTableSettings } from "./SearchBasketSapUiTable"; import Type from "sap/ui/table/rowmodes/Type"; import OverflowToolbar from "sap/m/OverflowToolbar"; export interface $SearchBasketSettings extends $VerticalLayoutSettings { basketConfigurator?: { adaptColumns: (columns: any[]) => any[]; adaptRow: (publicItem: ResultSetItem) => ResultSetItem; }; showDeleteAction?: boolean; // if basket- and result list item selection are not linked, we need to provide a delete button to remove items manually from the basket selectionMode?: string; // selection mode of the basket table/list } /** * @namespace sap.esh.search.ui.controls */ export default class SearchBasket extends VerticalLayout implements SearchBasketApi { static readonly metadata: MetadataOptions = { library: "sap.esh.search.ui.controls.basket", aggregations: {}, properties: { /** * An object containing the basket configurator functions 'adaptColumns' and 'adaptRow'. * @since 1.145.0 */ basketConfigurator: { type: "object", group: "Data", }, /** * If set to true, a delete action is shown for each row/item in the basket. Click to remove the item from the basket. * @since 1.145.0 */ showDeleteAction: { type: "boolean", group: "Behavior", defaultValue: false, }, /** * Selection mode of the basket table/list. * @since 1.145.0 */ selectionMode: { type: "string", group: "Behavior", defaultValue: "None", }, }, }; protected _basketTable: SearchBasketSapUiTable; constructor(sId?: string, settings?: $SearchBasketSettings) { super(sId, settings); const searchBasketSapUiTableSettings: $SearchBasketSapUiTableSettings = { basketConfigurator: settings?.basketConfigurator, showDeleteAction: settings?.showDeleteAction, rowMode: Type.Auto, }; if (typeof settings?.selectionMode !== "undefined") { if ( settings.selectionMode === "None" || settings.selectionMode === "Single" || settings.selectionMode === "Multi" || settings.selectionMode === "MultiToggle" ) { searchBasketSapUiTableSettings.selectionMode = settings.selectionMode; } } this._basketTable = new SearchBasketSapUiTable( `${this.getId()}-sapuitable`, searchBasketSapUiTableSettings ); const oBasketModel = this._basketTable.getBasketModel(); this.setModel(oBasketModel, "eshBasket"); const oToolbar = new OverflowToolbar(`${this.getId()}-basketToolbar`, { content: [this._basketTable.createClearBasketButton()], }); this.addContent(oToolbar); this.addContent(this._basketTable); } getBasketModel(): SearchBasketModel { return this._basketTable.getBasketModel(); } static renderer = { apiVersion: 2, }; }