-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessLists.js
55 lines (50 loc) · 1.51 KB
/
processLists.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
onCreate: this._updatePhoneTypes(sClientId);
onEdit: this._processPhoneTypes({
results: []
});
============================================================
_updatePhoneTypes: function(sClientId) {
this.getModel().read("/Client(" + sClientId + ")/ClientPhone", {
success: this._processPhoneTypes.bind(this),
error: this.onNavBack.bind(this)
});
},
_processPhoneTypes: function(oResponse) {
var fnStorePhoneTypes = function(oResQual) {
if (typeof oResQual.results !== "undefined") {
this._aPhoneTypes = oResQual.results;
}
this._setPhoneTypes(oResponse);
};
if (this._aPhoneTypes.length === 0) {
this.getModel().read("/PhoneTypes", {
success: fnStorePhoneTypes.bind(this),
error: this.onNavBack.bind(this)
});
} else {
this._setPhoneTypes(oResponse);
}
},
_setPhoneTypes: function(oResponse) {
var aExistingPhoneTypes = [];
var aPhoneTypes = [{
code: "",
description: "--Select--"
}];
if (typeof oResponse.results !== "undefined") {
// Generate list of current client phone types
aExistingPhoneTypes = oResponse.results.map(function(oValue) {
return oValue.phone_type_code;
});
// Generate list of output phonetypes
this._aPhoneTypes.forEach(function(oValue) {
if (aExistingPhoneTypes.indexOf(oValue.code) === -1) {
aPhoneTypes.push({
code: oValue.code,
description: oValue.description
});
}
});
}
this.getModel("view").setProperty("/phoneTypes", aPhoneTypes);
},