/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import { MetadataOptions } from "sap/ui/base/ManagedObject"; import SearchModel from "../../SearchModel"; import i18n from "../../i18n"; import { OverflowToolbarPriority } from "sap/m/library"; import OverflowToolbarLayoutData from "sap/m/OverflowToolbarLayoutData"; import Device from "sap/ui/Device"; import Button, { $ButtonSettings } from "sap/m/Button"; /** * Add selected result items to basket * */ /** * Constructs a new SearchBasketAddButton to display a button to add result items to the search basket. * * @param {string} [sId] ID for the new control, generated automatically if no ID is given * * @class * * This is the SAPUI5 search basket button control to display a button to add result items to the search basket. * Use in combination with control SearchCompositeControl by the Enterprise Search Team. * * @extends sap.m.OverflowToolbarButton * * @author SAP SE * @version 1.150.1 * * @see https://help.sap.com/viewer/691cb949c1034198800afde3e5be6570/2.0.08/en-US/ce86ef2fd97610149eaaaa0244ca4d36.html SAP HANA Search Developer Guide * @see https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/90b263323d0a4976bcda415e6bd20ea4/d93d53ef27074bbf9a4849c4a4c3e360.html Enterprise Search in SAP S/4HANA * * * @constructor * @public * @alias sap.esh.search.ui.controls.basket.SearchBasketAddButton * @since 1.143.0 * @name sap.esh.search.ui.controls.basket.SearchBasketAddButton * */ /** * @namespace sap.esh.search.ui.controls */ export default class SearchBasketAddButton extends Button { static readonly metadata: MetadataOptions = { library: "sap.esh.search.ui.controls.basket", properties: {}, aggregations: {}, }; constructor(sId?: string, settings?: $ButtonSettings) { if (!settings) { settings = {}; } if (!settings?.icon) { settings.icon = "sap-icon://cart-4"; } /* if (!settings?.text) {. do not set default text, we will show a button with icon-only by default settings.text = i18n.getText("addToBasket"); } */ if (!settings?.tooltip) { settings.tooltip = i18n.getText("addToBasket"); } super(sId, settings); this.attachPress(() => { const searchModel = this.getModel() as SearchModel; const searchCompControl = searchModel.getSearchCompositeControlInstanceByChildControl(this); const publicResultItems = searchCompControl.getPublicSearchModel().getProperty("/results/items"); if (searchCompControl) { // update basket items if (publicResultItems.some((item) => item.selected)) { // update basket items const oSearchBasketModel = searchCompControl.getSearchBasketModel(); const itemsAddedCount = publicResultItems.filter((item) => item.selected).length; oSearchBasketModel.updateBasketItems(publicResultItems, [], true); // keep existing items of basket, just add new items searchModel.setProperty("/basketCount", oSearchBasketModel.getProperty("/rows").length); oSearchBasketModel.selectAllItems(); oSearchBasketModel.setProperty("/_skipSelectionChange", true); for (const item of publicResultItems) { item.setSelected(false); } setTimeout(() => { oSearchBasketModel.setProperty("/_skipSelectionChange", false); }, 1000); oSearchBasketModel.logItemAdd(itemsAddedCount); } } }); this.bindProperty("visible", { parts: [ { path: "/config/basketAddButton" }, { path: "/config/basketLinkByResultViewItemSelection" }, { path: "/businessObjSearchEnabled" }, { path: "/resultviewSelectionVisibility" }, ], formatter: ( basketAddButton: boolean, basketLinkByResultViewItemSelection: boolean, businessObjSearchEnabled: boolean, resultviewSelectionVisibility: boolean ): boolean => { // do not show button on phones // do not show button for value help mode const searchModel = this.getModel() as SearchModel; return ( !Device.system.phone && !searchModel.config.optimizeForValueHelp && basketAddButton && !basketLinkByResultViewItemSelection && businessObjSearchEnabled && resultviewSelectionVisibility ); }, }); this.addStyleClass("searchBarBasketAddItemsButton"); this.setLayoutData( new OverflowToolbarLayoutData({ priority: OverflowToolbarPriority.NeverOverflow }) ); return this; } static renderer = { apiVersion: 2, }; }