-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.js
72 lines (52 loc) · 2.05 KB
/
list.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
// Transform a datum to make it usable on the map. TODO consider having the BE do this.
var transform = function (item) {
var new_item = {};
var year_st = item.start_date.substring(0,4);
var month_st = item.start_date.substring(5,7);
var day_st = item.start_date.substring(8,10);
var year_end = item.start_date.substring(0,4);
var month_end = item.start_date.substring(5,7);
var day_end = item.start_date.substring(8,10);
new_item.start = [day_st, month_st, year_st];
new_item.end = [day_end, month_end, year_end];
new_item.event = item.event_type;
new_item.headline = item.headline;
new_item.instruction = item.instruction;
new_item.city = item.city;
new_item.state = item.state;
return new_item
} // End of transform(1)
function renderList(json) {
var items = json.map(item => transform(item));
var list = document.createElement("ul");
list.classList.add("main-list");
for (var i in items) {
var mainitem = document.createElement("li");
var sublist = document.createElement("ul");
sublist.classList.add("sub-list");
var n = items[i], s = n.start, e = n.end;
var litem = document.createElement("li");
litem.appendChild(document.createTextNode(s[0]+"/"+s[1]+"/"+s[2]+" - "+e[0]+"/"+e[1]+"/"+e[2]));
sublist.appendChild(litem);
litem = document.createElement("li");
litem.appendChild(document.createTextNode(n.city + ", " + n.state));
sublist.appendChild(litem);
litem = document.createElement("li");
litem.appendChild(document.createTextNode(n.headline));
sublist.appendChild(litem);
mainitem.appendChild(sublist);
list.appendChild(mainitem);
}
document.getElementById(LIST).appendChild(list);
} // End of renderList(1)
var req = new XMLHttpRequest();
req.addEventListener("load", finish);
req.open("GET", WEATHER_DATA_URL);
req.send();
function finish() {
renderList(JSON.parse(req.response));
document.getElementById(LIST_BUTTON).addEventListener("click", function() {
document.getElementById(LIST).parentElement.classList.toggle("active");
document.getElementById(LIST_BUTTON).classList.toggle("active");
});
}