-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbclist.html
418 lines (374 loc) · 17.4 KB
/
mbclist.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<html>
<head>
<title>Merit Badge Counselor Information</title>
<!--
Copyright (c) 2021-2022 by James Brown
Subject to the terms and conditions listed below, the licensor hereby
grants to any person obtaining a copy of this software and associated
documentation (the "Software"), free of charge, a royalty-free,
worldwide, non-exclusive, non-sublicensable, irrevocable license to
use, copy, modify, merge, publish, distribute, reproduce and share
this software, in whole or in part, for noncommercial purposes only
and to produce, reproduce and share any derivative works for
noncommercial purposes only subject to the following conditions:
- The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
- Any derivative works of the Software must be licensed under the same terms.
- The National Council of the Boy Scouts of America and it's
employees, contractors, and subsidiaries are EXPRESSLY FORBIDDEN
from using any portion of the Software in any way whatsoever,
including but not limited to incorporating it into other software
or creating derivative works, without a specific written license
from the original author, James Brown. This includes any
subsidiaries or affiliates of the National Council such as, but not
limited to ScoutBook, Exploring, etc.
- Notwithstanding any other provisions of this license, Councils,
Districts and Units chartered by the Boy Scouts of America, other than
the National Council, may use the Software free of charge without
obtaining a written license, subject to all of the other terms of
this license.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!-- do not cache this page -->
<meta http-equiv="cache-control" content="max-age=0"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
<meta http-equiv="pragma" content="no-cache"/>
<style>
td.details-control {
cursor: pointer;
font-size: 2em;
font-weight: bold;
color: green;
}
tr.shown td.details-control {
color: black;
}
.narrow {
max-width: 5em;
}
.row-busy {
opacity: 40%;
}
.row-expiring {
background-color: DarkOrange !important;
}
.row-expired {
background-color: Red !important;
}
</style>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.23/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.js"></script>
<script type="text/javascript">
var data =[
// {{include: demo-mbc.json}}
];
var zipData = {
// {{include: demo-zip.json}}
};
var requiredMBs = [
"Camping",
"Citizenship in the Community",
"Citizenship in the Nation",
"Citizenship in the World",
"Communication",
"Cooking",
"Cycling",
"Emergency Preparedness",
"Environmental Science",
"Family Life",
"First Aid",
"Hiking",
"Lifesaving",
"Personal Fitness",
"Personal Management",
"Sustainability",
"Swimming"
];
// Custom filtering function for distance
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var targetZipcode = $('#targetZipcode').val();
var radius = parseFloat( $('#radius').val(), 10 ) || 0;
var zipcode = data[6].substr(0,5); // zip code column
$('#targetZipcode').css("background", (targetZipcode == '' || zipData.hasOwnProperty(targetZipcode)) ? "white" : "red");
$('#radius').css("background", radius<=0 ? "red" : "white");
// invalid zipcode or invalid distance? claim it matches
if (!zipData.hasOwnProperty(targetZipcode) || !zipData.hasOwnProperty(zipcode) || isNaN(radius) || radius<=0)
return true;
var lat1 = zipData[targetZipcode].lat,
lon1 = zipData[targetZipcode].lon,
lat2 = zipData[zipcode].lat,
lon2 = zipData[zipcode].lon;
var avgLat = (lat1 + lat2)/2;
var distance = Math.sqrt( Math.pow((lon1-lon2) * Math.cos( avgLat * Math.PI / 180), 2) + Math.pow(lat1-lat2, 2) ) * 69;
return (distance <= radius);
}
);
function ChildData ( d ) {
// `d` is the original data object for the row
return `<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">
<tr>
<td>Address:</td>
<td>${d.address}, ${d.city}, ${d.state} ${d.zip}</td>
</tr>
<tr>
<td>Phone:</td>
<td>${d.phone.map(item => item.type + " " + item.number).join("<br>")}</td>
</tr>
<tr>
<td>Email:</td>
<td>${d.email}</td>
</tr>
<tr>
<td>BSA ID:</td>
<td>${d.bsaid}</td>
</tr>
<tr>
<td>Works with:</td>
<td>${d.workwith}</td>
</tr>
<tr>
<td>Availability:</td>
<td>${d.availability}</td>
</tr>
<tr>
<td>YPT expires:</td>
<td>${d.yptexpiry}</td>
</tr>
</table>`;
}
$(document).ready( function () {
// Setup - add a text input to each header cell (2nd row)
$('#mbcs thead tr').clone(true).appendTo( '#mbcs thead' );
// remove duplicate proximity text on second row
$('#mbcs thead tr:eq(1) th:eq(1)').text('');
// on second row, skip the first two columns
$('#mbcs thead tr:eq(1) th:gt(1)').each( function (i) {
var title = $(this).text();
$(this).html( `<input type="text" placeholder="Search ${title}" ${title == "State" ? 'size=5' : ''} />` );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i+2).search() !== this.value )
{
// if it looks like a regex, do a regex search
if ($.fn.dataTable.util.escapeRegex(this.value) != this.value)
{
table
.column(i+2)
.search( this.value, true, false )
.draw();
}
else
{
table
.column(i+2)
.search( this.value, false, true )
.draw();
}
}
} );
} );
var table = $('#mbcs').DataTable( {
data: data,
columns: [
{
className: 'details-control dt-body-center',
searchable: false,
orderable: false,
data: null,
defaultContent: '+',
},
{
className: 'dt-body-center',
searchable: false,
orderable: true,
data: null,
visible: false,
defaultContent: 'dist',
render: function(data, type, row)
{
var targetZipcode = $('#targetZipcode').val();
var zipcode = row.zip.substr(0,5); // zip code column
// invalid zipcodes
if (!zipData.hasOwnProperty(targetZipcode) || !zipData.hasOwnProperty(zipcode))
return '';
var lat1 = zipData[targetZipcode].lat,
lon1 = zipData[targetZipcode].lon,
lat2 = zipData[zipcode].lat,
lon2 = zipData[zipcode].lon;
var avgLat = (lat1 + lat2)/2;
var distance = Math.sqrt( Math.pow((lon1-lon2) * Math.cos( avgLat * Math.PI / 180), 2) + Math.pow(lat1-lat2, 2) ) * 69;
return distance.toFixed(2);
}
},
{ data: 'name' },
{ data: 'address', visible: false },
{ data: 'city' },
{ data: 'state', className: 'narrow dt-body-center' },
{ data: 'zip', visible: false },
{ data: 'phone', visible: false,
render: function(data, type, row) { return data.map(item => item.type + " " + item.number).join("<br>"); }
},
{ data: 'email', visible: false },
{ data: 'district' },
{ data: 'bsaid', visible: false },
{ data: 'meritbadges',
render: function(data, type, row) {
var uniq = [... new Set(data)];
var retval= uniq.sort().join("<br>");
requiredMBs.forEach(function (mb) { retval = retval.replace(new RegExp(mb, 'i'), '<b>'+mb+'</b>')});
return retval;
}
},
{ data: 'workwith', visible: false },
{ data: 'availability', visible: false },
{ data: 'yptexpiry', visible: false },
],
order: [[2, 'asc']],
dom: '<"top"lif<"clear">>rt<"bottom"lip<"clear">>',
orderCellsTop: true,
fixedHeader: true,
pageLength: 10,
createdRow: function( row, data, dataIndex ) {
if ( data.availability == "Busy" )
{
$(row).addClass('row-busy');
}
var diffDays = (Date.parse(data.yptexpiry) - Date.now()) / (1000 * 60 * 60 * 24);
if ( diffDays <= 45 )
{
console.log(data.yptexpiry, diffDays, row);
$(row).addClass(diffDays <= 0 ? 'row-expired' : 'row-expiring');
}
} // createdRow
} ); // DataTable
// Event listener to the two distance filtering inputs to redraw on input
$('#targetZipcode, #radius').keyup( function(e) {
var targetZipcode = $('#targetZipcode').val();
var radius = parseFloat( $('#radius').val(), 10 ) || 0;
// hide or show proximity based on validity of zipcode and radius
if (!zipData.hasOwnProperty(targetZipcode) || isNaN(radius) || radius<=0)
{
if (table.column(1).visible())
{
var order = table.order();
for (var i = 0; i < order.length; i++)
{
// if we find column 1 in the list, remove it & backup one slot
if (order[i][0] == 1)
order.splice(i--, 1);
}
// if it's now empty, make name the sort column
if (order.length == 0)
order.push([2, "asc"]);
// make column invisible
table.column(1).visible(false);
}
}
else // inputs are both valid
{
if (table.column(1).visible() === false)
{
// make column visible
table.column(1).visible(true);
// force datatables to recalculate the proximity column
table.cells(null, 1).invalidate();
}
}
// redraw the table
table.draw();
} );
// Add event listener for opening and closing details
$('#mbcs tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
$(this).text("+");
}
else
{
// Open this row
row.child( ChildData(row.data()) ).show();
tr.addClass('shown');
$(this).text("-");
}
} );
// make the search box get focus automatically
$('div.dataTables_filter input').focus();
} );
</script>
</head>
<body>
<h1>Merit Badge Counselors</h1>
<p>Instructions:</p>
<ul>
<li><b>Filter</b> by distance by entering a target zip code and radius in miles. Distance is approximate and "as the crow flies".</li>
<li><b>Sort</b> by clicking column names. Shift-click on additional columns for multi-column sorting.</li>
<li><b>Search</b> specific columns by entering data in individual column search boxes. Adding columns narrows the search.</li>
<li><b>Global Search</b> across all fields using the "Search:" box at the top right. This includes 'hidden' data such as address, phone, email, etc.</li>
<li><b>Additional information</b> (address, phone, email, etc.) is available by clicking the "+" at the start of the row.</li>
<li><b>Colors:</b> Red = expired YPT; Orange = YPT expiring soon; Gray = MBC is not available</li>
</ul>
<span style="color: red; font-weight: bold">This information is NOT to be shared with anyone. It is to be used EXCLUSIVELY to support council and district advancement committee members.</span>
<table border="0" cellspacing="5" cellpadding="5">
<tbody>
<tr>
<td>Target zip code:</td>
<td><input type="text" id="targetZipcode" name="targetZipcode"></td>
</tr>
<tr>
<td>Radius (miles):</td>
<td><input type="text" id="radius" name="radius" value="10"></td>
</tr>
</tbody>
</table>
<table id="mbcs" class="display">
<thead>
<tr>
<th></th>
<th>Proximity</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th class="narrow">State</th>
<th>Zip code</th>
<th>Phone</th>
<th>Email</th>
<th>District</th>
<th>BSA ID</th>
<th>Merit Badges</th>
<th>Works with</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Proximity</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip code</th>
<th>Phone</th>
<th>Email</th>
<th>District</th>
<th>BSA ID</th>
<th>Merit Badges</th>
<th>Works with</th>
</tr>
</tfoot>
</table>
<p>Postal code data from <a href="www.geonames.org" target="_blank">www.geonames.org</a></p>
</body>
</html>