~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-03-28 08:02:51 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:719
tutorial.js: If the result returned from Submit is a JSON parse error,
    catches the error, reports it ("an unexplained error"), and sets the
    buttons back nicely so at least you can try again.
    (ie. It no longer breaks the client side).

    This stops once and for all the "Submit hangs forever" bug - UNLESS of
    course Submit is actually hanging forever.
    (Infinite loop -> Infinite loop, Error -> Error).

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 */
63
63
function submitexercise(exerciseid, filename)
64
64
{
 
65
    var original_saved_status = get_saved_status(exerciseid);
65
66
    set_submit_status(exerciseid, filename, "Submitting...");
66
67
    set_saved_status(exerciseid, filename, "Saving...");
67
68
    /* Get the source code the student is submitting */
76
77
    /* AJAX callback function */
77
78
    var callback = function(xhr)
78
79
        {
79
 
            var testresponse = JSON.parse(xhr.responseText);
 
80
            var testresponse;
 
81
            try
 
82
            {
 
83
                testresponse = JSON.parse(xhr.responseText);
 
84
            }
 
85
            catch (ex)
 
86
            {
 
87
                alert("There was an error submitting or running your code. "
 
88
                    + "Please notify the administrators of this.");
 
89
                /* Since it failed, set the Save button back how it was. */
 
90
                set_saved_status(exerciseid, filename, original_saved_status);
 
91
                set_submit_status(exerciseid, filename, "Submit");
 
92
                return;
 
93
            }
80
94
            handle_testresponse(exercisediv, exerciseid, testresponse);
81
95
            set_saved_status(exerciseid, filename, "Saved");
82
96
            set_submit_status(exerciseid, filename, "Submit");
182
196
    }
183
197
}
184
198
 
 
199
/** Retrieves the saved status of a given exercise.
 
200
 * Returns "Save" if the exercise is modified and needs to be saved.
 
201
 * Returns "Saved" if the exercise has been saved and is unmodified.
 
202
 * Returns "Saving..." if the exercise is in the process of being saved
 
203
 *  (an ajax request is on its way).
 
204
 */
 
205
function get_saved_status(exerciseid)
 
206
{
 
207
    var button = document.getElementById("savebutton_" + exerciseid);
 
208
    return button.value;
 
209
}
 
210
 
185
211
/** Changes the state of the submit button, so it can appear disabled during
186
212
 * the submission process (to avoid multiple clicks).
187
213
 * stat is a string which specifies the status, and also the button text.