1099.1.213
by Nick Chadwick
Modifief exercise view, so that exercises can now be viewed in an |
1 |
/* IVLE - Informatics Virtual Learning Environment
|
2 |
* Copyright (C) 2007-2009 The University of Melbourne
|
|
3 |
*
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
|
7 |
* (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
*
|
|
18 |
* Author: Nick Chadwick
|
|
19 |
*/
|
|
20 |
||
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
21 |
/* Show and hide the given page element */
|
1099.1.214
by Nick Chadwick
The skeleton for editing an exercise has now been created. The next |
22 |
function tog(something) |
23 |
{
|
|
24 |
$('#' + something).toggle("slow"); |
|
1099.1.213
by Nick Chadwick
Modifief exercise view, so that exercises can now be viewed in an |
25 |
}
|
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
26 |
|
1099.1.229
by Nick Chadwick
Fixed a slight oversight, which meant there was no way to add a new |
27 |
function add_exercise() |
28 |
{
|
|
29 |
var exercise_id = $('#exercise_id').val(); |
|
30 |
var exercise_name = $('#exercise_name').val(); |
|
31 |
var exercise_num_rows = $('#exercise_num_rows').val(); |
|
32 |
var exercise_desc = $('#exercise_desc').val(); |
|
33 |
var exercise_partial = $('#exercise_partial').val(); |
|
34 |
var exercise_solution = $('#exercise_solution').val(); |
|
35 |
var exercise_include = $('#exercise_include').val(); |
|
36 |
||
37 |
var callback = function(xhr) |
|
38 |
{
|
|
39 |
var testresponse; |
|
40 |
try
|
|
41 |
{
|
|
42 |
testresponse = JSON.parse(xhr.responseText); |
|
43 |
alert('Exercise Created'); |
|
44 |
window.location = '/+exercises'; |
|
45 |
}
|
|
46 |
catch (ex) |
|
47 |
{
|
|
48 |
alert('Error: Could not add exercise'); |
|
49 |
return; |
|
50 |
}
|
|
51 |
}
|
|
52 |
||
53 |
update_path = "api/+exercises"; |
|
54 |
||
55 |
var args = {'identifier': exercise_id , 'name': exercise_name, |
|
56 |
'description': exercise_desc, 'partial': exercise_partial, |
|
57 |
'solution': exercise_solution, 'include': exercise_include, |
|
58 |
'num_rows': exercise_num_rows, 'ivle.op': 'add_exercise'}; |
|
59 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
60 |
||
61 |
}
|
|
62 |
||
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
63 |
/* Edit the exercise values */
|
64 |
function edit_exercise() |
|
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
65 |
{
|
66 |
||
67 |
var exercise_id = $('#exercise_id').val(); |
|
68 |
var exercise_name = $('#exercise_name').val(); |
|
69 |
var exercise_num_rows = $('#exercise_num_rows').val(); |
|
1099.1.221
by Nick Chadwick
added in extra parts to the exercise edit view. Now almost all |
70 |
var exercise_desc = $('#exercise_desc').val(); |
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
71 |
var exercise_partial = $('#exercise_partial').val(); |
72 |
var exercise_solution = $('#exercise_solution').val(); |
|
73 |
var exercise_include = $('#exercise_include').val(); |
|
74 |
||
75 |
var callback = function(xhr) |
|
76 |
{
|
|
77 |
var testresponse; |
|
78 |
try
|
|
79 |
{
|
|
80 |
testresponse = JSON.parse(xhr.responseText); |
|
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
81 |
alert('Exercise Saved'); |
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
82 |
return; |
83 |
}
|
|
84 |
catch(ex) |
|
85 |
{
|
|
86 |
alert('Error updating Exercise'); |
|
87 |
return; |
|
88 |
}
|
|
89 |
}
|
|
90 |
||
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
91 |
update_path = "api/+exercises/" + exercise; |
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
92 |
|
93 |
var args = {'name': exercise_name, 'description': exercise_desc, |
|
94 |
'partial': exercise_partial, 'solution': exercise_solution, |
|
95 |
'include': exercise_include, 'num_rows': exercise_num_rows, |
|
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
96 |
'ivle.op': 'edit_exercise'}; |
97 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
98 |
}
|
|
99 |
||
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
100 |
/* Modify, add and delete suites */
|
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
101 |
function edit_suite(suiteid) |
102 |
{
|
|
103 |
var desc = $('#test_suite_description_' + suiteid).val(); |
|
104 |
var func = $('#test_suite_function_' + suiteid).val(); |
|
105 |
var stdin = $('#test_suite_stdin_' + suiteid).val(); |
|
106 |
||
107 |
var callback = function(xhr) |
|
108 |
{
|
|
109 |
var testresponse; |
|
110 |
try
|
|
111 |
{
|
|
112 |
testresponse = JSON.parse(xhr.responseText); |
|
113 |
alert('Suite Saved'); |
|
114 |
window.location.reload(); |
|
115 |
return; |
|
116 |
}
|
|
117 |
catch(ex) |
|
118 |
{
|
|
119 |
alert('Error Saving Test Suite'); |
|
120 |
return; |
|
121 |
}
|
|
122 |
}
|
|
123 |
||
124 |
var args = {'ivle.op': 'edit_suite', 'description': desc, 'function': func, |
|
125 |
'stdin': stdin, 'suiteid': suiteid}; |
|
126 |
update_path = "api/+exercises/" + exercise; |
|
127 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
128 |
}
|
|
129 |
||
130 |
function add_suite() |
|
131 |
{
|
|
132 |
var desc = $('#new_test_suite_description').val(); |
|
133 |
var func = $('#new_test_suite_function').val(); |
|
134 |
var stdin = $('#new_test_suite_stdin').val(); |
|
135 |
||
136 |
var callback = function(xhr) |
|
137 |
{
|
|
138 |
var testresponse; |
|
139 |
try
|
|
140 |
{
|
|
141 |
testresponse = JSON.parse(xhr.responseText); |
|
142 |
alert('Suite Created Sucessfully'); |
|
143 |
window.location.reload(); |
|
144 |
return; |
|
145 |
}
|
|
146 |
catch(ex) |
|
147 |
{
|
|
148 |
alert('Error Creating Test Suite'); |
|
149 |
}
|
|
150 |
}
|
|
151 |
||
152 |
var args = {'ivle.op': 'add_suite', 'description': desc, 'function': func, |
|
153 |
'stdin': stdin}; |
|
154 |
update_path = "api/+exercises/" + exercise; |
|
155 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
156 |
}
|
|
157 |
||
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
158 |
function delete_suite(suiteid) |
159 |
{
|
|
160 |
var callback = function(xhr) |
|
161 |
{
|
|
162 |
var testresponse; |
|
163 |
try
|
|
164 |
{
|
|
165 |
testresponse = JSON.parse(xhr.responseText); |
|
166 |
alert('Suite Deleted.'); |
|
167 |
window.location.reload() |
|
168 |
return; |
|
169 |
}
|
|
170 |
catch (ex) |
|
171 |
{
|
|
172 |
alert('Could not delete suite.'); |
|
173 |
}
|
|
174 |
||
175 |
}
|
|
176 |
||
177 |
var args = {'ivle.op': 'delete_suite', 'suiteid': suiteid} |
|
178 |
update_path = "api/+exercises/" + exercise; |
|
179 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
180 |
}
|
|
181 |
||
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
182 |
/* Modify and add Variables */
|
1099.1.242
by Nick Chadwick
Fixed a problem with exercise editor, which wasn't editing or adding |
183 |
function edit_var(varid, suiteid) |
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
184 |
{
|
185 |
var var_name = $('#var_type_' + varid).val(); |
|
186 |
var var_val = $('#var_val' + varid).val(); |
|
187 |
var var_type = $('#var_name_' + varid).val(); |
|
188 |
var argno = $('#var_argno_' + varid).val(); |
|
189 |
||
190 |
var callback = function(xhr) |
|
191 |
{
|
|
192 |
var testresponse; |
|
193 |
try
|
|
194 |
{
|
|
195 |
testresponse = JSON.parse(xhr.responseText); |
|
196 |
alert('Variable Added Sucessfully'); |
|
197 |
window.location.reload(); |
|
198 |
return; |
|
199 |
}
|
|
200 |
catch(ex) |
|
201 |
{
|
|
202 |
alert('Error Creating Test Suite'); |
|
203 |
return; |
|
204 |
}
|
|
205 |
}
|
|
206 |
||
1099.1.242
by Nick Chadwick
Fixed a problem with exercise editor, which wasn't editing or adding |
207 |
var args = {'ivle.op': 'edit_var', 'var_name': var_name, |
208 |
'var_val': var_val, 'var_type': var_type, 'argno': argno, |
|
209 |
'varid': varid, 'suiteid': suiteid}; |
|
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
210 |
|
211 |
update_path = "api/+exercises/" + exercise; |
|
212 |
ajax_call(callback, update_path, "", args, 'POST') |
|
213 |
||
214 |
}
|
|
215 |
||
216 |
function add_var(suiteid) |
|
217 |
{
|
|
1099.1.242
by Nick Chadwick
Fixed a problem with exercise editor, which wasn't editing or adding |
218 |
var var_name = $('#new_var_name_' + suiteid).val(); |
219 |
var var_val = $('#new_var_val_' + suiteid).val(); |
|
220 |
var var_type = $('#new_var_type_' + suiteid).val(); |
|
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
221 |
var argno = $('#new_var_argno_' + suiteid).val(); |
222 |
||
223 |
var callback = function(xhr) |
|
224 |
{
|
|
225 |
var testresponse; |
|
226 |
try
|
|
227 |
{
|
|
228 |
testresponse = JSON.parse(xhr.responseText); |
|
229 |
alert('Variable Added Sucessfully'); |
|
230 |
window.location.reload(); |
|
231 |
return; |
|
232 |
}
|
|
233 |
catch(ex) |
|
234 |
{
|
|
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
235 |
alert('Error Adding Variable.'); |
1099.1.217
by Nick Chadwick
working on making the exercise editor complete |
236 |
return; |
237 |
}
|
|
238 |
}
|
|
239 |
||
240 |
var args = {'ivle.op': 'add_var', 'var_name': var_name, |
|
241 |
'var_val': var_val, 'var_type': var_type, |
|
242 |
'argno': argno, 'suiteid': suiteid}; |
|
243 |
update_path = "api/+exercises/" + exercise; |
|
1099.1.216
by Nick Chadwick
Started adding in add and save options in the exercise edit view, to |
244 |
ajax_call(callback, update_path, "", args, 'POST'); |
245 |
}
|
|
1099.1.221
by Nick Chadwick
added in extra parts to the exercise edit view. Now almost all |
246 |
|
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
247 |
function delete_var(varid, suiteid) |
248 |
{
|
|
249 |
var callback = function(xhr) |
|
250 |
{
|
|
251 |
var testresponse; |
|
252 |
try
|
|
253 |
{
|
|
254 |
testresponse = JSON.parse(xhr.responseText); |
|
255 |
alert('Variable Deleted.'); |
|
256 |
window.location.reload(); |
|
257 |
return; |
|
258 |
}
|
|
259 |
catch(ex) |
|
260 |
{
|
|
261 |
alert('Error Deleting Variable'); |
|
262 |
return; |
|
263 |
}
|
|
264 |
}
|
|
265 |
var args = {'ivle.op': 'delete_var', 'suiteid': suiteid, 'varid': varid}; |
|
266 |
update_path = "api/+exercises/" + exercise; |
|
267 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
268 |
||
269 |
}
|
|
270 |
||
1099.1.221
by Nick Chadwick
added in extra parts to the exercise edit view. Now almost all |
271 |
/* Add and edit test case parts */
|
272 |
||
273 |
function add_test_case(suiteid) |
|
274 |
{
|
|
1099.6.1
by Nick Chadwick
Exercise-ui is now able to create an entire exercise. |
275 |
var passmsg = $("#new_test_case_pass_" + suiteid).val(); |
276 |
var failmsg = $("#new_test_case_fail_" + suiteid).val(); |
|
277 |
var case_default = $("#new_test_case_default_" + suiteid).val(); |
|
1099.1.221
by Nick Chadwick
added in extra parts to the exercise edit view. Now almost all |
278 |
|
279 |
var callback = function(xhr) |
|
280 |
{
|
|
281 |
var testresponse; |
|
282 |
try
|
|
283 |
{
|
|
284 |
testresponse = JSON.parse(xhr.responseText); |
|
1099.6.1
by Nick Chadwick
Exercise-ui is now able to create an entire exercise. |
285 |
alert('Test Case Added Sucessfully'); |
1099.1.221
by Nick Chadwick
added in extra parts to the exercise edit view. Now almost all |
286 |
window.location.reload(); |
287 |
return; |
|
288 |
}
|
|
289 |
catch(ex) |
|
290 |
{
|
|
291 |
alert('Error Creating Test Suite'); |
|
292 |
return; |
|
293 |
}
|
|
294 |
}
|
|
295 |
||
1099.6.1
by Nick Chadwick
Exercise-ui is now able to create an entire exercise. |
296 |
var args = {'ivle.op': 'add_testcase', 'passmsg': passmsg, |
297 |
'failmsg': failmsg, 'default': case_default, |
|
298 |
'suiteid': suiteid}; |
|
299 |
update_path = "api/+exercises/" + exercise; |
|
300 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
301 |
||
302 |
}
|
|
303 |
||
304 |
function edit_test_case(testid, suiteid) |
|
305 |
{
|
|
306 |
var passmsg = $("#test_case_pass_" + testid + "_" + suiteid).val(); |
|
307 |
var failmsg = $("#test_case_fail_" + testid + "_" + suiteid).val(); |
|
308 |
var case_default = $("#test_case_default_" + testid + "_" + suiteid).val(); |
|
309 |
||
310 |
var callback = function(xhr) |
|
311 |
{
|
|
312 |
var testresponse; |
|
313 |
try
|
|
314 |
{
|
|
315 |
testresponse = JSON.parse(xhr.responseText); |
|
316 |
alert('Test Case Modified Sucessfully'); |
|
317 |
return; |
|
318 |
}
|
|
319 |
catch(ex) |
|
320 |
{
|
|
321 |
alert('Error Saving Test Case'); |
|
322 |
return; |
|
323 |
}
|
|
324 |
}
|
|
325 |
||
326 |
var args = {'ivle.op': 'edit_testcase', 'passmsg': passmsg, |
|
327 |
'failmsg': failmsg, 'default': case_default, |
|
328 |
'testid':testid, 'suiteid': suiteid}; |
|
329 |
update_path = "api/+exercises/" + exercise; |
|
330 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
331 |
}
|
|
332 |
||
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
333 |
function delete_testcase(testid, suiteid) |
334 |
{
|
|
335 |
var callback = function(xhr) |
|
336 |
{
|
|
337 |
var testresponse; |
|
338 |
try
|
|
339 |
{
|
|
340 |
testresponse = JSON.parse(xhr.responseText); |
|
341 |
alert('Test Case Deleted.'); |
|
342 |
window.location.reload(); |
|
343 |
return; |
|
344 |
}
|
|
345 |
catch(ex) |
|
346 |
{
|
|
347 |
alert('Error Deleting Test Case'); |
|
348 |
return; |
|
349 |
}
|
|
350 |
}
|
|
351 |
||
352 |
var args = {'ivle.op': 'delete_testcase', 'testid': testid, |
|
353 |
'suiteid': suiteid}; |
|
354 |
update_path = "api/+exercises/" + exercise; |
|
355 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
356 |
}
|
|
357 |
||
358 |
/* Functions to add, edit, and delete test case parts */
|
|
1099.6.1
by Nick Chadwick
Exercise-ui is now able to create an entire exercise. |
359 |
function edit_test_part(partid, testid, suiteid) |
360 |
{
|
|
361 |
var part_type = $("#test_part_part_type_" + partid).val(); |
|
362 |
var test_type = $("#test_part_test_type_" + partid).val(); |
|
363 |
var data = $("#test_part_data_" + partid).val(); |
|
364 |
var filename = $("#test_part_file_" + partid).val(); |
|
365 |
||
366 |
var callback = function(xhr) |
|
367 |
{
|
|
368 |
var testresponse; |
|
369 |
try
|
|
370 |
{
|
|
371 |
testresponse = JSON.parse(xhr.responseText); |
|
372 |
alert("Test Part Modified"); |
|
373 |
}
|
|
374 |
catch (ex) |
|
375 |
{
|
|
376 |
alert("Error Adding Test Part"); |
|
377 |
return; |
|
378 |
}
|
|
379 |
}
|
|
380 |
||
381 |
var args = {'ivle.op': 'edit_testpart', 'part_type': part_type, |
|
382 |
'test_type': test_type, 'data': data, 'filename': filename, |
|
383 |
'partid': partid, 'testid': testid, 'suiteid': suiteid}; |
|
384 |
update_path = "api/+exercises/" + exercise; |
|
385 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
386 |
}
|
|
387 |
||
388 |
function add_test_part(testid, suiteid) |
|
389 |
{
|
|
390 |
var part_type = $("#new_test_part_part_type_" + testid).val(); |
|
391 |
var test_type = $("#new_test_part_test_type_" + testid).val(); |
|
392 |
var data = $("#new_test_part_data_" + testid).val(); |
|
393 |
var filename = $("#new_test_part_file_" + testid).val(); |
|
394 |
||
395 |
var savebutton = $("#new_test_part_save_" + testid); |
|
396 |
savebutton.attr('value', 'Saving...'); |
|
397 |
savebutton.attr('disabled', 'disabled'); |
|
398 |
||
399 |
var callback = function(xhr) |
|
400 |
{
|
|
401 |
var testresponse; |
|
402 |
var test_part_id; |
|
403 |
var test_parts = $("#test_case_parts_" + testid); |
|
404 |
try
|
|
405 |
{
|
|
406 |
testresponse = JSON.parse(xhr.responseText); |
|
407 |
savebutton.attr('value', 'Saving...'); |
|
408 |
savebutton.removeAttr('disabled'); |
|
409 |
||
410 |
alert("Test Part Added"); |
|
411 |
window.location.reload(); |
|
412 |
return; |
|
413 |
}
|
|
414 |
catch (ex) |
|
415 |
{
|
|
416 |
alert("Error Adding Test Part"); |
|
417 |
return; |
|
418 |
}
|
|
419 |
}
|
|
420 |
||
421 |
var args = {'ivle.op': 'add_testpart', 'part_type': part_type, |
|
422 |
'test_type': test_type, 'data': data, 'filename': filename, |
|
423 |
'testid': testid, 'suiteid': suiteid}; |
|
424 |
update_path = "api/+exercises/" + exercise; |
|
425 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
426 |
}
|
|
427 |
||
1099.6.4
by Nick Chadwick
Exercise UI is now ready to be merged into trunk. |
428 |
function delete_testpart(partid, testid, suiteid) |
429 |
{
|
|
430 |
var callback = function(xhr) |
|
431 |
{
|
|
432 |
try
|
|
433 |
{
|
|
434 |
testresponse = JSON.parse(xhr.responseText); |
|
435 |
alert("Test Part Deleted."); |
|
436 |
window.location.reload(); |
|
437 |
return; |
|
438 |
}
|
|
439 |
catch (ex) |
|
440 |
{
|
|
441 |
alert("Error Deleting Test Part"); |
|
442 |
return; |
|
443 |
}
|
|
444 |
}
|
|
445 |
||
446 |
var args = {'ivle.op': 'delete_testpart', 'partid': partid, |
|
447 |
'testid': testid, 'suiteid': suiteid}; |
|
448 |
update_path = "api/+exercises/" + exercise; |
|
449 |
ajax_call(callback, update_path, "", args, 'POST'); |
|
450 |
}
|