-
Notifications
You must be signed in to change notification settings - Fork 2
/
hbs.html
120 lines (104 loc) · 4.54 KB
/
hbs.html
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
<!doctype html>
<html>
<head>
<style>
#btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-family: Helvetica, Arial, serif;
font-size: 14px;
font-weight: bolder;
line-height: 1.428571429;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
color:#ffffff;
}
</style>
</head>
<body>
<script src="bower_components/jquery/jquery.min.js"></script>
<script src="bower_components/underscore/underscore-min.js"></script>
<script src="bower_components/handlebars/handlebars.min.js"></script>
<div id="btn" style="background-color: coral">Click for House Committees</div>
<script id="committee-member-template" type="text/x-handlebars-template">
<div class="entry">
{{ committee_name}}
<ul>
{{#each members1}}<li><a href="javascript:void(0);" data-committee="{{committee_abbrev}}">{{memberFirstName}} {{memberLastName}}{{#if title}}, {{title}}{{/if}}</a></li>{{/each}}
</ul>
</div>
</script>
<script>
$("#btn")
.click(function () {
//alert('button clicked');
drawMap("HSAG")
});
var drawMap = function (committee) {
var committeeRequest = $.ajax({
dataType: "json",
url: "https://congress.api.sunlightfoundation.com/committees",
data: {
per_page: "all",
chamber: "house",
committee_id: committee,
subcommittee: false,
fields: ["name", "committee_id", "office", "subcommittee", "phone", "url", "members"],
apikey: "9e3e71730ae34e1ebbf4dd0e1c346c07"
}
})
.done(function listMembers(committee) {
console.log(committee.results[0].name);
var source = $("#committee-member-template")
.html();
var template = Handlebars.compile(source);
console.log(committee.results[0].members);
console.log(committee.results[0].members[0].legislator);
console.log(committee.results[0].members[0].legislator.first_name);
//var parseCongressionalCommitteeResponse = function (congressionalCommittee) {
// create array that will be populated with state names
var arrayOfCommitteeChairs = [];
var arrayOfCommitteeMembers = [];
var committeeNamesObj = {};
_.each(committee.results[0].members, function(member, index){
var memberObject = {
memberFirstName: member.legislator.first_name,
memberLastName: member.legislator.last_name,
title: member.title
};
if (memberObject.title) {
arrayOfCommitteeChairs.push(memberObject);
} else {
arrayOfCommitteeMembers.push(memberObject);
}
})
var sortedArrayOfMemberNames = _(arrayOfCommitteeMembers).sortBy("memberLastName");
var sortedArrayOfMemberChairs = _(arrayOfCommitteeChairs).sortBy("title");
var sortedMemberNames = sortedArrayOfMemberChairs.concat(sortedArrayOfMemberNames);
console.log(sortedMemberNames);
console.log("arrayOfCommitteeMembers", arrayOfCommitteeMembers);
//return arrayOfStateNamesForThisCommittee;
// };
var context = {
committee_abbrev: committee.results[0].committee_id,
committee_name: committee.results[0].name,
members: committee.results[0].members[0],
members1: sortedMemberNames,
first_name: committee.results[0].members[0].legislator.first_name,
title: committee.results[0].members[0].title
}
var html = template(context);
$('body')
.append(html)
console.log(committee)
});
}
</script>
</body>
</html>