-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathResourceFilters.html
More file actions
226 lines (200 loc) · 6.53 KB
/
Copy pathResourceFilters.html
File metadata and controls
226 lines (200 loc) · 6.53 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type='text/javascript' src="https://kd7iwp.github.io/ChildrenOfTheStreetDatabase/javascripts/sheetrock.min.js"></script>
<script src="https://kd7iwp.github.io/ChildrenOfTheStreetDatabase/javascripts/handlebars.min.js"></script>
<script type='text/javascript'>//<![CDATA[
var parentToolkitSheet = 'https://docs.google.com/spreadsheets/d/1RHCgt5w5KlqucNdKVPP25uUovFu2vQIZsZml1dzZPR0/edit#gid=0';
var filterSheet = 'https://docs.google.com/spreadsheets/d/1RHCgt5w5KlqucNdKVPP25uUovFu2vQIZsZml1dzZPR0/edit#gid=1597681109';
// Register template for resources
var resourceTemplate;
// When querying the spreadsheet we must use column letters. Map the column names of our filters to their "letter"
var filterColMapping = {
"Service Location": ["H"],
"Service Type": ["G"],
"Service Region": ["I"]
};
function LoadResources(filterType, filterValue)
{
var searchQuery = "select A,B,C,D,E,F,G,H where " + filterColMapping[filterType] + " like '%" + filterValue + "%' order by A";
$('#loadingIcon').show();
// Load up the list of resources that match the filters
$('#resourceBody').empty().sheetrock({
url: parentToolkitSheet,
query: searchQuery,
loading: $('#loadingIcon'),
rowTemplate: resourceTemplate,
callback: SheetrockHandler
});
$('#loadingIcon').hide();
}
function SheetrockHandler(Error, Options, Response)
{
if (Error != null)
{
$('#errorMessage').show();
}
}
$(window).load(function(){
$('#regionFilter').change(function() {
LoadResources("Service Region", $(this).val());
});
$('#cityFilter').change(function() {
LoadResources("Service Location", $(this).val());
});
$('#typeFilter').change(function() {
LoadResources("Service Type", $(this).val());
});
// Clear out the other filters when one is changed
$('.filter').change(function() {
var selectedVal = $(this).val();
$('.filter').val('');
$(this).val(selectedVal);
});
// Register our Handlebars templates
var RegionTemplate = Handlebars.compile($('#region-template').html());
var CityTemplate = Handlebars.compile($('#city-template').html());
var TypeTemplate = Handlebars.compile($('#type-template').html());
resourceTemplate = Handlebars.compile($('#resourceTemplate').html());
// This Handlebars block_helper let's us know if a value exists or not to perform conditional template statements
Handlebars.registerHelper('if', function(conditional, options)
{
if (conditional)
return options.fn(this);
return options.inverse(this);
})
// Populate our select lists with filter options
$('#regionFilter').sheetrock({
url: filterSheet,
query: "select A",
rowTemplate: RegionTemplate,
callback: SheetrockHandler
});
$('#cityFilter').sheetrock({
url: filterSheet,
query: "select B",
rowTemplate: CityTemplate,
callback: SheetrockHandler
});
$('#typeFilter').sheetrock({
url: filterSheet,
query: "select C",
rowTemplate: TypeTemplate,
callback: SheetrockHandler
});
});//]]>
</script>
<style type="text/css">
.field label {
width: 200px;
}
select {
width: 200px;
}
#resourceList {
width: 100%;
table-layout: fixed;
}
.table-striped > tbody > tr:nth-of-type(2n+2) {
background-color: #F8C0EB;
}
#resourceList > thead > tr > th {
font-family: helvetica;
color: white;
background-color:#CF0072;
}
.contact {
font-size: small;
overflow: hidden;
margin-left: 5px;
}
</style>
</head>
<body>
<div id="loadingIcon" style="float:right;padding:10px;color:white;background-color:#CF0072;display:none;">
LOADING...
</div>
<div class="field">
<label for="regionFilter">Search by Region</label>
<select id="regionFilter" class="filter">
<option></option>
<script id="region-template" type="text/x-handlebars-template">
{{#if cells.Regions}}
<option value="{{cells.Regions}}">{{cells.Regions}}</option>
{{/if}}
</script>
</select>
</div>
<div class="field">
<label for="cityFilter">Search by City</label>
<select id="cityFilter" class="filter">
<option></option>
<script id="city-template" type="text/x-handlebars-template">
{{#if cells.Cities}}
<option value="{{cells.Cities}}">{{cells.Cities}}</option>
{{/if}}
</script>
</select>
</div>
<div class="field">
<label for="typeFilter">Search by Service Type</label>
<select id="typeFilter" class="filter">
<option></option>
<script id="type-template" type="text/x-handlebars-template">
{{#if cells.Types}}
<option value="{{cells.Types}}">{{cells.Types}}</option>
{{/if}}
</script>
</select>
</div>
<hr />
<div id="errorMessage" style="display:none;border:4px solid red;">
<p>There was an error loading the database</p>
</div>
<p>Resources available based on your selection:</p>
<table id="resourceList" class="table table-condensed table-striped">
<thead>
<tr>
<th style="width:15%;">Organization</th>
<th style="width:15%;">Program</th>
<th style="width:25%;">Description</th>
<th style="width:14%;">Services</th>
<th style="width:14%;">Service Area</th>
</tr>
</thead>
<tbody id="resourceBody">
<script id="resourceTemplate" type="text/x-handlebars-template">
<tr>
<td>
<strong>
{{#if cells.Website}}
<a href="http://{{cells.Website}}">{{cells.Organization}}</a>
{{else}}
{{cells.Organization}}
{{/if}}
</strong>
<div class="contact">
{{#if cells.Email}}
<strong>e:</strong> <a href="mailto:{{cells.Email}}">{{cells.Email}}</a>
{{/if}}
{{#if cells.Phone}}
{{#if cells.Email}}
<br />
{{/if}}
<strong>p:</strong> {{cells.Phone}}
{{/if}}
</div>
</td>
<td style="font-weight:bold;font-style:italic;">{{cells.Program}}</td>
<td>{{cells.Description}}</td>
<td>{{cells.Services}}</td>
<td>{{cells.Location}}</td>
</tr>
</script>
</tbody>
</table>
</body>
</html>