-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld_class_scoring.html
452 lines (408 loc) · 18.7 KB
/
world_class_scoring.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>FLL Score Entry</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.js"></script>
<script type="text/javascript" src="CurrentTime.js"></script>
<script type="text/javascript" src="utilities.js"></script>
<link rel="stylesheet" href="jquery/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript">
BEGIN=true;
mode="Automatic";
var previousDataExists = new Boolean;
var previousData = [];
previousData[0]=[];
var rules;
var scoring_data;
var score_info = [];
var answers = [];
var default_answers = [];
var old_answers = [];
var start_time = 0;
var timer;
function submitScoreForm() {
var theForm = $("form[name='ScoreEntry']");
var posting = $.post( theForm.attr("action"), theForm.serialize());
// Put the results in a div
posting.done(function( data ) {
alert("Score Submitted!");
resetForm(false);
});
}
function checkData(){
var errString = "\n";
submitScoreForm();
}
function normalize(string) {
string = string.replace(/ /g, "_");
string = string.replace(/\?/, "");
string = string.replace(/,/, "");
string = string.replace(/\"/g, "");
string = string.replace(/\(/g, "");
string = string.replace(/\)/g, "");
string = string.replace(/\'/g, "");
return string;
}
function setSubmit(status) {
if (!BEGIN) {
document.getElementById("submitButton").disabled = !(status);
if (status) {
$("#unanswered").addClass("qhidden");
$("#submitButton").removeClass('invalid').addClass('valid');
} else {
if ($("#data").css("display") == "none") {
// Hide unanswered error message if questions are not
// visible
$("#unanswered").addClass("qhidden");
} else {
$("#unanswered").removeClass("qhidden");
}
$("#submitButton").removeClass('valid').addClass('invalid');
}
}
}
function validate() {
if (!validAnswers()) {
setSubmit(false);
return;
}
computeScore();
//Ensure all radio button groups have had values set
//Walk through the radio buttons, keying off the name and whether it's "checked"
var allChanged = true
if (!BEGIN) {
for (var i = 0; i < score_info.length; i++) {
// Look up the clicked status of named buttonset
var qinput = $("#"+score_info[i].name + " :radio:checked");
allChanged = allChanged && qinput.is(":checked");
}
}
if (!allChanged)
$("#unanswered").removeClass("qhidden");
setSubmit(allChanged);
}
function activateElements() {
for (var i = 0; i < score_info.length; i++) {
// Turn inputs into button sets - pressable buttons rather than radio box
$("#" + score_info[i]["name"]).buttonset();
$("input[name='" + score_info[i]["name"] + "']").change(function() {
saveAnswer(this, $(this).val());
$(this).addClass("qdone");
validate();
});
}
if (navigator.userAgent.indexOf("Android") != -1) {
// Hack for Android Chrome weirdness
// Bug is that the padding value is lost when button clicked, so
// we'll capture the initial padding value and apply it to all
// the buttons when they are created, this seems to work around the issue.
myElements = document.getElementsByClassName("ui-button-text");
pad_val = window.getComputedStyle(myElements[0]).padding;
for (var i = 0; i < myElements.length; i++) {
myElements[i].style.padding=pad_val;
}
}
if (window.devicePixelRatio > 1) {
// On high DPI device, make button text bigger
myElements = document.getElementsByClassName("ui-button-text");
pad_val = window.getComputedStyle(myElements[0]).padding;
for (var i = 0; i < myElements.length; i++) {
myElements[i].style.fontSize="2em";
}
}
// Make button click happen with mousedown
// Allows for faster entry on computer
// This must happen after the buttons have been added to the DOM
$('label').on('mousedown', function(event) {
switch (event.which) {
case 1:
$(this).click();
}
});
}
function getElements() {
var newHTML = "";
var prev_heading = "";
var sectionHTML = "";
var section_num = 1;
scoring_data = getXML("Data.xml");
elements = scoring_data.getElementsByTagName("Element");
var prev_heading = elements[0].getElementsByTagName("Heading")[0].childNodes[0].nodeValue;
for (var i = 0; i < elements.length; i++) {
var question = elements[i].getElementsByTagName("Question")[0].childNodes[0].nodeValue;
var heading = elements[i].getElementsByTagName("Heading")[0].childNodes[0].nodeValue;
var tag = elements[i].getElementsByTagName("Tag")[0].childNodes[0].nodeValue;
var validate = elements[i].getElementsByTagName("Validate");
var score_element = elements[i].getElementsByTagName("Score");
if (heading !== prev_heading) {
// Start new header div
newHTML += "<div id='" + normalize(prev_heading) + "' class='qsection'><em>" + section_num.toString() + " - " + prev_heading + "</em>" + sectionHTML + "</div>";
sectionHTML = "";
prev_heading = heading;
section_num++;
}
var name = tag;
sectionHTML += ("<div id='" + tag + "-div' class='qdiv'>" + question);
sectionHTML += "<br>";
sectionHTML += ("<span id='" + tag + "'>");
var options = elements[i].getElementsByTagName("Option");
for (var j = 0; j < options.length; j++) {
if (options[j].getElementsByTagName("LabelFull").length > 0) {
var qlabel = options[j].getElementsByTagName("LabelFull")[0].childNodes[0].nodeValue;
} else {
var qlabel = options[j].getElementsByTagName("Label")[0].childNodes[0].nodeValue;
}
var qvalue = options[j].getElementsByTagName("Value")[0].childNodes[0].nodeValue;
// normalize(qlabel) is the input form value expected
// by the webserver. However, that's not the value expected
// by the javascript score computation engine. So, we save
// the "real" value in this table so that we can substitute
// the right one for the score computation. Ugly hack.
// Really need score computation to happen in only one place
// or to use the exact same input values.
// values[normalize(qlabel)] = qvalue;
var default_element = options[j].getElementsByTagName("Default");
if (default_element.length > 0) {
default_answers[tag] = tag + j.toString();
}
sectionHTML += ("<input type='radio' id='" + name + j.toString() + "' name='" + name + "' value='" + qvalue + "'/>");
sectionHTML += ("<label for='" + name + j.toString() + "'>" + qlabel + "</label>");
}
sectionHTML += ("</span>");
sectionHTML += ("<span class='old' id='Old_" + tag + "'></span>");
sectionHTML += ("</div>");
score_info[i] = {
question: question,
heading: heading,
tag: tag,
name: name,
score: (score_element.length > 0) ? score_element[0].childNodes[0].nodeValue : "",
validate: (validate.length > 0) ? validate[0].childNodes[0].nodeValue : "",
};
}
newHTML += "<div id='" + normalize(heading) + "' class='qsection'><em>" + section_num.toString() + " - " + prev_heading + "</em>" + sectionHTML + "</div>";
document.write(newHTML);
}
function saveAnswer(element, value) {
var tag = element.name;
var qdiv = $('#'+tag + "-div");
// Translate form input value into something the scoring code likes
answers[tag] = value;
qdiv.removeClass("qerror").addClass("qdone");
}
function validAnswers() {
var result = {};
for (var i = 0; i < score_info.length; i++) {
var validate = score_info[i].validate;
if (validate.length > 0) {
try {
result = eval(validate);
} catch (err) {
// Okay to get errors for answers that aren't ready
result = {'highlight': false, 'msg':''};
}
// Look up the clicked status of named buttonset
var qinput = $("#"+score_info[i].tag + " :radio:checked");
var qdiv = $('#'+score_info[i].tag + "-div");
if (result.highlight) {
// This will switch the style to our error class
qdiv.removeClass("qdone").addClass("qerror");
document.getElementById("CurrentScore").innerHTML = "Error";
if (result.msg !== '') {
document.getElementById("error_status").innerHTML = result.msg;
$('#header').removeClass("header-normal").addClass("header-error");
$('#main').removeClass("main-normal").addClass("main-error");
return(false);
}
} else if (qinput.is(":checked")) {
// Sets style to 'qdone' which is light green
qdiv.removeClass("qerror").addClass("qdone");
} else {
qdiv.removeClass("qerror");
}
}
}
$('#header').removeClass("header-error").addClass("header-normal");
$('#main').removeClass("main-error").addClass("main-normal");
document.getElementById("error_status").innerHTML = "";
return(true);
}
function computeScore() {
var score = 0;
var code = "";
for (var i = 0; i < score_info.length; i++) {
if (score_info[i].score.length > 0) {
code = score_info[i].score;
try {
eval(code);
} catch (err) {
// Okay to get errors for answers that aren't ready
}
}
}
if (score < 0)
score = 0;
$('#total_score').val(score);
document.getElementById("CurrentScore").innerHTML = "Score: " + score;
}
function resetForm(do_confirm) {
if (do_confirm && !confirm("Form will be completely reset.\n"
+ "Are you sure you want this?")) {
return;
}
elements = scoring_data.getElementsByTagName("Element");
// This unchecks all radio buttons
$("input:radio").prop("checked", false);
// Refresh the button so it shows it's new state (unchecked)
$("input:radio").button("refresh");
for (var i = 0; i < elements.length; i++) {
qdiv = $('#'+score_info[i].tag + "-div");
qdiv.removeClass("qerror").removeClass("qdone").removeClass("qwarn");
// Remove any previous entry formating
var old = $("#Old_" + score_info[i].tag);
old.removeClass("warn").addClass("old");
}
// Clear answers, otherwise the answers will persist between resets.
answers = [];
// Refresh score on form.
computeScore();
setSubmit(false);
}
function findUnanswered(event) {
event.preventDefault();
var main = $("#main");
var content_top = $("#content").offset().top;
for (var i = 0; i < elements.length; i++) {
// Look up the clicked status of named buttonset
var qinput = $("#" + score_info[i].tag + " :radio:checked");
var qdiv = $("#" + normalize(score_info[i].heading));
if (!qinput.is(":checked")) {
var offset = qdiv.offset().top;
main.animate({scrollTop: offset-content_top}, 800);
return;
}
}
}
</script>
</head>
<body>
<div id="header" class="header-normal">
<div id="title-row">
<div id="left-header">
<div id="CurrentScore">Score: 000</div>
</div>
<div id="mid-header" align="center">
<div id="mid-header-title">
<em>FIRST<sup>®</sup></em> LEGO<sup>®</sup> League <br />
FLL WORLD CLASS<sup>(SM)</sup> Score Sheet
</div>
</div>
<div id="right-header" style="margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<div id="setup">
<button id="timer_button" class="start valid"
type="button" onClick="startTimer();">Start Timer</button>
</div>
<div id="timer" style="padding-top: 5px;">Time: 2:30</div>
</div>
</div>
<div id="error_status"> </div>
</div>
<script>
function updateTimer(){
var current_time = new Date().getTime() / 1000;
var diff_time = current_time - start_time;
var totalSec = Math.round(150 - diff_time);
var minutes = parseInt( totalSec / 60 ) % 60;
var seconds = totalSec % 60;
document.getElementById("timer").innerHTML= "Time: " +
minutes + ":" + (seconds < 10 ? "0" + seconds : seconds);
if (totalSec <= 0) {
startTimer();
}
}
function startTimer(){
if (timer == null) {
start_time = new Date().getTime() / 1000;
timer = setInterval(updateTimer,1000);
document.getElementById("timer_button").innerHTML= "Stop Timer";
$("#timer_button").removeClass('valid').addClass('invalid');
} else {
clearInterval(timer);
timer = null;
document.getElementById("timer_button").innerHTML= "Start Timer";
$("#timer_button").removeClass('invalid').addClass('valid');
}
document.getElementById("timer").innerHTML= "Time: 2:30";
}
</script>
<script type="text/javascript">
</script>
<!-- ======== END OF HEADER ======== -->
<div id="main" class="main-normal">
<div id="content">
<form name='ScoreEntry' action="Process_POST" method="post">
<table>
<tr>
<td id="form">
<center>
<div id="setup">
<button id="reset_form"
type="button" onClick="resetForm(true);">Reset Form</button>
</div>
</center>
<hr />
</td>
</tr>
<tr>
<td>
<div id="data">
<script>
getElements();
</script>
<input type="number" id="total_score" name="total_score" class="qhidden" value="0"/>
</div>
<div id="unanswered" class="qhidden">
<center>
<button class="invalid" style="padding: 50px"
onClick="findUnanswered(event);">
Unanswered questions present.
</button>
</center>
</div>
</td>
</tr>
<script>
BEGIN=false;
</script>
<tr>
<td>
<center><button id="submitButton" class="invalid"
type="button" onClick="resetForm(true);"
disabled>Done</button></center>
</td>
</tr>
</table>
Version: 1.0
</form>
</div>
<script>
// Make button click happen with mousedown
// Allows for faster entry on computer
$('label').on('mousedown', function(event) {
switch (event.which) {
case 1:
$(this).click();
}
});
$(document).ready(function() {
activateElements();
validate();
});
</script>
</div>
</body>
</html>