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

« back to all changes in this revision

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

  • Committer: stevenbird
  • Date: 2008-02-19 23:12:46 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:515
Propagated "problem" -> "exercise" nomenclature change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
/** User clicks "Run" button. Do an Ajax call and print the test output.
31
31
 */
32
 
function runproblem(problemid, filename)
 
32
function runexercise(exerciseid, filename)
33
33
{
34
34
    /* Get the source code the student is submitting */
35
 
    var problemdiv = document.getElementById(problemid);
36
 
    var problembox = problemdiv.getElementsByTagName("textarea")[0];
37
 
    var code = problembox.value;
 
35
    var exercisediv = document.getElementById(problemid);
 
36
    var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
 
37
    var code = exercisebox.value;
38
38
 
39
39
    /* Dump the entire file to the console */
40
40
    console_enter_line(code, "block");
42
42
}
43
43
 
44
44
/** Given a response object (JSON-parsed object), displays the result of the
45
 
 * test to the user. This modifies the given problemdiv's children.
 
45
 * test to the user. This modifies the given exercisediv's children.
46
46
 */
47
 
function handle_runresponse(problemdiv, runresponse)
 
47
function handle_runresponse(exercisediv, runresponse)
48
48
{
49
 
    var runoutput = problemdiv.getElementsByTagName("textarea")[1];
 
49
    var runoutput = exercisediv.getElementsByTagName("textarea")[1];
50
50
    dom_removechildren(runoutput);
51
51
    runoutput.appendChild(document.createTextNode(runresponse.stdout));
52
52
}
53
53
 
54
54
/** User clicks "Submit" button. Do an Ajax call and run the test.
55
 
 * problemid: "id" of the problem's div element.
56
 
 * filename: Filename of the problem's XML file (used to identify the problem
 
55
 * exerciseid: "id" of the exercise's div element.
 
56
 * filename: Filename of the exercise's XML file (used to identify the exercise
57
57
 *     when interacting with the server).
58
58
 */
59
 
function submitproblem(problemid, filename)
 
59
function submitexercise(exerciseid, filename)
60
60
{
61
61
    /* Get the source code the student is submitting */
62
 
    var problemdiv = document.getElementById(problemid);
63
 
    var problembox = problemdiv.getElementsByTagName("textarea")[0];
64
 
    var code = problembox.value;
 
62
    var exercisediv = document.getElementById(exerciseid);
 
63
    var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
 
64
    var code = exercisebox.value;
65
65
 
66
 
    var args = {"code": code, "problem": filename, "action": "test"};
 
66
    var args = {"code": code, "exercise": filename, "action": "test"};
67
67
 
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. */
70
70
    var xhr = ajax_call("tutorialservice", "", args, "POST",
71
71
        "multipart/form-data");
72
72
    var testresponse = JSON.parse(xhr.responseText);
73
 
    handle_testresponse(problemdiv, testresponse);
 
73
    handle_testresponse(exercisediv, testresponse);
74
74
}
75
75
 
76
 
/** Given a problem div, return the testoutput div which is its child.
 
76
/** Given a exercise div, return the testoutput div which is its child.
77
77
 * (The div which is its child whose class is "testoutput".
78
78
 */
79
 
function get_testoutput(problemdiv)
 
79
function get_testoutput(exercisediv)
80
80
{
81
 
    var childs = problemdiv.childNodes;
 
81
    var childs = exercisediv.childNodes;
82
82
    var i;
83
83
    var testoutput;
84
84
    for (i=0; i<childs.length; i++)
85
 
        if (childs[i].nodeType == problemdiv.ELEMENT_NODE &&
 
85
        if (childs[i].nodeType == exercisediv.ELEMENT_NODE &&
86
86
            childs[i].getAttribute("class") == "testoutput")
87
87
            return childs[i];
88
88
    return null;
89
89
}
90
90
 
91
91
/** Given a response object (JSON-parsed object), displays the result of the
92
 
 * test to the user. This modifies the given problemdiv's children.
 
92
 * test to the user. This modifies the given exercisediv's children.
93
93
 */
94
 
function handle_testresponse(problemdiv, testresponse)
 
94
function handle_testresponse(exercisediv, testresponse)
95
95
{
96
 
    var testoutput = get_testoutput(problemdiv);
 
96
    var testoutput = get_testoutput(exercisediv);
97
97
    var i, j;
98
98
    var ul;
99
99
    var case_ul;