1
1
/* IVLE - Informatics Virtual Learning Environment
2
* Copyright (C) 2007-2008 The University of Melbourne
2
* Copyright (C) 2007-2009 The University of Melbourne
4
4
* This program is free software; you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License as published by
63
63
var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
64
64
var code = exercisebox.value;
66
var args = {"code": code, "exercise": filename, "action": "test"};
66
var args = {'code': code};
68
68
/* Send the form as multipart/form-data, since we are sending a whole lump
69
69
* of Python code, it should be treated like a file upload. */
90
90
/* Close the "view previous" area (force reload) */
91
91
close_previous(exerciseid);
93
ajax_call(callback, "tutorialservice", "", args, "POST",
94
"multipart/form-data");
93
attempts_path = "api/subjects/" + subject + "/+worksheets/" + worksheet
94
+ "/" + filename + '/+attempts/' + username;
95
ajax_call(callback, attempts_path, "", args, "PUT", "application/json");
97
98
/** User clicks "Save" button. Do an Ajax call to store it.
107
108
var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
108
109
var code = exercisebox.value;
110
var args = {"code": code, "exercise": filename, "action": "save"};
111
var args = {"text": code, "ivle.op": "save"};
112
113
/* Send the form as multipart/form-data, since we are sending a whole lump
113
114
* of Python code, it should be treated like a file upload. */
117
118
// XXX Maybe check to see if this worked?
118
119
set_saved_status(exerciseid, filename, "Saved");
120
ajax_call(callback, "tutorialservice", "", args, "POST",
121
"multipart/form-data");
122
call_path = 'api/subjects/' + subject + '/+worksheets/' + worksheet +
124
ajax_call(callback, call_path, "", args, "POST");
124
127
/** User clicks "Reset" button. Replace the contents of the user program text
471
474
var exercisediv = document.getElementById(exerciseid);
472
475
var divs = exercisediv.getElementsByTagName("div");
473
476
var attempthistory;
474
478
for (var i=0; i<divs.length; i++)
475
479
if (divs[i].getAttribute("class") == "attempthistory")
476
480
attempthistory = divs[i];
480
484
var openarea = attempthistory.getElementsByTagName("div")[0];
481
485
var dropdown = attempthistory.getElementsByTagName("select")[0];
482
486
var textarea = attempthistory.getElementsByTagName("textarea")[0];
487
/* Further handles on the paragraphs for showing/hiding */
488
var attemptslist = openarea.getElementsByTagName("p")[1];
489
var noattempts = openarea.getElementsByTagName("p")[2];
484
/* Activate the "open" state, and clear the dropdown box */
485
openbutton.setAttribute("style", "display: none");
486
openarea.setAttribute("style", "display: auto");
487
textarea.setAttribute("style", "display: none");
491
/* Clear the dropdown box */
488
492
dom_removechildren(dropdown);
489
493
var pleasewait = document.createElement("option");
490
494
pleasewait.appendChild(document.createTextNode("Retrieving past attempts..."));
491
495
dropdown.appendChild(pleasewait);
493
var args = {"exercise": filename, "action": "getattempts"};
495
497
/* Send the form as multipart/form-data, since we are sending a whole lump
496
498
* of Python code, it should be treated like a file upload. */
497
499
/* AJAX callback function */
527
529
opt.appendChild(document.createTextNode(" "));
528
530
var img = document.createElement("img");
529
531
img.setAttribute("src",
530
make_path("media/images/tutorial/tiny/complete.png"));
532
make_path("+media/ivle.webapp.tutorial/images/tiny/complete.png"));
531
533
img.setAttribute("alt", "Complete");
532
534
opt.appendChild(img);
534
536
dropdown.appendChild(opt);
539
/* Display the page elements */
540
openbutton.setAttribute("style", "display: none");
541
openarea.setAttribute("style", "display: auto");
542
textarea.setAttribute("style", "display: none");
543
attemptslist.setAttribute("style", "display: none");
544
noattempts.setAttribute("style", "display: none");
545
// NOTE: This must go after setting openarea to visible. For some
546
// reason, Firefox will not display these elements otherwise.
547
if (attempts.length > 0)
548
attemptslist.setAttribute("style", "display: auto");
550
noattempts.setAttribute("style", "display: auto");
537
ajax_call(callback, "tutorialservice", "", args, "GET");
552
attempts_path = "api/subjects/" + subject + "/+worksheets/" + worksheet
553
+ "/" + filename + '/+attempts/' + username;
554
ajax_call(callback, attempts_path, "", {}, "GET");
540
557
function close_previous(exerciseid)
565
582
var exercisediv = document.getElementById(exerciseid);
566
583
var divs = exercisediv.getElementsByTagName("div");
567
584
var attempthistory;
568
586
for (var i=0; i<divs.length; i++)
569
587
if (divs[i].getAttribute("class") == "attempthistory")
570
588
attempthistory = divs[i];
574
592
var textarea = attempthistory.getElementsByTagName("textarea")[0];
576
594
/* Get the "value" of the selected option */
595
if (dropdown.selectedIndex < 0)
596
// Nothing is selected. Fail silently (should not occur in practice).
577
598
var date = dropdown.options[dropdown.selectedIndex].getAttribute("value");
579
var args = {"exercise": filename, "action": "getattempt", "date": date};
581
600
/* Send the form as multipart/form-data, since we are sending a whole lump
582
601
* of Python code, it should be treated like a file upload. */
583
602
/* AJAX callback function */
605
624
textarea.appendChild(document.createTextNode(attempt));
606
625
textarea.setAttribute("style", "display: auto");
608
ajax_call(callback, "tutorialservice", "", args, "GET");
628
call_path = "api/subjects/" + subject + '/+worksheets/' + worksheet + '/'
629
+ filename + '/+attempts/' + username + '/' + date;
630
ajax_call(callback, call_path, "", {}, "GET");