-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
310 lines (294 loc) · 20.3 KB
/
index.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
<!DOCTYPE html>
<html lang="en" style="height:100%;">
<head>
<meta charset="utf-8">
<title>MaskGoShare - by better.sg</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="masks coronavirus wuhan singapore emergency supplies sharing"/>
<meta name="description" content="Mask Go Share - by better.sg"/>
<link rel="shortcut icon" href="ico/favicon.png">
<!-- Core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet">
<!-- Style Library -->
<link href="css/style-library-1.css" rel="stylesheet">
<link href="css/plugins.css" rel="stylesheet">
<link href="css/blocks.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<meta name="author" content="better.sg">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-97654928-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-97654928-2');
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/formResponses1', function(data) {
var template = Handlebars.compile($('#item-template').html());
$('#requestlist').html(template(data.formResponses1))
var template2 = Handlebars.compile($('#form86').html());
$('#formInput86').html(template(data.formResponses1))
})
// HandlebarsIntl.registerWith(Handlebars);
})
$(document).ready(function(){
$.getJSON('https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/formResponses1', function(data) {
var template = Handlebars.compile($('#formscript').html());
$('#selectoptions').html(template(data.formResponses1))
})
// HandlebarsIntl.registerWith(Handlebars);
$('#submitdonation').submit(function(e) {
e.preventDefault();
let form = $(this);
$.ajax({
type: 'post',
dataType: 'json',
url: 'https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/sheet1',
data: {
sheet1: {
timestamp: Date.now(),
selectoptions: $('#selectoptions').val(),
inputEmail1: $('#InputEmail1').val(),
}
},
success: function() {
alert('thank you!');
},
error: function(xhr, res, text) {
alert('Failed');
}
});
});
})
</script>
<script id="formscript" type="text/x-handlebars-template">
{{#each this}}
<option value="{{item}} - {{postalcode}}">{{item}} at S({{postalcode}})</option>
{{/each}}
</script>
<script id="item-template" type="text/x-handlebars-template">
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Request</th>
<th>Remarks</th>
<th>Postal Code</th>
</tr>
</thead>
<tbody >
{{#each this}}
<tr>
<td><small>{{ timestamp}}</small></td>
<td><a target="_top" href="mailto:{{email}}?subject=MaskGoShare">{{item}}</a></td>
<td>{{comments}}</td>
<td><a target="_blank" href="https://www.google.com.sg/maps/place/Singapore+{{postalcode}}">S({{postalcode}})</a></td>
</tr>
{{/each}}
</tbody>
</table>
</script>
<script type="text/javascript">
$(document).ready(async function(){
// Get latitude/longitude coordinates of a postal code from OneMap.
let getCoords = async (postalcode) => {
const onemapRes =
await fetch(
"https://developers.onemap.sg/commonapi/search?searchVal=" +
postalcode +
"&getAddrDetails=N&returnGeom=Y&pageNum=1");
const onemapJson = await onemapRes.json();
const lat = parseFloat(onemapJson['results'][0]['LATITUDE']);
const lng = parseFloat(onemapJson['results'][0]['LONGITUDE']);
return [lat, lng];
};
// When the page loads, store all the request data and get the
// coordinates of each request.
// TODO: Edit Google Sheet to store latitude and longitude so that
// we don't have the query the API every time the page is loaded.
const allDataRes = await fetch(
"https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/formResponses1"
);
const allDataJson = await allDataRes.json();
const allData = allDataJson['formResponses1'];
let coords = [];
for (let request of allData) {
const postalcode = request.postalcode;
try {
[lat, lng] = await getCoords(postalcode);
coords.push({...request, lat, lng});
} catch(e) {
console.log(e + "invalid postal code: " + postalcode);
}
}
$('#searchpostalcodeform').submit(async function(e) {
e.preventDefault();
const postalcode = $('#searchpostalcode').val();
$('#requestlist').hide();
//$('#searchpostalcodeform').hide();
$('#requestsearch').show();
try {
[lat, lng] = await getCoords(postalcode);
coords.map(obj => {
// Squared distance from searched postal code to request (x^2 + y^2)
// unclear what the unit of distance is between two lat longs
obj.distance = Math.round(100000000 * (Math.pow(obj.lat - lat, 2) + Math.pow(obj.lng - lng, 2)));
})
coords.sort((a, b) => a.distance - b.distance);
const template = Handlebars.compile($('#searchresults').html());
$('#requestsearch').html(template(coords));
} catch(e) {
// If we fail to get the coordinates of the searched postal code (e.g. if
// invalid postal code is entered), revert to default behaviour, i.e. search
// returned no results.
$.getJSON('https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/formResponses1?postalcode='+$('#searchpostalcode').val(), function(data) {
var template = Handlebars.compile($('#searchresults').html())
$('#requestsearch').html(template(data.formResponses1))
});
}
});
});
</script>
<script id="searchresults" type="text/x-handlebars-template">
<div class="requestsearch">
Nearest neighbour:
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Request</th>
<th>Remarks</th>
<th>Postal Code</th>
</tr>
</thead>
<tbody >
{{#each this}}
<tr>
<td><small>{{timestamp}}</small></td>
<td><a target="_top" href="mailto:{{email}}?subject=MaskGoShare">{{item}}</a></td>
<td>{{comments}}</td>
<td><a target="_blank" href="https://www.google.com.sg/maps/place/Singapore+{{postalcode}}">S({{postalcode}})</a></td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</script>
</head>
<body data-spy="scroll" data-target="nav">
<section id="content-1-1" class="bg-white min-height-300px min-height-xs-300px content-1-1 content-block">
<div class="container text-center">
<h1>Mask GO SHARE</h1>
<h4 class="lead font-weight-bold">Offer to help your neighbours. Request for emergency supplies.</h4>
<p> In the face of the nCov virus, let’s do our part to help each other. If you have an extra mask or hand-sanitiser, you can gift it to someone near you who might need it. If you’re in need, you can ask for help below. </p>
<div class="row justify-content-center">
<a type="button" class="btn col-sm-4 mr-2 btn-info" href="#help">i can help</a>
<a type="button" class="btn col-sm-4 btn-danger" href="#need">I need supplies</a>
</div>
</div>
</section>
<div class="container">
<div class="row">
<div class="col-md-6">
<a name="help"></a>
<h3><b>I can help someone</b></h3>
<p>If you have more supplies than you need for your family, please consider gifting it to a neighbour who might need it more. You can browse through the requests below and drop off the supplies in their mailbox or contact them to collect it from you. It's a small gesture that makes a big difference when people are anxious.</p>
<form id="searchpostalcodeform" action="https://v2-api.sheety.co/3035041ee3fdb393cc81ecd0720b6a63/maskGoShare/formResponses1">
<div class="form-group">
<input type="text" class="form-control" id="searchpostalcode" placeholder="Enter your postal code">
</div>
<button type="submit" class="btn btn-block btn-dark" value="Search Requests">Search Requests</button>
</form>
Search function is still work-in-progress.
<div id="requestlist"></div>
<div id="requestsearch"></div>
<hr>
<br>
<p>Once you've donated your item, please <a data-toggle="collapse" href="#completedCollapse" role="button" aria-expanded="false" aria-controls="collapseExample">let us know</a> so we can remove it from the database.</p>
<div class="collapse" id="completedCollapse">
<div class="card card-body">
<form id="submitdonation">
<div class="form-group">
<label for="InputEmail1">Email address (to thank you!)</label>
<input type="email" class="form-control" id="InputEmail1" placeholder="Enter email">
</div>
<div class="form-group">
<label>Donation that was completed by you:</label>
<select id="selectoptions" class="form-control"></select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<small>Item list will be checked and updated within 24 hours</small>
</form>
</div>
</div>
<div id="submitdonation-success" hidden>Thank you for your donation!</div>
</div>
<div class="col-md-6">
<h3>Give a neighbourly gift of love</h3>
<p>This is a map of all 1-bedroom and 2-bedroom HDB rental flats. Individuals or families staying here may benefit from a little love and support. If you want to drop off some supplies with them, find the nearest blocks to you and consider going door-to-door or leaving a gift in their mailbox. <br>Buildings with 1-bedroom flats are highlighted in red.</p>
<iframe src="https://www.google.com/maps/d/u/1/embed?mid=1WsR_4uxrSDxYgdlqcMwYhtVQiWfnxLv5" width="100%" height="480"></iframe>
</div>
</div>
<hr class="border-danger"/>
<div class="row">
<div class="col-md-6 bg-clouds">
<a name="need"></a>
<h3><b>I need some supplies</b></h3>
<p>If you need supplies for you and your family, you ask for help by leaving a request below. Please be patient and understanding, we hope there will be someone who can extend the help you need. </p>
<script>var submitted=false;</script>
<iframe name="hidden_iframe" id="hidden_iframe" style="display:none;" onload="if(submitted) {window.location='thanks.html';}"></iframe>
<form action="https://docs.google.com/forms/u/1/d/e/1FAIpQLSc7jZ8A4WeijukhNfxgXYrjS9Qt8UbuzcCcDJn7gZaMzOw9vw/formResponse" target="hidden_iframe" onsubmit="submitted=true;" method="POST" id="mG61Hd">
<div class="form-group">
<input type="text" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="item" aria-describedby="i.desc.1897964019 i.err.1897964019" name="entry.333478349" value="" dir="auto" data-initial-dir="auto" data-initial-value="" class="form-control" id="item" placeholder="Item you need and quantity">
</div>
<div class="form-group">
<input type="text" class="form-control" id="comments" placeholder="Reason or remarks" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="comments" aria-describedby="i.desc.1249966876 i.err.1249966876" name="entry.1373228244" value="" dir="auto" data-initial-dir="auto" data-initial-value="" aria-invalid="false">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Your email address" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="email" aria-describedby="i.desc.1390464321 i.err.1390464321" name="entry.1054961902" value="" dir="auto" data-initial-dir="auto" data-initial-value="" aria-invalid="false">
</div>
<div class="form-group">
<input type="text" class="form-control" id="postalcode" placeholder="Your Postal Code" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="postalcode" aria-describedby="i.desc.184113030 i.err.184113030" name="entry.295006785" value="" dir="auto" data-initial-dir="auto" data-initial-value="" aria-invalid="false">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="mailbox" placeholder="Your unit number" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="mailbox" aria-describedby="i.desc.928328055 i.err.928328055" name="entry.1453636306" value="null" dir="auto" data-initial-dir="auto" data-initial-value="" aria-invalid="false">
<!-- <label class="control-label small">Your unit number will be shown to people who are willing to help.</label> -->
</div>
<button type="submit" class="btn btn-block btn-info">Submit Request</button>
</form>
<div id="submitrequest-success" style="display: none;">
Thanks - we've added your request to the list
</div>
</div>
<div class="col-md-6">
<h3>Mask donation / collection centres</h3>
<p>If you want to collect masks from the official Government supply, please visit <a href="https://maskgowhere.sg" target="_blank">maskgowhere.sg</a></p>
<p>If you wish to donate your masks to an official entity that can help redistribute the extra masks to our most vulnerable people, please visit <a href="https://contribute.sg">contribute.sg</a></p>
<p>Also check out interesting tools like <a href="https://ncov.chat">ncov.chat</a></p>
</div>
</div>
</div>
<footer class="text-center border-danger border border-top-0">
<hr class="border-danger"/>
<p class="text-center">This is a #techforgood product by <a href="https://better.sg" target="_blank">better.sg</a>. We solve social problems with technology. Find out more and join us! If you have any feedback for us, please email us at <a href="mailto:info@better.sg">info@better.sg</a></p>
<img src="images/bettersgmasterlogo.png" class="text-center"/>
</footer>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/plugins.js"></script>
<script src="https://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="js/bskit-scripts.js"></script>
</body>
</html>