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/admin-books/webapp/manifest.json b/cap-notebook/demoapp/app/admin-books/webapp/manifest.json index a5ae8a52..7bf86c76 100644 --- a/cap-notebook/demoapp/app/admin-books/webapp/manifest.json +++ b/cap-notebook/demoapp/app/admin-books/webapp/manifest.json @@ -137,7 +137,7 @@ "attachments/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -147,8 +147,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -156,7 +166,7 @@ "references/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -166,8 +176,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -175,7 +195,7 @@ "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -185,8 +205,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -207,7 +237,7 @@ "attachments/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -217,8 +247,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -226,7 +266,7 @@ "references/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -236,8 +276,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -245,7 +295,7 @@ "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -255,8 +305,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -278,7 +338,7 @@ "attachments/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -288,16 +348,26 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } } } }, "references/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -307,8 +377,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } @@ -316,7 +396,7 @@ "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { "tableSettings": { "type": "ResponsiveTable", - "selectionMode": "Auto", + "selectionMode": "Multi", "rowPress": ".extension.books.controller.custom.onRowPress" }, "actions": { @@ -326,8 +406,18 @@ "requiresSelection": true, "press": ".extension.books.controller.custom.onChangelogPress", "command": "COMMON", "position": { - "anchor": "StandardAction::Create", - "placement": "After" + "anchor": "StandardAction::Create", + "placement": "After" + } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.books.controller.custom.isDownloadEnabled", + "press": ".extension.books.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } 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 @@ }; - +