From 29bdaa7865f905b2cee0d62aa79412a682b1d5a3 Mon Sep 17 00:00:00 2001 From: deepiksSingh2711 Date: Mon, 27 Apr 2026 22:00:15 +0530 Subject: [PATCH 1/2] leading application changes for the download of multiple attcahments --- .../webapp/controller/custom.controller.js | 45 +++++++++++++++++++ cap-notebook/demoapp/app/index.html | 2 +- cap-notebook/demoapp/srv/admin-service.cds | 9 ++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js b/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js index 1a230e0e..8cb074e7 100644 --- a/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js +++ b/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js @@ -13,6 +13,14 @@ sap.ui.define( }; return ControllerExtension.extend("books.controller.custom", { + isDownloadEnabled: function(oBindingContext, aSelectedContexts) { + if (!aSelectedContexts || aSelectedContexts.length === 0) { + return false; + } + return !aSelectedContexts.some(function(oContext) { + return oContext.getProperty("mimeType") === "application/internet-shortcut"; + }); + }, onRowPress: function(oContext) { this.base.editFlow .invokeAction("AdminService.openAttachment", { @@ -90,6 +98,43 @@ sap.ui.define( }, close: function (closeBtn) { closeBtn.getSource().getParent().close(); + }, + onDownloadPress: function(oContext, aSelectedContexts) { + var sIds = aSelectedContexts.map(function(oCtx) { + return oCtx.getObject().ID; + }).join(","); + this.base.editFlow + .invokeAction("AdminService.downloadSelectedAttachments", { + contexts: aSelectedContexts[0], + parameterValues: [{ name: "ids", value: sIds }], + skipParameterDialog: true + }) + .then(function (res) { + var sJsonResponse = res.getObject().value; + var aEntries = JSON.parse(sJsonResponse); + aEntries.forEach(function (oEntry) { + if (oEntry.status === "success") { + if (oEntry.linkUrl) { + window.open(oEntry.linkUrl, "_blank"); + } else if (oEntry.content) { + var byteString = atob(oEntry.content); + var aBytes = new Uint8Array(byteString.length); + for (var i = 0; i < byteString.length; i++) { + aBytes[i] = byteString.charCodeAt(i); + } + var oBlob = new Blob([aBytes], { type: oEntry.mimeType || "application/octet-stream" }); + var sUrl = URL.createObjectURL(oBlob); + var oLink = document.createElement("a"); + oLink.href = sUrl; + oLink.download = oEntry.fileName || "download"; + document.body.appendChild(oLink); + oLink.click(); + document.body.removeChild(oLink); + URL.revokeObjectURL(sUrl); + } + } + }); + }); } }); } diff --git a/cap-notebook/demoapp/app/index.html b/cap-notebook/demoapp/app/index.html index 3371025f..1b0453be 100644 --- a/cap-notebook/demoapp/app/index.html +++ b/cap-notebook/demoapp/app/index.html @@ -14,7 +14,7 @@ }; - +