@sapui5/sap.ui.export 1.93.3 → 1.96.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/sap/ui/export/.library +45 -47
- package/src/sap/ui/export/ExportBase.js +197 -0
- package/src/sap/ui/export/ExportUtils.js +74 -12
- package/src/sap/ui/export/PortableDocument.js +284 -0
- package/src/sap/ui/export/Spreadsheet.js +35 -162
- package/src/sap/ui/export/SpreadsheetExport.js +1 -1
- package/src/sap/ui/export/js/XLSXBuilder.js +1 -1
- package/src/sap/ui/export/js/XLSXBuilder.js.map +1 -1
- package/src/sap/ui/export/library.js +9 -2
- package/src/sap/ui/export/messagebundle.properties +3 -0
- package/src/sap/ui/export/messagebundle_ar.properties +2 -0
- package/src/sap/ui/export/messagebundle_bg.properties +2 -0
- package/src/sap/ui/export/messagebundle_ca.properties +2 -0
- package/src/sap/ui/export/messagebundle_cs.properties +2 -0
- package/src/sap/ui/export/messagebundle_cy.properties +2 -0
- package/src/sap/ui/export/messagebundle_da.properties +2 -0
- package/src/sap/ui/export/messagebundle_de.properties +2 -0
- package/src/sap/ui/export/messagebundle_el.properties +2 -0
- package/src/sap/ui/export/messagebundle_en.properties +2 -0
- package/src/sap/ui/export/messagebundle_en_GB.properties +2 -0
- package/src/sap/ui/export/messagebundle_en_US_sappsd.properties +2 -0
- package/src/sap/ui/export/messagebundle_en_US_saprigi.properties +2 -0
- package/src/sap/ui/export/messagebundle_en_US_saptrc.properties +2 -0
- package/src/sap/ui/export/messagebundle_es.properties +2 -0
- package/src/sap/ui/export/messagebundle_es_MX.properties +2 -0
- package/src/sap/ui/export/messagebundle_et.properties +2 -0
- package/src/sap/ui/export/messagebundle_fi.properties +2 -0
- package/src/sap/ui/export/messagebundle_fr.properties +2 -0
- package/src/sap/ui/export/messagebundle_fr_CA.properties +2 -0
- package/src/sap/ui/export/messagebundle_hi.properties +2 -0
- package/src/sap/ui/export/messagebundle_hr.properties +2 -0
- package/src/sap/ui/export/messagebundle_hu.properties +2 -0
- package/src/sap/ui/export/messagebundle_id.properties +2 -0
- package/src/sap/ui/export/messagebundle_it.properties +3 -1
- package/src/sap/ui/export/messagebundle_iw.properties +2 -0
- package/src/sap/ui/export/messagebundle_ja.properties +2 -0
- package/src/sap/ui/export/messagebundle_kk.properties +2 -0
- package/src/sap/ui/export/messagebundle_ko.properties +2 -0
- package/src/sap/ui/export/messagebundle_lt.properties +2 -0
- package/src/sap/ui/export/messagebundle_lv.properties +2 -0
- package/src/sap/ui/export/messagebundle_ms.properties +2 -0
- package/src/sap/ui/export/messagebundle_nl.properties +2 -0
- package/src/sap/ui/export/messagebundle_no.properties +2 -0
- package/src/sap/ui/export/messagebundle_pl.properties +2 -0
- package/src/sap/ui/export/messagebundle_pt.properties +2 -0
- package/src/sap/ui/export/messagebundle_pt_PT.properties +2 -0
- package/src/sap/ui/export/messagebundle_ro.properties +2 -0
- package/src/sap/ui/export/messagebundle_ru.properties +4 -2
- package/src/sap/ui/export/messagebundle_sh.properties +2 -0
- package/src/sap/ui/export/messagebundle_sk.properties +4 -2
- package/src/sap/ui/export/messagebundle_sl.properties +2 -0
- package/src/sap/ui/export/messagebundle_sv.properties +2 -0
- package/src/sap/ui/export/messagebundle_th.properties +2 -0
- package/src/sap/ui/export/messagebundle_tr.properties +2 -0
- package/src/sap/ui/export/messagebundle_uk.properties +2 -0
- package/src/sap/ui/export/messagebundle_vi.properties +2 -0
- package/src/sap/ui/export/messagebundle_zh_CN.properties +2 -0
- package/src/sap/ui/export/messagebundle_zh_TW.properties +2 -0
- package/ui5.yaml +0 -3
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SAPUI5
|
|
3
|
+
* (c) Copyright 2009-2021 SAP SE. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
sap.ui.define([
|
|
7
|
+
'sap/base/Log',
|
|
8
|
+
'sap/ui/core/Core',
|
|
9
|
+
'sap/ui/export/ExportBase',
|
|
10
|
+
'sap/ui/export/ExportUtils',
|
|
11
|
+
'sap/ui/model/odata/v4/ODataModel'
|
|
12
|
+
], function(Log, Core, ExportBase, ExportUtils, ODataModel) {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @constructor The <code>sap.ui.export.PortableDocument</code> class allows you to export table data from a UI5 application to a Portable Document Format (*.PDF) file.
|
|
17
|
+
*
|
|
18
|
+
* @author SAP SE
|
|
19
|
+
* @version 1.96.2
|
|
20
|
+
*
|
|
21
|
+
* @since 1.96
|
|
22
|
+
* @name sap.ui.export.PortableDocument
|
|
23
|
+
* @extends sap.ui.base.ExportBase
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
var PortableDocument = ExportBase.extend('sap.ui.export.PortableDocument', {
|
|
27
|
+
|
|
28
|
+
constructor: function(mSettings) {
|
|
29
|
+
ExportBase.call(this, mSettings);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sets the data source configuration that will be used for exporting the data. If the passed parameter is null,
|
|
35
|
+
* the call will be ignored.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object|sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oDataSource Possible types are a data
|
|
38
|
+
* source configuration, a <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
|
|
39
|
+
* @returns {Object|null} - Valid dataSource object or null in case the dataSource configuration is not supported
|
|
40
|
+
*
|
|
41
|
+
* @since 1.96
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
PortableDocument.prototype.processDataSource = function(oDataSource) {
|
|
45
|
+
var mDataSource = null;
|
|
46
|
+
var sDataSourceType = typeof oDataSource;
|
|
47
|
+
|
|
48
|
+
if (!oDataSource) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (sDataSourceType != 'object') {
|
|
53
|
+
Log.error('Spreadsheet#processDataSource: Unable to apply data source of type ' + sDataSourceType);
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (oDataSource.dataUrl && oDataSource.serviceUrl) {
|
|
59
|
+
mDataSource = oDataSource;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (oDataSource.isA && oDataSource.isA(['sap.ui.model.ListBinding', 'sap.ui.model.TreeBinding'])) {
|
|
63
|
+
mDataSource = this.createDataSourceFromBinding(oDataSource);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return mDataSource;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Creates a valid dataSource configuration
|
|
71
|
+
*
|
|
72
|
+
* @param {sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oBinding - A subclass of <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
|
|
73
|
+
* @returns {Object} - Valid data source configuration built upon the ListBinding
|
|
74
|
+
*/
|
|
75
|
+
PortableDocument.prototype.createDataSourceFromBinding = function(oBinding) {
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Use empty array as default in case of <code>ListBinding</code> is not of type
|
|
79
|
+
* ClientListBinding and does not provide a getDownloadUrl function
|
|
80
|
+
*/
|
|
81
|
+
var oDataSource = null;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* If <code>ClientListBinding</code>, we use the binding path to receive the data from the underlying model
|
|
85
|
+
*/
|
|
86
|
+
if (oBinding.isA('sap.ui.model.ClientListBinding')) {
|
|
87
|
+
Log.error('Unable to create dataSource configuration due to not supported Binding: ' + oBinding.getMetadata().getName());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (oBinding.isA('sap.ui.model.ClientTreeBinding')) {
|
|
91
|
+
Log.error('Unable to create dataSource configuration due to not supported Binding: ' + oBinding.getMetadata().getName());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* All other <code>Bindings</code> need to provide a downloadUrl
|
|
96
|
+
*/
|
|
97
|
+
if (typeof oBinding.getDownloadUrl === 'function') {
|
|
98
|
+
var oModel = oBinding.getModel(),
|
|
99
|
+
sDataUrl = ExportUtils.interceptUrl(oBinding.getDownloadUrl('json')),
|
|
100
|
+
sServiceUrl = ExportUtils.interceptUrl(oModel.sServiceUrl),
|
|
101
|
+
bV4ODataModel = oModel.isA('sap.ui.model.odata.v4.ODataModel');
|
|
102
|
+
|
|
103
|
+
var oDataUrl = new URL(sDataUrl, document.baseURI);
|
|
104
|
+
oDataUrl.hash = '';
|
|
105
|
+
oDataUrl.search = '';
|
|
106
|
+
|
|
107
|
+
oDataSource = {
|
|
108
|
+
type: 'odata',
|
|
109
|
+
version: bV4ODataModel ? 4 : 2,
|
|
110
|
+
dataUrl: oDataUrl.toString(),
|
|
111
|
+
serviceUrl: sServiceUrl.split('/').slice(0, -4).join("/") + "/iwbep/common/0001/", // Requires the serviceUrl to end with a /
|
|
112
|
+
headers: bV4ODataModel ? oModel.getHttpHeaders(true) : oModel.getHeaders()
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return oDataSource;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates the DocumentDescription based on the given export
|
|
121
|
+
* settings and assigns a unique Id to it.
|
|
122
|
+
*
|
|
123
|
+
* @param {Object} oWorkbook Workbook settings of the export configuration
|
|
124
|
+
* @returns {Object} DocumentDescription object that contains all relevant export settings
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
PortableDocument.prototype._createDocumentDescription = function(oWorkbook) {
|
|
128
|
+
var oDocumentDescription, oMetaInfo;
|
|
129
|
+
|
|
130
|
+
oDocumentDescription = {
|
|
131
|
+
"Title": oWorkbook.context.title,
|
|
132
|
+
"Format": {
|
|
133
|
+
"PaperSize": "DIN_A4",
|
|
134
|
+
"Orientation": "LANDSCAPE",
|
|
135
|
+
"FontSize": 12
|
|
136
|
+
},
|
|
137
|
+
"CoverPage": [],
|
|
138
|
+
"TableColumns": []
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
oMetaInfo = oWorkbook.context.metaInfo;
|
|
142
|
+
|
|
143
|
+
/* Add metaInfo to CoverPage */
|
|
144
|
+
if (oMetaInfo instanceof Array) {
|
|
145
|
+
oMetaInfo.forEach(function(oGroup) {
|
|
146
|
+
var oCoverPageGroup = {
|
|
147
|
+
"Title": oGroup.name,
|
|
148
|
+
"Content": []
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
oGroup.items.forEach(function(oItem) {
|
|
152
|
+
oCoverPageGroup["Content"].push({
|
|
153
|
+
"Name": oItem.key,
|
|
154
|
+
"Value": oItem.value
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
oDocumentDescription["CoverPage"].push(oCoverPageGroup);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Add columns */
|
|
162
|
+
oWorkbook.columns.forEach(function(oColumn){
|
|
163
|
+
oDocumentDescription["TableColumns"].push({
|
|
164
|
+
"Name": oColumn.property,
|
|
165
|
+
"Header": oColumn.label
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return oDocumentDescription;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Applies default settings to the export configuration.
|
|
174
|
+
*
|
|
175
|
+
* @param {Object} mSettings Export configuration object
|
|
176
|
+
* @returns {Promise} Promise that gets resolved when the default settings have been applied
|
|
177
|
+
*/
|
|
178
|
+
PortableDocument.prototype.setDefaultExportSettings = function(mSettings) {
|
|
179
|
+
var oContext = mSettings && mSettings.workbook && mSettings.workbook.context;
|
|
180
|
+
|
|
181
|
+
if (!(oContext instanceof Object)) {
|
|
182
|
+
oContext = mSettings.workbook.context = {};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (typeof oContext.title === 'string') {
|
|
186
|
+
return Promise.resolve();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return Core.getLibraryResourceBundle('sap.ui.export', true).then(function(oResourceBundle) {
|
|
190
|
+
oContext.title = oResourceBundle.getText('XLSX_DEFAULT_TITLE');
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
PortableDocument.prototype.createBuildPromise = function(mSettings) {
|
|
195
|
+
var that = this;
|
|
196
|
+
return new Promise(function(fnResolve, fnReject) {
|
|
197
|
+
var oBinding, oDocumentDescription, oModel;
|
|
198
|
+
|
|
199
|
+
oDocumentDescription = that._createDocumentDescription(mSettings.workbook);
|
|
200
|
+
|
|
201
|
+
/* Create COMMON service model and bind to MyDocumentDescription entity */
|
|
202
|
+
oModel = new ODataModel({
|
|
203
|
+
serviceUrl: mSettings.dataSource.serviceUrl,
|
|
204
|
+
synchronizationMode: 'None'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
oBinding = oModel.bindList('/MyDocumentDescriptions');
|
|
208
|
+
oBinding.attachCreateCompleted(function(oEvent) {
|
|
209
|
+
var success = oEvent.getParameter('success');
|
|
210
|
+
|
|
211
|
+
if (success) {
|
|
212
|
+
fnResolve(oEvent.getParameter('context').getObject()['Id']);
|
|
213
|
+
} else {
|
|
214
|
+
fnReject();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
oBinding.create(oDocumentDescription);
|
|
219
|
+
|
|
220
|
+
}).then(function(sDocumentDescriptionId) {
|
|
221
|
+
return that.sendRequest(mSettings.dataSource.dataUrl, sDocumentDescriptionId).then(function(response) {
|
|
222
|
+
ExportUtils.saveAsFile(response, mSettings.fileName);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Requests the generated PDF via HTTP GET from the OData service.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} sUrl Absolute data URL of the OData entity that should be exported as PDF
|
|
231
|
+
* @param {string} sDocumentDescriptionId GUID of the DocumentDescription that should be used for creating the PDF
|
|
232
|
+
* @returns {Promise} A Promise that gets resolved after the XHR request
|
|
233
|
+
*/
|
|
234
|
+
PortableDocument.prototype.sendRequest = function(sUrl, sDocumentDescriptionId) {
|
|
235
|
+
return new Promise(function(fnResolve, fnReject) {
|
|
236
|
+
var oXHR = this.request = new XMLHttpRequest();
|
|
237
|
+
|
|
238
|
+
/* Send GET request to receive PDF file */
|
|
239
|
+
oXHR.open('GET', sUrl);
|
|
240
|
+
oXHR.responseType = 'blob';
|
|
241
|
+
oXHR.setRequestHeader("Accept", "application/pdf");
|
|
242
|
+
oXHR.setRequestHeader("SAP-Document-Description-Id", sDocumentDescriptionId);
|
|
243
|
+
|
|
244
|
+
oXHR.addEventListener('abort', function() {
|
|
245
|
+
fnReject('Request aborted');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
oXHR.addEventListener('error', function() {
|
|
249
|
+
fnReject('Error occured while requesting data');
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
oXHR.addEventListener('load', function() {
|
|
253
|
+
var status = oXHR.status;
|
|
254
|
+
|
|
255
|
+
if (status >= 200 && status <= 400) {
|
|
256
|
+
fnResolve(oXHR.response);
|
|
257
|
+
} else {
|
|
258
|
+
fnReject(oXHR.response);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
oXHR.send();
|
|
263
|
+
}.bind(this));
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Cancels the active request. If the request has not been sent
|
|
268
|
+
* or the response has been received already, this function has
|
|
269
|
+
* no effect.
|
|
270
|
+
*
|
|
271
|
+
* @function
|
|
272
|
+
* @name sap.ui.export.PortableDocument#cancel
|
|
273
|
+
* @since 1.96
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
PortableDocument.prototype.cancel = function() {
|
|
277
|
+
if (this.request && this.request.readyState != XMLHttpRequest.DONE) {
|
|
278
|
+
this.request.abort();
|
|
279
|
+
this.request = null;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
return PortableDocument;
|
|
284
|
+
});
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
sap.ui.define([
|
|
7
7
|
'sap/ui/core/Core',
|
|
8
8
|
'./ExportDialog',
|
|
9
|
-
'sap/ui/
|
|
9
|
+
'sap/ui/export/ExportBase',
|
|
10
10
|
'sap/ui/Device',
|
|
11
11
|
'sap/ui/export/SpreadsheetExport',
|
|
12
12
|
'sap/base/Log',
|
|
13
13
|
'sap/ui/export/ExportUtils'
|
|
14
14
|
],
|
|
15
|
-
function(Core, ExportDialog,
|
|
15
|
+
function(Core, ExportDialog, ExportBase, Device, SpreadsheetExport, Log, ExportUtils) {
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
/* global Blob */
|
|
@@ -82,7 +82,7 @@ sap.ui.define([
|
|
|
82
82
|
* <li><code>workbook.context</code> - Context object that will be applied to the generated file. It may contain the following fields:</li>
|
|
83
83
|
* <ul>
|
|
84
84
|
* <li><code>application</code> (string) - The application that creates the XLSX document (default: "SAP UI5")</li>
|
|
85
|
-
* <li><code>version</code> (string) - Application version that creates the XLSX document (default: "1.
|
|
85
|
+
* <li><code>version</code> (string) - Application version that creates the XLSX document (default: "1.96.2")</li>
|
|
86
86
|
* <li><code>title</code> (string) - Title of the XLSX document (NOT the filename)</li>
|
|
87
87
|
* <li><code>modifiedBy</code> (string) - User context for the XLSX document</li>
|
|
88
88
|
* <li><code>sheetName</code> (string) - The label of the data sheet</li>
|
|
@@ -165,7 +165,7 @@ sap.ui.define([
|
|
|
165
165
|
* columns: aColumns,
|
|
166
166
|
* context: {
|
|
167
167
|
* application: 'Debug Test Application',
|
|
168
|
-
* version: '1.
|
|
168
|
+
* version: '1.96.2',
|
|
169
169
|
* title: 'Some random title',
|
|
170
170
|
* modifiedBy: 'John Doe',
|
|
171
171
|
* metaSheetName: 'Custom metadata',
|
|
@@ -277,32 +277,29 @@ sap.ui.define([
|
|
|
277
277
|
* @constructor The <code>sap.ui.export.Spreadsheet</code> class allows you to export table data from a UI5 application to a spreadsheet file.
|
|
278
278
|
*
|
|
279
279
|
* @author SAP SE
|
|
280
|
-
* @version 1.
|
|
280
|
+
* @version 1.96.2
|
|
281
281
|
*
|
|
282
282
|
* @since 1.50
|
|
283
283
|
* @name sap.ui.export.Spreadsheet
|
|
284
|
-
* @extends sap.ui.
|
|
284
|
+
* @extends sap.ui.export.ExportBase
|
|
285
285
|
* @see {@link topic:2691788a08fc43f7bf269ea7c6336caf Spreadsheet}
|
|
286
286
|
* @public
|
|
287
287
|
*/
|
|
288
|
-
var Spreadsheet =
|
|
288
|
+
var Spreadsheet = ExportBase.extend(CLASS_NAME, {
|
|
289
289
|
|
|
290
290
|
constructor: function(mSettings) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
/*
|
|
294
|
-
this._mSettings = {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
showProgress: true,
|
|
298
|
-
worker: true
|
|
299
|
-
};
|
|
291
|
+
ExportBase.call(this, mSettings);
|
|
292
|
+
|
|
293
|
+
/* Spreadsheet default settings */
|
|
294
|
+
this._mSettings.customizing = {};
|
|
295
|
+
this._mSettings.showProgress = true;
|
|
296
|
+
this._mSettings.worker = true;
|
|
300
297
|
|
|
301
298
|
/* Only apply supported properties */
|
|
302
299
|
// IMPORTANT: keep count before dataSource to ensure that the expected count can be used for dataSource string
|
|
303
|
-
['
|
|
300
|
+
['showProgress', 'worker'].forEach(function(sProperty) {
|
|
304
301
|
if (typeof mSettings[sProperty] !== 'undefined') {
|
|
305
|
-
this._mSettings[sProperty] =
|
|
302
|
+
this._mSettings[sProperty] = mSettings[sProperty];
|
|
306
303
|
}
|
|
307
304
|
}.bind(this));
|
|
308
305
|
|
|
@@ -415,61 +412,6 @@ sap.ui.define([
|
|
|
415
412
|
});
|
|
416
413
|
};
|
|
417
414
|
|
|
418
|
-
/**
|
|
419
|
-
* The <code>beforeExport</code> event is fired just before the export process is started.
|
|
420
|
-
*
|
|
421
|
-
* @name sap.ui.export.Spreadsheet#beforeExport
|
|
422
|
-
* @event
|
|
423
|
-
* @param {sap.ui.base.Event} oEvent
|
|
424
|
-
* @param {sap.ui.base.EventProvider} oEvent.getSource
|
|
425
|
-
* @param {object} oEvent.getParameters
|
|
426
|
-
* @param {ArrayBuffer} oEvent.getParameter.exportSettings - Contains export-related configuration
|
|
427
|
-
*
|
|
428
|
-
* @since 1.74
|
|
429
|
-
* @public
|
|
430
|
-
*/
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Attaches event handler <code>fnFunction</code> to the {@link sap.ui.export.Spreadsheet#event:beforeExport}
|
|
434
|
-
* event of this <code>sap.ui.export.Spreadsheet</code>.</br>
|
|
435
|
-
* When called, the context of the event handler (its <code>this</code>) will be bound to <code>oListener</code> if specified,
|
|
436
|
-
* otherwise it will be bound to this <code>sap.ui.export.Spreadsheet</code> itself.</br>
|
|
437
|
-
* This event is fired just before the export process is started.
|
|
438
|
-
*
|
|
439
|
-
* @param {object} [oData] An application-specific payload object that will be passed to the event handler along with the event object when firing the event
|
|
440
|
-
* @param {function} fnHandler The function to be called when the event occurs
|
|
441
|
-
* @param {object} [oListener] Context object to call the event handler with. Defaults to the <code>sap.ui.export.Spreadsheet</code> instance itself
|
|
442
|
-
*
|
|
443
|
-
* @returns {this} Reference to <code>this</code> in order to allow method chaining
|
|
444
|
-
*
|
|
445
|
-
* @name sap.ui.export.Spreadsheet#attachBeforeExport
|
|
446
|
-
* @function
|
|
447
|
-
* @since 1.74
|
|
448
|
-
* @public
|
|
449
|
-
*/
|
|
450
|
-
Spreadsheet.prototype.attachBeforeExport = function(oData, fnHandler, oListener) {
|
|
451
|
-
return this.attachEvent('beforeExport', oData, fnHandler, oListener);
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Detaches event handler <code>fnFunction</code> from the {@link sap.ui.export.Spreadsheet#event:beforeExport}
|
|
456
|
-
* event of this <code>sap.ui.export.Spreadsheet</code>.</br>
|
|
457
|
-
* The passed function and listener object must match the ones used for event registration.
|
|
458
|
-
*
|
|
459
|
-
* @param {function} fnHandler The function to be called when the event occurs
|
|
460
|
-
* @param {object} [oListener] Context object on which the given function had to be called
|
|
461
|
-
*
|
|
462
|
-
* @returns {this} Reference to <code>this</code> in order to allow method chaining
|
|
463
|
-
*
|
|
464
|
-
* @name sap.ui.export.Spreadsheet#detachBeforeExport
|
|
465
|
-
* @function
|
|
466
|
-
* @since 1.74
|
|
467
|
-
* @public
|
|
468
|
-
*/
|
|
469
|
-
Spreadsheet.prototype.detachBeforeExport = function(fnHandler, oListener) {
|
|
470
|
-
return this.detachEvent('beforeExport', fnHandler, oListener);
|
|
471
|
-
};
|
|
472
|
-
|
|
473
415
|
/**
|
|
474
416
|
* The <code>beforeSave</code> event is fired just before the generated file is saved to the file system.
|
|
475
417
|
*
|
|
@@ -526,22 +468,6 @@ sap.ui.define([
|
|
|
526
468
|
return this.detachEvent('beforeSave', fnHandler, oListener);
|
|
527
469
|
};
|
|
528
470
|
|
|
529
|
-
/**
|
|
530
|
-
* Cleans up the internal structures and removes all event handlers.
|
|
531
|
-
*
|
|
532
|
-
* The object must not be used anymore after destroy was called.
|
|
533
|
-
*
|
|
534
|
-
* @see sap.ui.base.Object#destroy
|
|
535
|
-
* @public
|
|
536
|
-
*/
|
|
537
|
-
Spreadsheet.prototype.destroy = function() {
|
|
538
|
-
EventProvider.prototype.destroy.apply(this, arguments);
|
|
539
|
-
|
|
540
|
-
this.cancel();
|
|
541
|
-
this.bIsDestroyed = true;
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
|
|
545
471
|
/**
|
|
546
472
|
* Cancels a running export process. This method does nothing if no export is running.
|
|
547
473
|
*
|
|
@@ -561,7 +487,6 @@ sap.ui.define([
|
|
|
561
487
|
return this;
|
|
562
488
|
};
|
|
563
489
|
|
|
564
|
-
|
|
565
490
|
/**
|
|
566
491
|
* Progress callback. The function is called when the progress status changes.
|
|
567
492
|
*
|
|
@@ -582,32 +507,6 @@ sap.ui.define([
|
|
|
582
507
|
Log.debug('Spreadsheet export: ' + iProgress + '% loaded.');
|
|
583
508
|
};
|
|
584
509
|
|
|
585
|
-
/**
|
|
586
|
-
* Returns the amount of data that is available on the backend
|
|
587
|
-
* in case the binding provides this information.
|
|
588
|
-
*
|
|
589
|
-
* @param {sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oBinding - A subclass of <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
|
|
590
|
-
* @return {number|null} Amount of data in the backend or null if the binding does not provide this information
|
|
591
|
-
*/
|
|
592
|
-
var getCountFromBinding = function(oBinding) {
|
|
593
|
-
var iCount;
|
|
594
|
-
|
|
595
|
-
if (typeof oBinding.getCount === 'function') {
|
|
596
|
-
iCount = oBinding.getCount();
|
|
597
|
-
} else if (!oBinding.isA('sap.ui.model.TreeBinding') // Explicitly exclude TreeBinding because Binding#getLength is numberOfExpandedLevels dependent
|
|
598
|
-
&& typeof oBinding.isLengthFinal === 'function'
|
|
599
|
-
&& oBinding.isLengthFinal()) {
|
|
600
|
-
|
|
601
|
-
iCount = oBinding.getLength();
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
if (typeof iCount !== 'number' || iCount < 0 || isNaN(iCount)) {
|
|
605
|
-
iCount = null;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
return iCount;
|
|
609
|
-
};
|
|
610
|
-
|
|
611
510
|
/**
|
|
612
511
|
* Creates a valid dataSource configuration
|
|
613
512
|
*
|
|
@@ -654,7 +553,7 @@ sap.ui.define([
|
|
|
654
553
|
dataUrl: sDataUrl,
|
|
655
554
|
serviceUrl: sServiceUrl,
|
|
656
555
|
headers: bV4ODataModel ? oModel.getHttpHeaders(true) : oModel.getHeaders(),
|
|
657
|
-
count: getCountFromBinding(oBinding),
|
|
556
|
+
count: ExportUtils.getCountFromBinding(oBinding),
|
|
658
557
|
useBatch: bV4ODataModel || oModel.bUseBatch
|
|
659
558
|
};
|
|
660
559
|
|
|
@@ -674,10 +573,10 @@ sap.ui.define([
|
|
|
674
573
|
* Sets the data source configuration that will be used for exporting the data. If the passed parameter is null,
|
|
675
574
|
* the call will be ignored.
|
|
676
575
|
*
|
|
677
|
-
* @param {string|Array|Object|sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oDataSource
|
|
576
|
+
* @param {string|Array|Object|sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oDataSource Possible types are a plain
|
|
678
577
|
* string that contains an URL of an OData service, an array of JSON objects, a data source configuration,
|
|
679
578
|
* a <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
|
|
680
|
-
* @returns {Object} - Valid dataSource object
|
|
579
|
+
* @returns {Object|null} - Valid dataSource object or null in case the dataSource configuration is not supported
|
|
681
580
|
*
|
|
682
581
|
* @since 1.73
|
|
683
582
|
* @public
|
|
@@ -687,7 +586,7 @@ sap.ui.define([
|
|
|
687
586
|
var sDataSourceType = typeof oDataSource;
|
|
688
587
|
|
|
689
588
|
if (!oDataSource) {
|
|
690
|
-
return;
|
|
589
|
+
return null;
|
|
691
590
|
}
|
|
692
591
|
|
|
693
592
|
if (sDataSourceType == 'string') {
|
|
@@ -700,9 +599,9 @@ sap.ui.define([
|
|
|
700
599
|
}
|
|
701
600
|
|
|
702
601
|
if (sDataSourceType != 'object') {
|
|
703
|
-
Log.error('Spreadsheet#
|
|
602
|
+
Log.error('Spreadsheet#processDataSource: Unable to apply data source of type ' + sDataSourceType);
|
|
704
603
|
|
|
705
|
-
return;
|
|
604
|
+
return null;
|
|
706
605
|
}
|
|
707
606
|
|
|
708
607
|
if (oDataSource instanceof Array ) {
|
|
@@ -724,13 +623,14 @@ sap.ui.define([
|
|
|
724
623
|
* Creates and returns a new Promise object that triggers the export process for the given {@link sap.ui.export.Spreadsheet}.
|
|
725
624
|
*
|
|
726
625
|
* @function
|
|
727
|
-
* @name sap.ui.export.Spreadsheet#
|
|
728
|
-
* @param {sap.ui.export.Spreadsheet} oSpreadsheet - Spreadsheet
|
|
626
|
+
* @name sap.ui.export.Spreadsheet#createBuildPromise
|
|
729
627
|
* @param {Object} mParameters - Export parameters object
|
|
730
628
|
* @returns {Promise} Promise object
|
|
731
629
|
* @private
|
|
732
630
|
*/
|
|
733
|
-
function
|
|
631
|
+
Spreadsheet.prototype.createBuildPromise = function(mParameters) {
|
|
632
|
+
var that = this;
|
|
633
|
+
|
|
734
634
|
return new Promise(function(fnResolve, fnReject) {
|
|
735
635
|
|
|
736
636
|
var progressDialog;
|
|
@@ -745,22 +645,22 @@ sap.ui.define([
|
|
|
745
645
|
if (progressDialog) {
|
|
746
646
|
progressDialog.updateStatus(oMessage.fetched, oMessage.total);
|
|
747
647
|
}
|
|
748
|
-
|
|
648
|
+
that.onprogress(oMessage.fetched, oMessage.total);
|
|
749
649
|
}
|
|
750
650
|
|
|
751
651
|
/*
|
|
752
652
|
* It is important to check if the process is still assigned, this allows to cancel the export
|
|
753
653
|
* even though all rows have been appended to the Spreadsheet but the file has not been saved yet
|
|
754
654
|
*/
|
|
755
|
-
if (oMessage.finished &&
|
|
756
|
-
|
|
655
|
+
if (oMessage.finished && that.process !== null) {
|
|
656
|
+
that.process = null;
|
|
757
657
|
|
|
758
658
|
if (!oMessage.spreadsheet) {
|
|
759
659
|
fnReject('Spreadsheet export: The process was canceled');
|
|
760
660
|
return;
|
|
761
661
|
}
|
|
762
662
|
|
|
763
|
-
var executeDefaultAction =
|
|
663
|
+
var executeDefaultAction = that.fireEvent('beforeSave', {
|
|
764
664
|
data: oMessage.spreadsheet
|
|
765
665
|
}, true, true);
|
|
766
666
|
|
|
@@ -783,7 +683,7 @@ sap.ui.define([
|
|
|
783
683
|
|
|
784
684
|
if (typeof oMessage.error != 'undefined') {
|
|
785
685
|
var sError = oMessage.error.message || oMessage.error;
|
|
786
|
-
|
|
686
|
+
that.process = null;
|
|
787
687
|
|
|
788
688
|
if (progressDialog) {
|
|
789
689
|
progressDialog.finish();
|
|
@@ -796,12 +696,12 @@ sap.ui.define([
|
|
|
796
696
|
|
|
797
697
|
function startExport() {
|
|
798
698
|
if (!mParameters.showProgress) {
|
|
799
|
-
if (
|
|
699
|
+
if (that.process) {
|
|
800
700
|
fnReject('Cannot start export: the process is already running');
|
|
801
701
|
return;
|
|
802
702
|
}
|
|
803
703
|
|
|
804
|
-
|
|
704
|
+
that.process = SpreadsheetExport.execute(mParameters, onmessage);
|
|
805
705
|
return;
|
|
806
706
|
}
|
|
807
707
|
|
|
@@ -809,13 +709,13 @@ sap.ui.define([
|
|
|
809
709
|
ExportDialog.getProgressDialog().then(function(oDialogResolve) {
|
|
810
710
|
progressDialog = oDialogResolve;
|
|
811
711
|
|
|
812
|
-
if (
|
|
712
|
+
if (that.process) {
|
|
813
713
|
fnReject('Cannot start export: the process is already running');
|
|
814
714
|
return;
|
|
815
715
|
}
|
|
816
716
|
|
|
817
717
|
progressDialog.oncancel = function() {
|
|
818
|
-
return
|
|
718
|
+
return that.process && that.process.cancel();
|
|
819
719
|
};
|
|
820
720
|
|
|
821
721
|
progressDialog.open();
|
|
@@ -824,7 +724,7 @@ sap.ui.define([
|
|
|
824
724
|
progressDialog.updateStatus(0, mParameters.dataSource.count);
|
|
825
725
|
|
|
826
726
|
// Start export once the dialog is present and the code lists have been loaded
|
|
827
|
-
|
|
727
|
+
that.process = SpreadsheetExport.execute(mParameters, onmessage);
|
|
828
728
|
});
|
|
829
729
|
}
|
|
830
730
|
|
|
@@ -851,33 +751,6 @@ sap.ui.define([
|
|
|
851
751
|
}
|
|
852
752
|
|
|
853
753
|
});
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Loads data from the backend, builds and saves the resulting spreadsheet file. You can use the <code>cancel</code> method to stop a running export.
|
|
858
|
-
*
|
|
859
|
-
* @function
|
|
860
|
-
* @returns {Promise} Promise object. You may use it to track the result of the export process.
|
|
861
|
-
*
|
|
862
|
-
* @name sap.ui.export.Spreadsheet#build
|
|
863
|
-
* @public
|
|
864
|
-
*/
|
|
865
|
-
Spreadsheet.prototype.build = function() {
|
|
866
|
-
var mParameters = this._mSettings;
|
|
867
|
-
|
|
868
|
-
if (this.bIsDestroyed) {
|
|
869
|
-
var sMessage = CLASS_NAME + ': Cannot trigger build - the object has been destroyed';
|
|
870
|
-
|
|
871
|
-
Log.error(sMessage);
|
|
872
|
-
return Promise.reject(sMessage);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
return this.setDefaultExportSettings(mParameters).then(function() {
|
|
876
|
-
this.fireEvent('beforeExport', {exportSettings: mParameters}, false, false);
|
|
877
|
-
ExportUtils.validateSettings(mParameters);
|
|
878
|
-
|
|
879
|
-
return _createBuildPromise(this, mParameters);
|
|
880
|
-
}.bind(this));
|
|
881
754
|
};
|
|
882
755
|
|
|
883
756
|
return Spreadsheet;
|