~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/tutorial/tutorial.js

  • Committer: mattgiuca
  • Date: 2008-01-29 05:42:01 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:325
tutorial: Added "run" button which submits the students code to the
tutorialservice for "unofficial" testing.
Currently tutorialservice:run just echoes the code back to the student.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Date: 25/1/2008
21
21
 */
22
22
 
 
23
/** User clicks "Run" button. Do an Ajax call and print the test output.
 
24
 */
 
25
function runproblem(problemid, filename)
 
26
{
 
27
    /* Get the source code the student is submitting */
 
28
    var problemdiv = document.getElementById(problemid);
 
29
    var problembox = problemdiv.getElementsByTagName("textarea")[0];
 
30
    var code = problembox.value;
 
31
 
 
32
    var args = {"code": code, "problem": filename, "action": "run"};
 
33
 
 
34
    /* Send the form as multipart/form-data, since we are sending a whole lump
 
35
     * of Python code, it should be treated like a file upload. */
 
36
    var xhr = ajax_call("tutorialservice", "", args, "POST",
 
37
        "multipart/form-data");
 
38
    var testresponse = JSON.parse(xhr.responseText);
 
39
    handle_runresponse(problemdiv, testresponse);
 
40
}
 
41
 
 
42
/** Given a response object (JSON-parsed object), displays the result of the
 
43
 * test to the user. This modifies the given problemdiv's children.
 
44
 */
 
45
function handle_runresponse(problemdiv, runresponse)
 
46
{
 
47
    var runoutput = problemdiv.getElementsByTagName("textarea")[1];
 
48
    dom_removechildren(runoutput);
 
49
    runoutput.appendChild(document.createTextNode(runresponse.stdout));
 
50
}
 
51
 
23
52
/** User clicks "Submit" button. Do an Ajax call and run the test.
24
53
 * problemid: "id" of the problem's div element.
25
54
 * filename: Filename of the problem's XML file (used to identify the problem