-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
486 lines (469 loc) · 14.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
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, follow">
<meta name="format-detection" content="telephone-no">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
<title>PennCycle Mobile</title>
<link rel="stylesheet" href="static/css/themes/jquery.mobile-1.3.1.min.css">
<link rel="stylesheet" href="static/css/style.css">
<script src="static/js/jquery.js"></script>
<script src="static/js/index.js"></script>
<script src="static/js/jquery.mobile-1.3.1.min.js"></script>
<script src="static/js/cordova.js"></script>
<script src="static/js/mustache.js"></script>
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css">
<style type="text/css">
html, body {
height: 100%;
width: 100%;
margin: 0;
}
.asteriskField {
display: none;
}
.waiver_wrapper {
height: 300px;
overflow: scroll;
padding: 10px;
background-color: white;
}
#map {
width: 100%;
height: 50%;
}
.full {
height: 100%;
}
.logo {
height: 8%;
}
.logo img {
height: 100%;
}
.marker {
height: 22px;
width: 22px;
background-color: white;
text-align: center;
border-radius: 100%;
border: 1px solid black;
}
.station_marker {
padding-left: -10px;
background-color: hsl(220, 100%, 90%);
}
.bike {
display: none;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="static/js/markerwithlabel.js"></script>
<script>
var student_data, bike_data, map, phone, lat, lng;
var base_url = "http://localhost:8001/";
$(function(){
if (document.URL.indexOf("http://") == -1) {
phone = true;
} else {
phone = false;
}
if (window.phone) {
initializePhoneGap();
} else {
deviceReady();
}
});
function initializePhoneGap() {
var timer = window.setInterval(function () {
if (window.device) {
window.clearInterval(timer);
deviceReady();
}
}, 100 );
window.setTimeout(function () {
if (!window.device) {
window.clearInterval(timer);
alert("Failed to load within 10 seconds. Close and reopen the app.");
};
}, 10000 ); //10 seconds
};
function deviceReady() {
if (phone) {
var network = navigator.connection.type;
if (network == "none") {
$(".offline").css("visibility", "visible");
}
}
init();
$("#index").on("pageshow", function() {
location.reload();
init();
});
$("#check_for_student").click(function() {
penncard = $("#penncard").val();
$.post(
base_url + "mobile/check_for_student/",
{"penncard": penncard},
function(data) {
if (data.registered) {
$.mobile.changePage("#verify");
temp = "Welcome back, {{student}}!";
welcome_message = Mustache.render(temp, data);
$("#welcome_message").html(welcome_message);
window.localStorage.setItem("penncard", penncard);
} else {
$.mobile.changePage("#signup");
$("#signup_form_wrapper").html(data.signup_form);
}
});
});
$("#verify_pin").click(function() {
penncard = window.localStorage.getItem("penncard");
if (!penncard) {
$.mobile.changePage("#index");
}
pin = $("#pin").val();
$.post(
base_url + "mobile/verify/",
{"penncard": penncard, "pin": pin},
function(data) {
if (data.valid) {
window.localStorage.setItem("pin", pin);
student_data = data.student_data;
$.mobile.changePage("#index");
} else {
$("#pin_error").html("Pin did not match.");
}
});
});
$("#resend_pin").click(function() {
$.post(
base_url + "mobile/send_pin/",
{"penncard": penncard},
function(data) {
if (data.success) {
$("#pin_error").html(
"Pin sent to " + data.phone
);
} else {
$("#pin_error").html(
"Unable to resend PIN. Email messenger@penncycle.org if this problem persists."
);
}
});
});
$("#submit_signup_form").click(function(e) {
$.post(
base_url + "mobile/signup/",
$("#signup_form").serialize(),
function(data) {
if (data.success) {
window.localStorage.setItem("pin", data.pin);
$.mobile.changePage("#waiver");
$("#waiver_text").html(data.waiver);
student_data = data.student_data;
bike_data = data.bike_data;
} else {
$("#signup_form_wrapper").html(data.signup_form);
}
});
});
$("#accept_waiver").click(function() {
$.post(
base_url + "verify_waiver/",
{"penncard": window.localStorage.getItem("penncard")},
function(data) {
if (data.message == "success") {
$.mobile.changePage("#index");
}
});
});
$("#submit_feedback").click(function() {
$.post(
base_url + "mobile/feedback/",
{"feedback": $("#feedback_text").val()},
function(data) {
alert("Feedback submitted. Thanks!");
$.mobile.changePage("#index");
});
});
$("#logout").on("pageshow", function() {
window.localStorage.clear();
});
}
function init() {
console.log("that's why i'm init");
map = initMap();
get_bike_data();
get_station_data();
navigator.geolocation.getCurrentPosition(geoSuccess, geoFail);
if (!window.localStorage.hasOwnProperty("penncard")) {
$("#content").replaceWith($("#home"));
} else {
$.getJSON(base_url + "mobile/student_data/",
{"penncard": window.localStorage.getItem("penncard")},
function(data) {
display_account(data);
window.localStorage.setItem("student_string", JSON.stringify(data));
});
$("#content").replaceWith($("#welcome_checkout"));
}
$("#index").trigger("create");
}
function geoSuccess(position) {
console.log("Successfully got coordinates")
lat = position.coords.latitude;
lng = position.coords.longitude;
var currentPosition = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: currentPosition,
map: map
});
}
function geoFail(error) {
alert("Please enable location services.");
}
function initMap() {
var mapOptions = {
zoom: 16,
center: new google.maps.LatLng(39.951600,-75.197794),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
return map;
}
function get_bike_data() {
var station_counts = {};
$.getJSON(base_url + "mobile/bike_data/", function(bikes) {
bike_data = bikes;
for (var i = bikes.length - 1; i >= 0; i--) {
bike = bikes[i];
if (bike.status == "available") {
lat = bike.latitude - .0002;
lng = bike.longitude - .0001;
station = bike.location;
if (station_counts[station]) {
lng += .0005 * (station_counts[station] % 5);
lat -= .0005 * Math.floor(station_counts[station] / 5);
station_counts[station] += 1;
} else {
station_counts[station] = 1;
}
pos = new google.maps.LatLng(lat, lng);
var marker = new MarkerWithLabel({
position: pos,
map: map,
icon: "static/img/blank.png",
labelContent: bike.name,
labelClass: "marker"
});
google.maps.event.addListener(marker, "click", function(e) {
var el = e.target;
var number = el.innerText;
$("#bike_" + number).show();
});
}
}
if (window.localStorage.hasOwnProperty("penncard")) {
show_bikes_for_checkout();
}
});
}
function get_station_data() {
$.getJSON(base_url + "mobile/station_data/", function(stations) {
for (var i = stations.length - 1; i >= 0; i--) {
station = stations[i];
lng = station.longitude;
lat = station.latitude;
pos = new google.maps.LatLng(lat, lng);
var marker = new MarkerWithLabel({
position: pos,
map: map,
icon: "static/img/station_icon.png",
labelContent: station.name,
labelClass: "station_marker"
});
google.maps.event.addListener(marker, "click", function(e) {
var station = e.target.innerText;
$(".bike").hide();
$("." + station).show();
});
};
});
}
function show_bikes_for_checkout() {
var letters = ["a", "b", "c"];
var template = '<div id="bike_{{name}}" class="bike {{location}} ui-block-{{block}}">'
+ '<img src="static/img/bikes/{{manufacturer}}.png">'
+ '<h3>{{name}} ({{manufacturer}}): At {{location}}</h3>'
+ '<button class="checkout" number="{{name}}">Check Out</button>'
+ '</div>';
var available_bikes = [];
for (var i = bike_data.length - 1; i >= 0; i--) {
if (bike_data[i].status == "available") {
available_bikes.push(bike_data[i]);
}
}
for (var i = 0; i < available_bikes.length; i++) {
bike = available_bikes[i];
bike.block = letters[i % 3];
var html = Mustache.render(template, bike)
$("#bikes_for_checkout").append(html);
}
$("#index").trigger("create");
}
function display_account(data) {
if (data.can_ride) {
data.eligibility = "able";
} else {
data.eligible = "unable"
data.problem = "You don't currently have any PennCycle plans. "
+ "<a href='buy_plan'>Click here</a> to view your options.";
}
var template = '<h3>Welcome, {{ name}}! You are currently '
+ '{{ eligibility }} to ride.</h3>'
+ '<p>{{ data.problem }}<p>';
var html = Mustache.render(template, data);
$("#account_info").html(html);
$("#show_bikes").click(function() {
$(".bike").show();
});
$("#hide_bikes").click(function() {
$(".bike").hide();
});
}
$(document).on("click", ".checkout", function() {
var penncard = window.localStorage.getItem("penncard");
var pin = window.localStorage.getItem("pin");
var bike = $(this).attr("number");
$("#checkout_bike_number").html(bike);
$.post(
base_url + "mobile/checkout/",
{
"penncard": penncard,
"pin": pin,
"bike": bike,
}, function(data) {
if (data.success) {
$("#checkout_pin").html(data.combo);
$.mobile.changePage("#checkout_success");
} else {
$.mobile.changePage("#checkout_failure");
}
});
});
</script>
</head>
<body>
<div data-role="page" id="index" class="full">
<div data-role="header" class="logo" data-theme="b" href="#index">
<img src="static/img/logo.png">
</div>
<div data-role="content" class="full">
<div id="map"></div>
<div id="content"></div>
</div>
<h2 class="offline" style="display:none">Offline</h2>
<div data-role="footer" class="ui-bar">
<a href="#index">Home</a>
<a href="#feedback">Feedback?</a>
<a href="#logout">Log Out</a>
<a onclick="location.reload()">Refresh Data</a>
</div>
</div>
<div data-role="dialog" id="signup" data-transition="pop">
<div data-role="content">
<h2>Sign up to get started!</h2>
<div id="signup_form_wrapper"></div>
<button id="submit_signup_form">Submit</button>
</div>
</div>
<div data-role="dialog" id="feedback" data-transition="pop">
<div data-role="content">
<h2>We appreciate your feedback.</h2>
<p>If your comment is about the functionality of the app, please let us know what platform you are using (iOS, Android, etc).</p>
<input type="text" id="feedback_text">
<button id="submit_feedback">Submit</button>
</div>
</div>
<div data-role="dialog" id="verify" data-transition="pop">
<div data-role="content">
<h2 id="welcome_message"></h2>
<p>Enter your PIN to log in to PennCycle.</p>
<input type="number" id="pin" placeholder="4 digits">
<p id="pin_error"></p>
<div id="verify_pin" data-role="button" data-theme="d" type="button">Submit</div>
<br>
<a id="resend_pin">Forgot your pin? Click here to have it sent to your phone.</a>
</div>
</div>
<div data-role="page" id="waiver">
<div data-role="header" class="logo" data-theme="b">
<img src="static/img/logo.png">
</div>
<div data-role="content">
<h3>Please review and sign our waiver.</h3>
<div id="waiver_text" class="waiver_wrapper"></div>
<button id="accept_waiver">I accept this waiver.</button>
</div>
<div data-role="footer" class="ui-bar" data-theme="c">
<a href="#index">Home</a>
<a href="#feedback">Feedback?</a>
<a href="#logout">Log Out</a>
</div>
</div>
<div data-role="page" id="logout">
<div data-role="header" data-theme="b">
<img src="static/img/logo.png">
</div>
<div data-role="content">
<h2>You have been successfully logged out.</h2>
<p>Thanks for using Penncycle mobile!</p>
<a href="#index">Return Home</a>
</div>
<div data-role="footer" class="ui-bar">
<a href="#index">Home</a>
<a href="#feedback">Feedback?</a>
</div>
</div>
<div data-role="page" id="templates">
<div id="home">
<h2>Welcome to PennCycle Mobile!</h2>
<p class="message">Enter your PennCard to get started.</p>
<input type="number" id="penncard" placeholder="8 digits">
<button id="check_for_student">Submit</button>
</div>
<div id="welcome_checkout">
<div id="account_info"></div>
<p>To check out a bike, click on its icon on the map, or select it from the available bikes</p>
<a id="show_bikes">Show all bikes</a>
| <a id="hide_bikes">Hide bikes</a>
<div class="ui-grid-b" id="bikes_for_checkout"></div>
</div>
<div id="welcome_checkin">
<div id="account_info"></div>
<p>To check in a bike, select the station where you will be checking it in and then click check in.</p>
<div id="checked_out_bike"></div>
<button id="check_in_bike" class="disabled">Select at station...</button>
</div>
</div>
<div data-role="dialog" id="checkout_success">
<div data-role="content">
<h2>You have successfully checked out bike <b id="checkout_bike_number"></b>.</h2>
<p>The pin is <b id="checkout_pin"></b>.</p>
<p>If you do not have a helmet, you may either borrow one for free from Quaker Corner (see the map) or buy your own. <b>Helmets are required for riding PennCycle.</b></p>
<a href="#index">OK</a>
</div>
</div>
<div data-role="dialog" id="checkout_failure">
<div data-role="content">
<h2 class="text-error">You were unable to check out bike <span id="checkout_bike_number"></span></h2>
<p>This could be because the bike is not currently available, you are ineligible to ride, or your network connection failed.</p>
<a href="#index">OK</a>
</div>
</div>
</body>
</html>