-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstudent_view.html
330 lines (278 loc) · 12.7 KB
/
student_view.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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Student Login</title>
<script type="text/javascript" src="https://cdn.firebase.com/js/client/1.1.1/firebase.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.0.0/jquery.serialize-object.compiled.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/path.js/0.8.4/path.min.js"></script>
<script src="quiz_builder/js/utils.js"></script>
<script src="quiz_builder/js/models/session.js"></script>
<style type="text/css">
form {
display: none;
}
</style>
<script type="text/javascript">
var currentChar = 'boy';
function changeChar(charc) {
currentChar = charc;
$( "#charTable" ).children().css( "background-color", "white" );
$( "#"+charc ).css( "background-color", "#D1D1E0" );
}
</script>
<script type="text/javascript">
window.onload = function() {
(function(jQuery, Firebase, Path) {
"use strict";
var rootRef = new Firebase(Session.dataRef + '/' + Session.id);
var routeMap = {
'#/': {
form: 'frmProfile',
controller: 'profile',
authRequired: true
},
'#/logout': {
form: 'frmLogout',
controller: 'logout'
},
'#/profile': {
form: 'frmProfile',
controller: 'profile',
authRequired: true
},
};
var controllers = {};
var activeForm = null;
var alertBox = $('#alert');
function routeTo(route) {
window.location.href = '#/' + route;
}
function authAnonymously() {
var deferred = $.Deferred();
rootRef.authAnonymously(function(err, authData) {
if (authData) {
deferred.resolve(authData);
}
if (err) {
deferred.reject(err);
}
});
return deferred.promise();
}
function handleAuthResponse(promise, route) {
$.when(promise)
.then(function(authData) {
routeTo(route);
}, function(err) {
console.log(err);
showAlert({
title: err.code,
detail: err.message,
className: 'alert-danger'
});
});
}
function showAlert(opts) {
var title = opts.title;
var detail = opts.detail;
var className = 'alert ' + opts.className;
alertBox.removeClass().addClass(className);
alertBox.children('#alert-title').text(title);
alertBox.children('#alert-detail').text(detail);
}
controllers.logout = function(form) {
localStorage.setItem('currentUUID', '');
localStorage.setItem('currentName', '');
rootRef.unauth();
};
controllers.profile = function(form) {
var user = rootRef.getAuth();
var userRef;
if (!user) {
handleAuthResponse(authAnonymously(), 'profile');
return;
}
userRef = rootRef.child('Students').child(user.uid);
userRef.once('value', function(snap) {
var user = snap.val();
if (!user) {
return;
}
form.find('#txtName').val(user.name);
localStorage.setItem('currentUUID', user.uid);
localStorage.setItem('currentName', user.name);
});
form.on('submit', function(e) {
e.preventDefault();
var studentCount = 1;
var userInfo = $(this).serializeObject();
//var userChar = $("#charSelect").val();
var userChar = currentChar;
console.log(userChar);
rootRef.once('value', function(dataSnapshot) {
studentCount = dataSnapshot.val().StudentCount;
if (studentCount < 10) {
localStorage.setItem('currentUUID', user.uid);
localStorage.setItem('currentName', userInfo.Name);
localStorage.setItem('currentId', userInfo.ID);
Session.createUser(user.uid, userChar, userInfo, function onComplete() {
window.location.href = "test_tiles.html?session_id=" + Session.id;
});
} else {
if (Session.id == 'session12245') {
console.log("RESERING");
console.log(userRef);
rootRef.update({
"Students": {},
"StudentCount": 0
});
localStorage.setItem('currentUUID', user.uid);
localStorage.setItem('currentName', userInfo.Name);
localStorage.setItem('currentId', userInfo.ID);
Session.createUser(user.uid, userChar, userInfo, function onComplete() {
window.location.href = "test_tiles.html?session_id=" + Session.id;
});
} else {
showAlert({
title: 'Class completed!',
detail: 'No place is available at this session. Request a new session from your teacher.',
className: 'alert-info'
});
}
}
});
});
};
function transitionRoute(path) {
var formRoute = routeMap[path];
var currentUser = rootRef.getAuth();
var upcomingForm = $('#' + formRoute.form);
if (!activeForm) {
activeForm = upcomingForm;
}
activeForm.hide();
upcomingForm.show().hide().fadeIn(750);
activeForm.off();
activeForm = upcomingForm;
controllers[formRoute.controller](activeForm);
}
function prepRoute() {
transitionRoute(this.path);
}
Path.map("#/").to(prepRoute);
Path.map("#/logout").to(prepRoute);
Path.map("#/profile").to(prepRoute);
Path.root("#/");
$(function() {
Path.listen();
handleAuthResponse(authAnonymously(), 'profile');
rootRef.onAuth(function globalOnAuth(authData) {
if (authData) {
Session.fetchSessionQuestions();
showAlert({
title: 'Join class!',
detail: 'Enter your name and hit start to join class',
className: 'alert-success'
});
} else {
showAlert({
title: 'Left class',
detail: 'You have left class. Click "SchoolFarm" to join class again',
className: 'alert-info'
});
}
});
});
}(window.jQuery, window.Firebase, window.Path))
}
</script>
</head>
<body>
<header class="navbar navbar-static-top navbar-inverse" id="top" role="banner">
<div class="container">
<div class="navbar-header">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a href="#" class="navbar-brand">SchoolFarm</a>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li> <a href="quiz_builder/index.html">Create Quiz</a>
</li>
</ul>
</nav>
</div>
</header>
<div id="container" class="container">
<form id="frmLogout" role="form">
<h2>You are logged out!</h2>
</form>
<!-- Button trigger modal -->
<button type="button" style="float:right;" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
How to play
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">SchoolFarm - How to Play</h4>
</div>
<div class="modal-body">
<h4>Solve as much questions as you can to plant your land! <br> Compete with your friends by planting as much <span style = "color:#27ae60">grass</span> as you can by correctly answering the questions!</h4>
<br>
<h3> Grass Block (Correct)</h3><img src="sprites/GreenGrassBlock.png" />
<div style="text-align: right; "><h3> Dirt Block (Wrong!)</h3><img src="sprites/DirtBlock.png" /> </div>
<h4>Good Luck! </h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="alert" class="alert alert-success" role="alert">
<h4 id="alert-title">Logged in!</h4>
<p id="alert-detail">Using anonymous</p>
</div>
<form id="frmProfile" role="form">
<h2>Please type in your name</h2>
<br>
<div class="form-group">
<label for="txtName">Name</label>
<input type="text" class="form-control" id="txtName" placeholder="Name" name="Name">
</div>
<h2>Choose your player:</h2>
<!-- <div class="form-group">
<select id="charSelect">
<option value="boy">Boy</option>
<option value="girl">Pink Girl</option>
<option value="horn">Blue Girl</option>
<option value="pr">Princess</option>
<option value="cat">Cat Girl</option>
</select>
</div> -->
<table class="table ">
<tr id ="charTable" >
<td style="text-align: center;background:#D1D1E0;" id='boy' ><img src="sprites/CharacterBoy.png" onclick="changeChar('boy')" />
</td>
<td style="text-align: center;" id='cat'><img src="sprites/CharacterCatGirl.png" onclick="changeChar('cat')" />
</td>
<td style="text-align: center;" id='horn'><img src="sprites/CharacterHornGirl.png" onclick="changeChar('horn')" />
</td>
<td style="text-align: center;" id='girl'><img src="sprites/CharacterPinkGirl.png" onclick="changeChar('girl')" />
</td>
<td style="text-align: center;" id='pr'><img src="sprites/CharacterPrincessGirl.png" onclick="changeChar('pr')" />
</td>
</tr>
</table>
<div style="text-align:center;"><button type="submit" class="btn btn-primary btn-lg">Start Quiz!</button></div>
</form>
</div>
</body>
</html>