-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
378 lines (301 loc) · 9.29 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>PLP Hour Checker</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css" />
<!-- reset.css -->
<link rel="stylesheet" href="https://drive.google.com/uc?export=download&id=0Bxe1aH3lWDbtQkhHdnBrUzMwN3M"/>
<!-- styles.css -->
<link rel="stylesheet" href="https://drive.google.com/uc?export=download&id=0Bxe1aH3lWDbtT1VoZ3RGaTNrUU0"/>
<link rel="shortcut icon" href="/favicon.ico"/>
<!-- progressbar -->
<script src="https://drive.google.com/uc?export=download&id=0Bxe1aH3lWDbtdlBpODBzeFRqS0k"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var server_addr = 'https://plp-rubyserverapps.rhcloud.com:8443';
if(window.location.hostname == 'localhost') {
server_addr = window.location.href;
}
var server = io.connect(server_addr);
var client_id = null;
server.on('id', function(data) {
client_id = data.body;
console.log('received client id');
});
</script>
<style>
.hidden {
display:none;
}
#stats1Out {
z-index: 3;
}
</style>
</head>
<body>
<div id="main-panel" class="panel">
<div class="fx-shadow-overlay"></div><!--#fx-shadow-overlay-->
<div class="wrapper">
<div id="brand">
<!-- <p class="logo">Scan Your ID</p>
<p class="tagline">Please scan your ID to continue</p> -->
</div><!--#brand-->
<div class="stats" id="stats1">
<div class="stats-out" id="stats1Out"></div><!--.stats-out-->
</div><!--.circle-->
<div class="panel-content">
<div class="editor">
<div class="editor-wrapper">
<div class="editor-content Bloom-colorize">
<!-- <div id="sid"></div> -->
<h1 id="sid-input">Upload File</h1>
</div><!--.editor-content-->
</div><!--.editor-wrapper-->
</div><!--.editor-->
</div><!--.panel-content-->
<div id="out">Calculate PLP hours by clicking or dragging your file above.</div>
</div><!--#home-page-->
</div><!--#main-panel-->
<div class="panel" id="results-panel">
<div class="nav-bar">
<div class="nav-bar-logo"></div>
<div class="nav-bar-text">PLP Hour Checker</div>
<div class="nav-bar-exit" id="close-button"><span class="fa fa-close fa-lg"></span></div>
</div><!--.nav-bar -->
<div class="wrapper">
<div class="panel-content">
<div class="editor">
<div class="editor-wrapper">
<div class="editor-content" id="results-content">
Loading, please wait....
</div><!--.editor-content-->
</div><!--.editor-wrapper-->
</div><!--.editor-->
</div><!--.panel-content-->
</div><!--.wrapper-->
</div><!--.panel-->
<div id="overlay"></div><!--#overlay-->
<form method="post" action="/upload" enctype="multipart/form-data" name="form" class="hidden">
<input type="file" name="excel" />
</form>
<script>
// load progressbar
var statsOutProgress = new ProgressBar.Circle('#stats1', {
color:'rgba(180,243,255,1.0)',
duration:1200,
easing:'easeIn',
strokeWidth:1,
trailColor:'rgba(255,255,255,0.05)'
});
statsOutProgress.set(0);
var animation = {
from: {color: 'rgba(180,243,255,1.0)'},
to: {color: 'rgba(180,243,255,1.0)'},
duration: 800,
callbacks: {},
has_finished: false,
step: function(state, circle) {
circle.path.setAttribute('stroke', state.color);
},
refresh: function(percent, callback) {
animation.has_finished = false;
statsOutProgress.animate(percent || 0, animation, function() {
animation.has_finished = true;
if(typeof callback == 'function') {
callback.call();
}
});
},
reset: function(progress) {
statsOutProgress.set(progress || 0);
},
on: function(evt, callback, rm) {
if(!animation.callbacks[evt]) {
animation.callbacks[evt] = [];
}
callback.rm = rm || false;
animation.callbacks[evt].push(callback);
},
emit: function(evt, args) {
if(!animation.callbacks[evt]) {
return;
}
if(!(args instanceof Array)) {
args = [args];
}
var idx_rm = [];
for(var i = 0; i < animation.callbacks[evt].length; i++) {
if(animation.callbacks[evt][i].rm) {
idx_rm.push(i);
}
animation.callbacks[evt][i].apply(this, args);
}
if(!idx_rm.length) {
return;
}
for(var i = 0; i < idx_rm.length; i++) {
animation.callbacks[evt].splice(idx_rm[i], 1);
}
}
};
var closeButton = document.getElementById('close-button');
$(closeButton).on('click', function() {
hideResults();
});
var uploadLogo = document.getElementById('stats1');
var uploadText = document.getElementById('sid-input');
$(uploadText).on('click', function(e) {
console.log('click');
document.form.excel.click();
});
$(uploadLogo).on('click', function(e) {
document.form.excel.click();
});
// Enable drag to upload if available
if (window.File && window.FileList && window.FileReader) {
var filedrag = $("#stats1Out");
var xhr = new XMLHttpRequest();
if (xhr.upload) {
filedrag.on('drop', function(e) {
e.preventDefault();
e.stopPropagation();
doUpload(e.originalEvent.dataTransfer.files);
});
filedrag.on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
statsOutProgress.set(1);
});
filedrag.on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
});
filedrag.on('dragleave', function (e) {
e.stopPropagation();
e.preventDefault();
statsOutProgress.reset();
});
}
}
// Enable file chooser upload
$(document.form.excel).on('change', function() {
doUpload(document.form.excel.files);
});
function doUpload(files) {
animation.reset();
if(!files.length) {
return;
}
// set message
var sidInput = document.getElementById('sid-input');
sidInput.innerHTML = 'Uploading...';
var formData = new FormData();
formData.append('excel', files[0]);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.setRequestHeader('enctype', 'multipart/form-data');
xhr.send(formData);
$(xhr).on('progress', function(byteStream) {
if(byteStream.lengthComputable && byteStream.loaded / byteStream.total < 1) {
animation.refresh(byteStream.loaded / byteStream.total);
console.log(byteStream.loaded / byteStream.total * 100);
}
});
$(xhr).on('load', function() {
animation.reset();
animation.refresh(1, function() {
animation.emit('end');
});
});
$(xhr).on('error', function(err) {
console.log('An error ocurred uploading your file', err);
animation.to = {color: 'rgba(205,55,0, 1.0)'};
});
$(xhr).on('readystatechange', function() {
if(xhr.status == 200 && xhr.readyState == 4) {
handleServerResponse(xhr.responseText, function(err, data) {
document.form.excel.value = '';
sidInput.innerHTML = 'Upload File';
if(err) {
return showAlert(err);
}
animation.on('end', function() {
showResults(data);
}, true);
});
}
});
}
function handleServerResponse(response, callback) {
var err = null;
callback = callback || function() {};
animation.to = {color: 'rgba(205,55,0, 1.0)'};
if(response == 'err_upload') {
err = 'An error occurred while uploading your file, please try again.';
}
if(response == 'err_filename') {
err = 'Unexpected client filename. Please try again.';
}
if(response == 'err_doctype') {
err = 'The file format you are trying to upload is not supported.';
}
if(response == 'err_parse') {
err = 'There was an error reading your file, please try again.';
}
if(err) {
return callback.call(this, err, null);
}
try {
animation.to = {color: 'rgba(180,243,255,1.0)'};
callback.call(this, null, JSON.parse(response));
} catch(e) {
callbac.call(this, e.toString(), null);
}
}
function showResults(data) {
$('#main-panel').fadeOut('normal', function() {
var content = 'Welcome <b>' + (data.name || '') + '</b>,<br />';
content += 'You have completed a total of <b>' + data.hours.year + '</b> hours this year.<br />';
content += 'This semester alone, you have submitted <b>' + data.hours.semester + '</b> hours.<br /><br />';
content += 'You have completed a total of <b>' + data.hours.total + '</b> hours during your time in the PLP program.';
$('#results-panel').fadeIn();
$('#results-content').html(content);
});
}
function hideResults() {
$('#results-panel').fadeOut('normal', function() {
$('#main-panel').fadeIn();
});
}
// display alert message
function showAlert(text) {
if(!showAlert.container) {
showAlert.container = document.createElement('div');
showAlert.container.className = 'alert-banner-top';
$(showAlert.container).on('click', function() {
clearTimeout(showAlert.container.timeout);
$(this).fadeOut();
});
document.body.appendChild(showAlert.container);
}
$(showAlert.container).fadeIn();
showAlert.container.innerHTML = text;
clearTimeout(showAlert.container.timeout);
showAlert.container.timeout = setTimeout(function() {
$(showAlert.container).fadeOut();
}, 100000);
}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-62273783-3', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>