-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ObjectPageExtController.js
58 lines (56 loc) · 1.67 KB
/
ObjectPageExtController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
sap.ui.define([], function () {
"use strict";
return {
/**
* Create Dialog to Upload Excel and open it
* @param {*} oEvent
*/
openExcelUploadDialog: async function (oEvent) {
this._view.setBusyIndicatorDelay(0);
this._view.setBusy(true);
if (!this.excelUpload) {
this.excelUpload = await this._controller.getAppComponent().createComponent({
usage: "excelUpload",
async: true,
componentData: {
context: this,
columns: ["product_ID", "quantity", "title", "price", "validFrom", "timestamp", "date", "time"],
mandatoryFields: ["product_ID", "quantity"],
excelFileName: "Test.xlsx"
}
});
// event to check before uploaded to app
this.excelUpload.attachCheckBeforeRead(function (oEvent) {
// example
const sheetData = oEvent.getParameter("sheetData");
let errorArray = [];
for (const [index, row] of sheetData.entries()) {
//check for invalid price
if (row.UnitPrice) {
if (row.UnitPrice > 100) {
const error = {
title: "Price to high (max 100)",
row: index + 2,
group: true
};
errorArray.push(error);
}
}
}
oEvent.getSource().addToErrorsResults(errorArray);
}, this);
// event to change data before send to backend
this.excelUpload.attachChangeBeforeCreate(function (oEvent) {
let payload = oEvent.getParameter("payload");
// round number from 12,56 to 12,6
if (payload.price) {
payload.price = Number(payload.price.toFixed(1));
}
oEvent.getSource().setPayload(payload);
}, this);
}
this.excelUpload.openExcelUploadDialog();
this._view.setBusy(false);
}
};
});