1
/* IVLE - Informatics Virtual Learning Environment
2
* Copyright (C) 2007-2009 The University of Melbourne
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.
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.
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
18
* Author: Nick Chadwick
21
/* Show and hide the given page element */
22
function tog(something)
24
$('#' + something).toggle("slow");
27
function add_exercise()
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();
37
var callback = function(xhr)
42
testresponse = JSON.parse(xhr.responseText);
43
alert('Exercise Created');
44
window.location = '/+exercises';
48
alert('Error: Could not add exercise');
53
update_path = "api/+exercises";
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');
63
/* Edit the exercise values */
64
function edit_exercise()
67
var exercise_id = $('#exercise_id').val();
68
var exercise_name = $('#exercise_name').val();
69
var exercise_num_rows = $('#exercise_num_rows').val();
70
var exercise_desc = $('#exercise_desc').val();
71
var exercise_partial = $('#exercise_partial').val();
72
var exercise_solution = $('#exercise_solution').val();
73
var exercise_include = $('#exercise_include').val();
75
var callback = function(xhr)
80
testresponse = JSON.parse(xhr.responseText);
81
alert('Exercise Saved');
86
alert('Error updating Exercise');
91
update_path = "api/+exercises/" + exercise;
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,
96
'ivle.op': 'edit_exercise'};
97
ajax_call(callback, update_path, "", args, 'POST');
100
/* Modify, add and delete suites */
101
function edit_suite(suiteid)
103
var desc = $('#test_suite_description_' + suiteid).val();
104
var func = $('#test_suite_function_' + suiteid).val();
105
var stdin = $('#test_suite_stdin_' + suiteid).val();
107
var callback = function(xhr)
112
testresponse = JSON.parse(xhr.responseText);
113
alert('Suite Saved');
114
window.location.reload();
119
alert('Error Saving Test Suite');
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');
132
var desc = $('#new_test_suite_description').val();
133
var func = $('#new_test_suite_function').val();
134
var stdin = $('#new_test_suite_stdin').val();
136
var callback = function(xhr)
141
testresponse = JSON.parse(xhr.responseText);
142
alert('Suite Created Sucessfully');
143
window.location.reload();
148
alert('Error Creating Test Suite');
152
var args = {'ivle.op': 'add_suite', 'description': desc, 'function': func,
154
update_path = "api/+exercises/" + exercise;
155
ajax_call(callback, update_path, "", args, 'POST');
158
function delete_suite(suiteid)
160
var callback = function(xhr)
165
testresponse = JSON.parse(xhr.responseText);
166
alert('Suite Deleted.');
167
window.location.reload()
172
alert('Could not delete suite.');
177
var args = {'ivle.op': 'delete_suite', 'suiteid': suiteid}
178
update_path = "api/+exercises/" + exercise;
179
ajax_call(callback, update_path, "", args, 'POST');
182
/* Modify and add Variables */
183
function edit_var(varid, suiteid)
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();
190
var callback = function(xhr)
195
testresponse = JSON.parse(xhr.responseText);
196
alert('Variable Added Sucessfully');
197
window.location.reload();
202
alert('Error Creating Test Suite');
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};
211
update_path = "api/+exercises/" + exercise;
212
ajax_call(callback, update_path, "", args, 'POST')
216
function add_var(suiteid)
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();
221
var argno = $('#new_var_argno_' + suiteid).val();
223
var callback = function(xhr)
228
testresponse = JSON.parse(xhr.responseText);
229
alert('Variable Added Sucessfully');
230
window.location.reload();
235
alert('Error Adding Variable.');
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;
244
ajax_call(callback, update_path, "", args, 'POST');
247
function delete_var(varid, suiteid)
249
var callback = function(xhr)
254
testresponse = JSON.parse(xhr.responseText);
255
alert('Variable Deleted.');
256
window.location.reload();
261
alert('Error Deleting Variable');
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');
271
/* Add and edit test case parts */
273
function add_test_case(suiteid)
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();
279
var callback = function(xhr)
284
testresponse = JSON.parse(xhr.responseText);
285
alert('Test Case Added Sucessfully');
286
window.location.reload();
291
alert('Error Creating Test Suite');
296
var args = {'ivle.op': 'add_testcase', 'passmsg': passmsg,
297
'failmsg': failmsg, 'default': case_default,
299
update_path = "api/+exercises/" + exercise;
300
ajax_call(callback, update_path, "", args, 'POST');
304
function edit_test_case(testid, suiteid)
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();
310
var callback = function(xhr)
315
testresponse = JSON.parse(xhr.responseText);
316
alert('Test Case Modified Sucessfully');
321
alert('Error Saving Test Case');
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');
333
function delete_testcase(testid, suiteid)
335
var callback = function(xhr)
340
testresponse = JSON.parse(xhr.responseText);
341
alert('Test Case Deleted.');
342
window.location.reload();
347
alert('Error Deleting Test Case');
352
var args = {'ivle.op': 'delete_testcase', 'testid': testid,
354
update_path = "api/+exercises/" + exercise;
355
ajax_call(callback, update_path, "", args, 'POST');
358
/* Functions to add, edit, and delete test case parts */
359
function edit_test_part(partid, testid, suiteid)
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();
366
var callback = function(xhr)
371
testresponse = JSON.parse(xhr.responseText);
372
alert("Test Part Modified");
376
alert("Error Adding Test Part");
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');
388
function add_test_part(testid, suiteid)
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();
395
var savebutton = $("#new_test_part_save_" + testid);
396
savebutton.attr('value', 'Saving...');
397
savebutton.attr('disabled', 'disabled');
399
var callback = function(xhr)
403
var test_parts = $("#test_case_parts_" + testid);
406
testresponse = JSON.parse(xhr.responseText);
407
savebutton.attr('value', 'Saving...');
408
savebutton.removeAttr('disabled');
410
alert("Test Part Added");
411
window.location.reload();
416
alert("Error Adding Test Part");
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');
428
function delete_testpart(partid, testid, suiteid)
430
var callback = function(xhr)
434
testresponse = JSON.parse(xhr.responseText);
435
alert("Test Part Deleted.");
436
window.location.reload();
441
alert("Error Deleting Test Part");
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');