-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuiStep1.html
More file actions
420 lines (349 loc) · 12.3 KB
/
uiStep1.html
File metadata and controls
420 lines (349 loc) · 12.3 KB
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
<!DOCTYPE html>
<script>
if (window.trustedTypes && window.trustedTypes.createPolicy) {
window.trustedTypes.createPolicy('default', {
createHTML: string => string,
createScriptURL: string => string,
createScript: string => string,
});
}
</script>
<?!= HtmlService.createTemplateFromFile('uiStyle').evaluate().getContent(); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</script>
<div id="s1_mw">
<div id="s1_mw_instr">
<table border="0">
<tr>
<td><img src="<?= FLUBAROO_WELCOME_IMG_URL ?>"
style="padding-right:15px;">
</td>
<td>
<?= langstr("FBL_STR_STEP1_INSTR") ?>
</td>
</tr>
</table>
</div>
<div id="s1_mw_alert" class="error" style="display:none;"></div>
<!-- Alert shadow box -->
<div id="light" class="s1_white_content"></div>
<div id="fade" class="s1_black_overlay">
</div>
<!-- <div class="vspacer_full"></div> -->
<div id="s1_mw_sel">
<?=langstr('FLB_STR_LOADING')?>
</div>
<div style="float:right;margin-top:20px;">
<table border="0" id="s1_mw_continue"><tr>
<td><img id="s1_mw_working" src="<?= FLUBAROO_WORKING_IMG_BAR_URL ?>" style="display:none;"></td>
<td width="35px"></td>
<td><input type="button" class="action" value="Continue" onclick="step1Continue()" /></td>
</tr></table>
</div>
</div>
<script>
// run on load
$(function() {
var tz = null;
var locale = null;
try
{
tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
locale = Intl.DateTimeFormat().resolvedOptions().locale;
}
catch (e)
{
}
google.script.run.withSuccessHandler(populateQuestionData)
.uiStep1GetQuestionData(tz, locale);
});
var prior_grading_opts_g = null;
var continue_with_changed_student_idents_g = false;
function populateQuestionData(qdata)
{
console.log('populateQuestionData: returned with qdata: ' + JSON.stringify(qdata));
var h = '<table id="s1_mw_sel_table">';
h += '<tr><td style="white-space:nowrap;"><b><?= langstr("FLB_STR_GRADE_STEP1_LABEL_GRADING_OPTION") ?></b></td>';
var show_ec_arg = "false";
var show_categories = qdata.category_names.length > 0;
if (qdata.existing_gopts_exist)
{
prior_grading_opts_g = qdata.default_gopts;
}
if (qdata.show_extra_credit)
{
h += '<td class="s1_mw_sel_table_hspacer" style="white-space:nowrap;"><b><?= langstr("FLB_STR_GRADING_OPT_EXTRA_CREDIT") ?></b></td>';
show_ec_arg = "true";
}
h += '<td class="s1_mw_sel_table_hspacer" style="white-space:nowrap;"><b><?= langstr("FLB_STR_GRADE_STEP1_LABEL_POINTS") ?></b></td>';
if (show_categories)
{
h += '<td class="s1_mw_sel_table_hspacer" style="white-space:nowrap;"><b><?= langstr("FLB_STR_GRADE_STEP1_LABEL_CATEGORY") ?></b></td>';
}
// add column for question. have it take up the remaining horizontal space.
h += '<td class="s1_mw_sel_table_hspacer" width="99%"><b><?= langstr("FLB_STR_GRADE_STEP1_LABEL_QUESTION") ?></b></td>';
h += '</tr>'
// iterate through each question
for (var i=0; i < qdata.ques_vals.length; i++)
{
var q = qdata.ques_vals[i];
var default_gopt_index = qdata.default_gopts[i];
var default_gopt_val = qdata.possible_gopts[default_gopt_index];
var default_point_index = qdata.default_pts[i];
var default_extra_credit_checked = qdata.default_extra_credit[i];
var default_category = qdata.default_categories[i];
// for each question, list possible grading options
h += '<tr><td><div class="block form-group">';
h += '<select name="g_opts" id="g_opt_id_' + i + '" onchange="selectChange(\'' + i + '\',' + show_ec_arg + ',' + show_categories + ')">';
for (var j=0; j < qdata.possible_gopts.length; j++)
{
var gopt_val = qdata.possible_gopts[j];
var gopt_disp = qdata.possible_gopts_disp[j];
h += '<option value="' + gopt_val + '" ';
if (j == default_gopt_index)
{
h += 'selected';
}
h += '>' + gopt_disp + '</option>';
}
h += '</select></div>';
h += '</td>';
// show "extra credit" checkbox if allowed in advanced options, but only enable it if question is gradeable.
var d = "";
var c = "";
if (qdata.show_extra_credit)
{
if ((default_gopt_val.indexOf('<?=GRADING_OPT_NORMAL?>') == -1)
&& (default_gopt_val.indexOf('<?=GRADING_OPT_MANUAL?>') == -1))
{
d = " disabled ";
}
else if (default_extra_credit_checked)
{
c = " checked ";
}
h += '<td class="s1_mw_sel_table_hspacer"><input type="checkbox" name="g_extra_credit" id="g_ec_id_' + i + '" ' + d + c + '></td>';
}
// for each question, list possible points worth
h += '<td class="s1_mw_sel_table_hspacer"><div class="block form-group">';
// initially disable points selector if question is not gradeable (i.e. Identifies Student)
if ((default_gopt_val.indexOf('<?=GRADING_OPT_NORMAL?>') == -1)
&& (default_gopt_val.indexOf('<?=GRADING_OPT_MANUAL?>') == -1))
{
d = " disabled ";
}
h += '<select class="s1_mw_sel_pts" name="g_pts" id="g_pts_id_' + i + '" ' + d + '>';
for (var j=0; j < qdata.possible_pts.length; j++)
{
var pt = qdata.possible_pts[j];
h += '<option value="' + pt + '" ';
if (j == default_point_index)
{
h += 'selected';
}
h += '>' + pt + '</option>';
}
h += '</select></div>';
// if applicable, show a drop-down of category names
if (show_categories)
{
h += '<td class="s1_mw_sel_table_hspacer"><div class="block form-group">';
h += '<select class="s1_mw_sel_category" name="g_category" id="g_category_id_' + i + '" ' + d + '>';
// show blank as the first option, meaning no category selected.
h += '<option value="" ';
if (d !== "")
{
h += 'selected';
}
h += '></option>';
for (var j=0; j < qdata.category_names.length; j++)
{
var cat = qdata.category_names[j];
h += '<option value="' + cat + '" ';
if (d === "" && (qdata.category_names[j] === default_category))
{
h += 'selected';
}
h += '>' + cat + '</option>';
}
h += '</select></div>';
}
// for each question, list the question itself
h += '<td class="s1_mw_sel_table_hspacer">';
h += q;
h += '</td></tr>';
}
h += '</table>';
console.log('populateQuestionData: setting html');
$('#s1_mw_sel').html(h);
console.log('populateQuestionData: returning');
// record (globally) any pre-existing grading options
}
function selectChange(id_num, show_extra_credit, show_categories)
{
var gopt_elem_id = "#g_opt_id_" + id_num;
var pts_elem_id = "#g_pts_id_" + id_num;
var pts_extra_credit_id = "#g_ec_id_" + id_num;
var category_name_id = "#g_category_id_" + id_num;
var gopt_val = $(gopt_elem_id).val();
if ((gopt_val.indexOf('<?=GRADING_OPT_NORMAL?>') == -1)
&& (gopt_val.indexOf('<?=GRADING_OPT_MANUAL?>') == -1))
{
$(pts_elem_id).prop('disabled', true);
if (show_extra_credit)
{
$(pts_extra_credit_id).prop('disabled', true);
}
if (show_categories)
{
$(category_name_id).prop('disabled', true);
$(category_name_id).val("");
}
}
else
{
$(pts_elem_id).prop('disabled', false);
if (show_extra_credit)
{
$(pts_extra_credit_id).prop('disabled', false);
}
if (show_categories)
{
$(category_name_id).prop('disabled', false);
}
}
}
// The code in this function runs when the page is loaded.
function step1Continue()
{
var server_gopts = [];
var server_category_names = [];
var iden_student = false; // at least one student identifier?
var gradeable_ques = false;
clearAlert();
// always add a first option of "skip" for the timestamp question
server_gopts.push("<?=GRADING_OPT_SKIP?>");
var g_cat = document.getElementsByName('g_category');
if (g_cat)
{
// if recording categories, put the one for the timestamp as blank
// (will be ignored).
server_category_names.push("");
}
// Parse all HTML form data into an array of grading options
// that can be passed to the server.
var g_opts = document.getElementsByName('g_opts');
for (var i=0; i < g_opts.length; i++)
{
var gopt = g_opts[i].value;
if (gopt == "<?=GRADING_OPT_STUD_ID?>")
{
iden_student = true;
}
else if ((gopt.indexOf("<?=GRADING_OPT_NORMAL?>") != -1) || (gopt.indexOf("<?=GRADING_OPT_MANUAL?>") != -1))
{
gradeable_ques = true;
}
server_gopts.push(gopt);
}
// Check if extra credit was assigned to any question. Length of g_ec will be 0 if
// extra credit isn't enabled.
var g_ec = document.getElementsByName('g_extra_credit');
for (var i=0; i < g_ec.length; i++)
{
// if extra credit, modify the corresponding grading option.
if (g_ec[i].checked)
{
server_gopts[i+1] = server_gopts[i+1] + <?=GRADING_OPT_EXTRA_CREDIT?>;
}
}
var g_pts = document.getElementsByName('g_pts');
for (var i=0; i < g_pts.length; i++)
{
var g_pt = g_pts[i].value;
// if possible to assign points to this question type, then record how many.
if ((server_gopts[i+1].indexOf("<?=GRADING_OPT_NORMAL?>") != -1)
|| (server_gopts[i+1].indexOf("<?=GRADING_OPT_MANUAL?>") != -1))
{
server_gopts[i+1] += "|" + g_pt;
}
}
// Do client-side checks.
// At least one stud iden field
if (!iden_student)
{
showAlert('<?=langstr("FBL_STR_GRADE_STEP1_STUD_IDENT_ERROR")?>');
return;
}
// At least one gradeable question
if (!gradeable_ques)
{
showAlert('<?=langstr("FBL_STR_GRADE_STEP1_NO_GRADEABLE_ERROR")?>');
return;
}
if (prior_grading_opts_g)
{
var new_sid_opt_fp = "";
var old_sid_opt_fp = "";
for (var i=1; i < server_gopts.length; i++)
{
if (server_gopts[i] === "<?=GRADING_OPT_STUD_ID?>")
{
new_sid_opt_fp += (i-1).toString();
}
}
// assumes that GRADING_OPT_STUD_ID always has index 0 (first)
for (var i=0; i < prior_grading_opts_g.length; i++)
{
if (prior_grading_opts_g[i] === 0)
{
old_sid_opt_fp+= (i).toString();
}
}
// Check if they've changed student identifying fields
if (new_sid_opt_fp !== old_sid_opt_fp)
{
if (!continue_with_changed_student_idents_g)
{
//showAlert('<?=langstr("FBL_STR_CHANGING_STUDENT_IDENTIFIERS_WARNINGS")?>');
openPopup('<?=langstr("FBL_STR_CHANGING_STUDENT_IDENTIFIERS_WARNINGS")?>');
continue_with_changed_student_idents_g = true; // let them through if they hit Continue again
return;
}
}
}
// Process category names
if (g_cat)
{
for (var i=0; i < g_cat.length; i++)
{
server_category_names.push(g_cat[i].value);
}
}
// show the animation next to the continue button
$('#s1_mw_working').show();
// call server-side function, passing it the grading options
google.script.run.gradingStep1SubmitHandler(server_gopts, server_category_names);
}
function showAlert(alert)
{
$('#s1_mw_alert').html(alert);
$('#s1_mw_alert').show(200);
}
function clearAlert()
{
$('#s1_mw_alert').html('');
$('#s1_mw_alert').hide(200);
}
function openPopup(msg)
{
$('#light').html(msg);
$('#light').show(200);
$('#fade').show(200);
}
function closePopup()
{
$('#light').hide(200);
$('#fade').hide(200);
}
</script>