~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-15 12:25:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:707
tutorialservice: "submit" requests now return "completed" and "attempts"
    fields as well. They query the DB for the completed and attempt stats.
tutorial.js: Handling the submit response: Now updates the summary bar,
    setting the ball to green and "Complete" if successful, and also updating
    the number of attempts made dynamically.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    var callback = function(xhr)
78
78
        {
79
79
            var testresponse = JSON.parse(xhr.responseText);
80
 
            handle_testresponse(exercisediv, testresponse);
 
80
            handle_testresponse(exercisediv, exerciseid, testresponse);
81
81
            set_saved_status(exerciseid, filename, "Saved");
82
82
            set_submit_status(exerciseid, filename, "Submit");
83
83
        }
189
189
/** Given a response object (JSON-parsed object), displays the result of the
190
190
 * test to the user. This modifies the given exercisediv's children.
191
191
 */
192
 
function handle_testresponse(exercisediv, testresponse)
 
192
function handle_testresponse(exercisediv, exerciseid, testresponse)
193
193
{
194
194
    var testoutput = get_testoutput(exercisediv);
195
195
    var i, j;
255
255
            }
256
256
        }
257
257
    }
 
258
 
 
259
    /* Update the summary box (completed, attempts) with the new values we got
 
260
     * back from the tutorialservice.
 
261
     */
 
262
    var summaryli = document.getElementById("summaryli_" + exerciseid);
 
263
    var summarycomplete = document.getElementById("summarycomplete_"
 
264
        + exerciseid);
 
265
    var summaryattempts = document.getElementById("summaryattempts_"
 
266
        + exerciseid);
 
267
    summaryli.setAttribute("class",
 
268
        (testresponse.completed ? "complete" : "incomplete"));
 
269
    summarycomplete.removeChild(summarycomplete.lastChild);
 
270
    summarycomplete.appendChild(document.createTextNode(testresponse.completed
 
271
        ? "Complete" : "Incomplete"));
 
272
    var old_attempts_value = summaryattempts.lastChild.data;
 
273
    summaryattempts.removeChild(summaryattempts.lastChild);
 
274
    summaryattempts.appendChild(document.createTextNode(
 
275
        testresponse.attempts));
 
276
    if (testresponse.completed && testresponse.attempts == 1 &&
 
277
        old_attempts_value == "0")
 
278
    {
 
279
        /* Add "Well done" for extra congratulations */
 
280
        summaryli.appendChild(document.createTextNode(
 
281
            " Well done!"));
 
282
    }
258
283
}
259
284
 
260
285
/* DOM creators for test case response elements */