-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectFieldChanges.js
77 lines (75 loc) · 2.32 KB
/
selectFieldChanges.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
onStartDateChange: function(oEvent) {
var aFilters = [];
var oCompanySelect = this.byId("newHireCompany");
var oTemplate = new sap.ui.core.Item({
key: "{CompanyCode}",
text: "{CompanyName}"
});
var sPath = "/Companies";
oCompanySelect.bindAggregation("items", {
path: sPath,
template: oTemplate,
filters: aFilters,
events: {
dataReceived: function() {
var aItems = oCompanySelect.getItems();
if (aItems.length === 1) {
var sCompanyCode = oCompanySelect.getSelectedKey();
this._processCompSelect(sCompanyCode);
} else {
oCompanySelect.insertItem(new sap.ui.core.Item({
text: "-- Select --",
key: ""
}), 0);
oCompanySelect.setSelectedKey("");
oCompanySelect.setEnabled(true);
}
}.bind(this)
}
});
},
onCompSelChange: function(oEvent) {
var oItem = oEvent.getSource();
var sCompanyCode = oItem.getSelectedKey();
var oDefaultRate = this.byId("newHireRate");
if (sCompanyCode !== "") {
this._processCompSelect(sCompanyCode);
oDefaultRate.setValue("");
}
},
_processCompSelect: function(sCompanyCode) {
var aFilters = [];
var dStartDate = new Date(this.byId("newHireStartDate").getDateValue()).toISOString();
var oPositionSelect = this.byId("newHirePosition");
var oItemSelectTemplate = new sap.ui.core.Item({
key: "{PositionNumber}",
text: "{PositionNumber} - {PositionDescription}"
});
if (sCompanyCode && sCompanyCode.length > 0) {
aFilters.push(new Filter("CompanyCode", "EQ", sCompanyCode));
}
if (dStartDate && dStartDate.length > 0) {
aFilters.push(new Filter("StartDate", "LE", dStartDate));
aFilters.push(new Filter("EndDate", "GE", dStartDate));
aFilters.push(new Filter("HourlyFlag", "EQ", 'Y'));
}
var sPath = "/WorkerPositions";
oPositionSelect.bindAggregation("items", {
path: sPath,
template: oItemSelectTemplate,
filters: aFilters,
events: {
dataReceived: function() {
var aItems = oPositionSelect.getItems();
if (aItems.length > 0 && aItems[0].getKey() !== "") {
oPositionSelect.insertItem(new sap.ui.core.Item({
text: "-- Select --",
key: ""
}), 0);
oPositionSelect.setSelectedKey("");
}
oPositionSelect.setEnabled(true);
}
}
});
},