1
<tal:tag condition="view/update" />
2
/* This is the Javascript to be included when rendering the gradebook overview. */
3
var numstudents = <tal:block replace="python: len(view.students)"/>
4
var students = new Array(numstudents);
5
<tal:loop repeat="row view/table">
6
students[<tal:block replace="repeat/row/index"/>] = '<tal:block replace="python: view.breakJSString(row['student']['id'])"/>';
9
var numactivities = <tal:block replace="python: len(view.scorableActivities())"/>
10
var activities = new Array(numactivities);
11
<tal:loop repeat="activity view/activities">
12
activities[<tal:block replace="repeat/activity/index"/>] = '<tal:block replace="activity/hash"/>';
15
var numscores = <tal:block replace="python: len(view.scores)"/>;
16
var scores = new Object();
17
<tal:loop repeat="activity view/scores">
18
scores['<tal:block replace="activity" />'] = new Array(<tal:block replace="python: view.scores[activity]" />);
21
var numdescriptions = <tal:block replace="python: len(view.descriptions)"/>
22
var descriptions = new Array(numdescriptions);
23
<tal:loop repeat="activity view/descriptions">
24
descriptions['<tal:block replace="activity/act_hash"/>'] = '<tal:block replace="activity/description"/>';
31
function setNotEdited()
36
function checkChanges()
40
warningText = '<tal:block replace="view/warningText" />';
41
saveFlag = window.confirm(warningText);
44
button = document.getElementsByName('UPDATE_SUBMIT')[0];
51
function onLoadHandler()
53
// highlight error values
54
for (a = 0; a < numactivities; a++)
56
activity = activities[a];
57
for (s = 0; s < numstudents; s++)
59
name = activity + '_' + students[s];
60
value = document.getElementById(name).value;
61
setBackgroundColor(name, activity, value, true);
66
window.onload = onLoadHandler;
67
window.onunload = checkChanges;
70
function handleCellFocus(cell, activity)
74
setDescription(activity);
77
function setDescription(activity)
79
desc = document.getElementById('description');
80
currentDesc = descriptions[activity];
81
desc.innerHTML = currentDesc;
84
function tempDescription(activity)
86
desc = document.getElementById('description');
87
desc.innerHTML = descriptions[activity];
90
function restoreDescription()
92
desc = document.getElementById('description');
93
desc.innerHTML = currentDesc;
96
function spreadsheetBehaviour(e)
99
if(window.event) // IE
103
else if(e.which) // Netscape/Firefox/Opera
108
var my_name = currentCell.id;
110
done = new Boolean(false);
112
for (s = 0; s != numstudents; s++)
114
for (a = 0; a != numactivities; a++)
116
try_name = activities[a] + '_' + students[s]
117
if (try_name == my_name)
127
var i_stayed_put = new Boolean(true);
128
if (keynum == 37) // left arrow
130
if (a != 0) { a--; i_stayed_put = false;}
132
if (keynum == 39) // right arrow
134
if (a != numactivities - 1) {a++; i_stayed_put = false;}
136
if (keynum == 38) // up arrow
138
if (s != 0) {s--; i_stayed_put = false;}
140
if ((keynum == 40) || (keynum == 13)) // down arrow or enter
142
if (s != numstudents - 1) {s++; i_stayed_put = false;}
145
if (i_stayed_put == true)
147
var newname = activities[a] + '_' + students[s];
148
var el = document.getElementsByName(newname)[0]
153
function checkValid(e, name)
155
var activity = name.split('_')[0];
157
activity = name.split('_')[1];
162
if(window.event) // IE
166
else if(e.which) // Netscape/Firefox/Opera
170
if (keynum < 48 || (keynum > 57 && keynum < 65) || (keynum > 90 && keynum < 97) || keynum > 122)
176
var element = document.getElementById(name);
177
var elementCell = document.getElementById(name+'_cell');
178
var value = element.value;
180
return setBackgroundColor(name, activity, value, false);
183
function setBackgroundColor(name, activity, value, errors_only)
185
changeBackgroundColor(name+'_cell', 'default_bg');
190
// handle validation of discrete score system
191
var actScores = scores[activity];
192
if (actScores[0] == 'd')
194
for(var index in actScores)
196
if (index > 0 && value == actScores[index])
199
changeBackgroundColor(name+'_cell', 'changed_bg');
203
changeBackgroundColor(name+'_cell', 'error_bg');
207
// handle validation of ranged score system
210
var min = parseInt(actScores[1]);
211
var max = parseInt(actScores[2]);
212
var intValue = parseInt(value);
213
var regex = /[0-9]+$/;
214
if (!value.match(regex) || intValue < min)
216
changeBackgroundColor(name+'_cell', 'error_bg');
223
changeBackgroundColor(name+'_cell', 'warning_bg');
228
changeBackgroundColor(name+'_cell', 'changed_bg');
232
function performFillDown(activity) {
233
var fd = document.getElementById('fd_'+activity);
234
if (fd.value=='') return false;
235
changeBackgroundColor('fd_'+activity+'_cell', 'default_bg');
236
if (checkValid(null, 'fd_'+activity) == false) {
237
changeBackgroundColor('fd_'+activity+'_cell', 'warning_bg');
240
for(j=0;j!=numstudents;j++) {
241
name = activity+'_'+students[j];
242
document.getElementById(name).value = fd.value;
243
setBackgroundColor(name, activity, fd.value, false);
245
document.getElementById('fd_'+activity).value = '';
246
document.getElementById('fdbtn_'+activity).style.display = 'none';
247
changeBackgroundColor('fd_'+activity+'_cell', 'default_bg');
251
function checkFillDown(activity)
253
var fd = document.getElementById('fd_'+activity);
254
if (checkValid(null, 'fd_'+activity))
256
var el = document.getElementById('fdbtn_'+activity);
257
el.style.display='block';
258
if (document.getElementById('fd_'+activity).value=='') {
259
changeBackgroundColor('fd_'+activity+'_cell', 'default_bg');
260
el.style.display='none';
265
document.getElementById('fdbtn_'+activity).style.display='none';
266
if (document.getElementById('fd_'+activity).value=='') {
267
changeBackgroundColor('fd_'+activity+'_cell', 'default_bg');
272
function changeBackgroundColor(id, class) {
273
obj = document.getElementById(id);
274
$(obj).removeClass('default_bg');
275
$(obj).removeClass('changed_bg');
276
$(obj).removeClass('warning_bg');
277
$(obj).removeClass('error_bg');
278
$(obj).addClass(class);