diff --git a/cap-notebook/demoapp/app/admin-books/fiori-service.cds b/cap-notebook/demoapp/app/admin-books/fiori-service.cds index de8e3171..146ea4cf 100644 --- a/cap-notebook/demoapp/app/admin-books/fiori-service.cds +++ b/cap-notebook/demoapp/app/admin-books/fiori-service.cds @@ -48,7 +48,7 @@ annotate AdminService.Books with @(UI: { $Type : 'UI.ReferenceFacet', Label : '{i18n>Chapters}', ID : 'i18nChapters', - Target : 'chapters/@UI.LineItem#i18nChapters', + Target : 'cHapters/@UI.LineItem#i18nChapters', }, { $Type : 'UI.ReferenceFacet', 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..763daa54 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 243b45fc..ff087547 100644 --- a/cap-notebook/demoapp/app/admin-books/webapp/manifest.json +++ b/cap-notebook/demoapp/app/admin-books/webapp/manifest.json @@ -85,7 +85,7 @@ "target": "AuthorsDetails" }, { - "pattern": "Books({key})/chapters({key2}):?query:", + "pattern": "Books({key})/cHapters({key2}):?query:", "name": "chaptersObjectPage", "target": "ChaptersObjectPage" }, @@ -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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.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": { @@ -310,13 +380,23 @@ "anchor": "StandardAction::Create", "placement": "After" } + }, + "download": { + "text": "Download", + "requiresSelection": true, + "enabled": ".extension.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } } } }, "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.admin.controller.custom.isDownloadEnabled", + "press": ".extension.admin.controller.custom.onDownloadPress", + "position": { + "anchor": "StandardAction::Create", + "placement": "After" } } } diff --git a/cap-notebook/demoapp/app/common.cds b/cap-notebook/demoapp/app/common.cds index 0f859fdf..90326595 100644 --- a/cap-notebook/demoapp/app/common.cds +++ b/cap-notebook/demoapp/app/common.cds @@ -64,6 +64,14 @@ annotate my.Books.attachments with @UI: { TypeNamePlural: '{i18n>Attachments}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -150,7 +158,15 @@ annotate my.Books.references with @UI: { TypeNamePlural: '{i18n>Attachments}', }, LineItem : [ - {Value: type, @HTML5.CssDefaults: {width: '10%'}}, + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, + {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, {Value: createdAt, @HTML5.CssDefaults: {width: '15%'}}, @@ -231,6 +247,14 @@ annotate my.Books.footnotes with @UI: { TypeNamePlural: '{i18n>Attachments}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -312,6 +336,14 @@ annotate my.Chapters.attachments with @UI: { TypeNamePlural: '{i18n>Attachments}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -393,6 +425,14 @@ annotate my.Chapters.references with @UI: { TypeNamePlural: '{i18n>References}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -474,6 +514,14 @@ annotate my.Chapters.footnotes with @UI: { TypeNamePlural: '{i18n>Footnotes}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -555,6 +603,14 @@ annotate my.Pages.attachments with @UI: { TypeNamePlural: '{i18n>Attachments}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -636,6 +692,14 @@ annotate my.Pages.references with @UI: { TypeNamePlural: '{i18n>References}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -717,6 +781,14 @@ annotate my.Pages.footnotes with @UI: { TypeNamePlural: '{i18n>Footnotes}', }, LineItem : [ + { + $Type : 'UI.DataFieldForAction', + Action: 'AdminService.createAttachmentInActive', + Label : 'Create Attachment', + Inline: false, + RequiresSelection: false, + ![@UI.Hidden]: {$edmJson: {$Ne: [ {$Path: 'IsActiveEntity'}, true ]}} + }, {Value: type, @HTML5.CssDefaults: {width: '10%'}}, {Value: fileName, @HTML5.CssDefaults: {width: '20%'}}, {Value: content, @HTML5.CssDefaults: {width: '0%'}}, @@ -995,4 +1067,4 @@ annotate common.Currencies with @(UI : { { Value: code }, { Value: descr } ]} -}); +}); \ No newline at end of file diff --git a/cap-notebook/demoapp/app/index.html b/cap-notebook/demoapp/app/index.html index ab8ffe43..1b0453be 100644 --- a/cap-notebook/demoapp/app/index.html +++ b/cap-notebook/demoapp/app/index.html @@ -14,8 +14,8 @@ }; - - +