-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwastecollectionProvider_43.js
More file actions
132 lines (114 loc) · 5.03 KB
/
wastecollectionProvider_43.js
File metadata and controls
132 lines (114 loc) · 5.03 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//<provider>43</provider><version>1.0.0</version><parms>"zipcode,housenr"</parms>
//provider ACV (Veendendaal e.o.) testdata: 3902AT 5
function readCalendar(wasteZipcode, wasteHouseNr, extraDates, enableCreateICS, wasteICSId, wasteStreet, wasteStreetName, wasteCity, wasteFullICSUrl) {
var params = "companyCode=f8e2844a-095e-48f9-9f98-71fceb51d2c3&postCode=" + wasteZipcode + "&houseNumber=" + wasteHouseNr + "&houseLetter=&houseNumberAddition=";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "https://wasteapi.2go-mobile.com/api/FetchAdress", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
addressJson = JSON.parse(xmlhttp.responseText);
read2goMobileCalendar(addressJson['dataList'][0]['UniqueId']);
}
}
xmlhttp.send(params);
}
function read2goMobileCalendar(uniqueId) {
var now = new Date;
var strMonNow = now.getMonth() + 1;
if (strMonNow < 10) {
strMonNow = "0" + strMonNow;
}
var strDayNow = now.getDate();
if (strDayNow < 10) {
strDayNow = "0" + strDayNow;
}
var later = new Date(now.getTime() + 7772000000); // 3 months later
var strMonLater = later.getMonth() + 1;
if (strMonLater < 10) {
strMonLater = "0" + strMonLater;
}
var strDayLater = later.getDate();
if (strDayLater < 10) {
strDayLater = "0" + strDayLater;
}
var startDate = now.getFullYear() + "-" + strMonNow + "-" + strDayNow;
var endDate = later.getFullYear() + "-" + strMonLater + "-" + strDayLater;
var params = "companyCode=f8e2844a-095e-48f9-9f98-71fceb51d2c3&uniqueAddressId=" + uniqueId + "&startDate=" + startDate + "&endDate=" + endDate;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "https://wasteapi.2go-mobile.com/api/GetCalendar", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
wasteDatesString = "";
var wasteType = "";
var mobileAfvalbeheerDates = [];
var calendar2goMobile = JSON.parse(xmlhttp.responseText)
for (var i= 0; i < calendar2goMobile['dataList'].length; i++) {
for (var j= 0; j < calendar2goMobile['dataList'][i]['pickupDates'].length; j++) {
if (calendar2goMobile['dataList'][i]['_pickupTypeText'] == "GREENGREY") {
mobileAfvalbeheerDates.push(calendar2goMobile['dataList'][i]['pickupDates'][j].substring(0,10) + "-" + wasteType2goMobile("GREEN"));
mobileAfvalbeheerDates.push(calendar2goMobile['dataList'][i]['pickupDates'][j].substring(0,10) + "-" + wasteType2goMobile("GREY"));
} else {
mobileAfvalbeheerDates.push(calendar2goMobile['dataList'][i]['pickupDates'][j].substring(0,10) + "-" + wasteType2goMobile(calendar2goMobile['dataList'][i]['_pickupTypeText']));
}
}
}
var tmp = sortArray2(mobileAfvalbeheerDates, extraDates);
for (i = 0; i < tmp.length; i++) {
wasteDatesString = wasteDatesString + tmp[i] + "\n";
}
writeWasteDates(wasteDatesString, enableCreateICS);
}
}
xmlhttp.send(params);
}
function wasteType2goMobile(shortName) {
switch (shortName) {
case "GREEN": return 3; //groente/fruit
case "PAPER": return 2; //papier
case "PACKAGES": return 1; //pmd
case "PLASTIC": return 1; //pmd
case "VET": return 7; //KGA meppel.nl
case "GREY": return 0; //restafval
default: break;
}
return "?";
}
function sortArray2(inputarray, extraDates) {
var newArray = inputarray.concat(extraDates);
newArray.sort();
return newArray;
}
function writeWasteDates(wasteDatesString, enableCreateICS) {
var doc2 = new XMLHttpRequest();
doc2.open("PUT", "file:///var/volatile/tmp/wasteDates.txt");
doc2.onreadystatechange=function() {
if (doc2.readyState === 4){
if (doc2.status === 0) {
updateWasteIcon("no");
}
}
}
doc2.send(wasteDatesString);
// create ICS file for use in the calendar app when requested
if (enableCreateICS) {
var outputICS = "";
var tmpICS = wasteDatesString.split("\n");
for (var i = 0; i < tmpICS.length; i++) {
if (tmpICS[i].length > 10) {
outputICS = outputICS + "BEGIN:VEVENT\r\n";
outputICS = outputICS + "DTSTART;VALUE=DATE:" + tmpICS[i].substring(0,4) + tmpICS[i].substring(5,7) + tmpICS[i].substring(8,10) + "\r\n";
outputICS = outputICS + "SUMMARY:" + wasteTypeFriendlyName(tmpICS[i].substring(11,12)) + "\r\n";
outputICS = outputICS + "BEGIN:VEVENT\r\n";
}
}
var doc3 = new XMLHttpRequest();
doc3.open("PUT", "file:///var/volatile/tmp/wasteDates.ics");
doc3.send(outputICS);
}
}