89
89
function saveexercise(exerciseid, filename)
91
set_saved_status(exerciseid, filename, "Saving...");
91
92
/* Get the source code the student is submitting */
92
93
var exercisediv = document.getElementById(exerciseid);
93
94
var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
101
102
var callback = function(xhr)
103
104
// XXX Maybe check to see if this worked?
105
set_saved_status(exerciseid, filename, "Saved");
105
107
ajax_call(callback, "tutorialservice", "", args, "POST",
106
108
"multipart/form-data");
111
/* savetimers is a dict mapping exerciseIDs to timer IDs.
112
* Its members indicate all exercises that have been modified but not saved.
116
/** Changes whether an exercise is considered "saved" or not.
117
* stat is a string which specifies the status, and also the button text.
118
* If stat == "Save", then it indicates it is NOT saved. This will
119
* enable the "Save" button, and set a timer going which will auto-save
120
* after a set period of time (eg. 30 seconds).
121
* Any other value will disable the "Save" button and disable the timer.
122
* stat should be "Saving..." when the save request is issued, and "Saved"
123
* when the response comes back.
125
function set_saved_status(exerciseid, filename, stat)
127
var timername = "savetimer_" + exerciseid;
128
var button = document.getElementById("savebutton_" + exerciseid);
129
var is_saved = stat != "Save";
132
/* Disable the timer, if it exists */
133
if (typeof(savetimers[timername]) != "undefined")
135
clearTimeout(savetimers[timername]);
136
savetimers[timername] = undefined;
141
/* Disable the button */
142
button.disabled = true;
146
/* Enable the button */
147
button.disabled = false;
148
/* Create a timer which will auto-save when it expires */
149
var save_string = "saveexercise(" + repr(exerciseid) + ", "
150
+ repr(filename) + ")"
151
savetimers[timername] = setTimeout(save_string, 10000);
109
155
/** Given a exercise div, return the testoutput div which is its child.
110
156
* (The div which is its child whose class is "testoutput".