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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/media/tutorial.js

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* IVLE - Informatics Virtual Learning Environment
2
 
 * Copyright (C) 2007-2008 The University of Melbourne
 
2
 * Copyright (C) 2007-2009 The University of Melbourne
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
63
63
    var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
64
64
    var code = exercisebox.value;
65
65
 
66
 
    var args = {"code": code, "exercise": filename, "action": "test"};
 
66
    var args = {'code': code};
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. */
90
90
            /* Close the "view previous" area (force reload) */
91
91
            close_previous(exerciseid);
92
92
        }
93
 
    ajax_call(callback, "tutorialservice", "", args, "POST",
94
 
        "multipart/form-data");
 
93
    attempts_path = "api/subjects/" + subject + "/" + year + "/" + semester + 
 
94
        "/+worksheets/" + worksheet + "/" + filename + '/+attempts/' + username;
 
95
    ajax_call(callback, attempts_path, "", args, "PUT", "application/json");
95
96
}
96
97
 
97
98
/** User clicks "Save" button. Do an Ajax call to store it.
107
108
    var exercisebox = exercisediv.getElementsByTagName("textarea")[0];
108
109
    var code = exercisebox.value;
109
110
 
110
 
    var args = {"code": code, "exercise": filename, "action": "save"};
 
111
    var args = {"text": code, "ivle.op": "save"};
111
112
 
112
113
    /* Send the form as multipart/form-data, since we are sending a whole lump
113
114
     * of Python code, it should be treated like a file upload. */
117
118
            // XXX Maybe check to see if this worked?
118
119
            set_saved_status(exerciseid, filename, "Saved");
119
120
        }
120
 
    ajax_call(callback, "tutorialservice", "", args, "POST",
121
 
        "multipart/form-data");
 
121
        
 
122
    call_path = 'api/subjects/' + subject + "/" + year + "/" + semester + 
 
123
                                '/+worksheets/' + worksheet + '/' + filename;
 
124
    ajax_call(callback, call_path, "", args, "POST");
122
125
}
123
126
 
124
127
/** User clicks "Reset" button. Replace the contents of the user program text
141
144
    var resettextbox = document.getElementById("input_resettext_" + exerciseid);
142
145
    var text_urlencoded = resettextbox.value;
143
146
    /* Need to un-urlencode the value */
144
 
    exercisebox.value = decodeURIComponent(text_urlencoded);
 
147
    exercisebox.value = text_urlencoded;//decodeURIComponent(text_urlencoded);
145
148
    /* We changed the text, so make Save button available, and autosave after
146
149
     * 10 seconds. */
147
150
    set_saved_status(exerciseid, filename, "Save");
471
474
    var exercisediv = document.getElementById(exerciseid);
472
475
    var divs = exercisediv.getElementsByTagName("div");
473
476
    var attempthistory;
 
477
    var attempts_path;
474
478
    for (var i=0; i<divs.length; i++)
475
479
        if (divs[i].getAttribute("class") == "attempthistory")
476
480
            attempthistory = divs[i];
480
484
    var openarea = attempthistory.getElementsByTagName("div")[0];
481
485
    var dropdown = attempthistory.getElementsByTagName("select")[0];
482
486
    var textarea = attempthistory.getElementsByTagName("textarea")[0];
 
487
    /* Further handles on the paragraphs for showing/hiding */
 
488
    var attemptslist = openarea.getElementsByTagName("p")[1];
 
489
    var noattempts = openarea.getElementsByTagName("p")[2];
483
490
 
484
 
    /* Activate the "open" state, and clear the dropdown box */
485
 
    openbutton.setAttribute("style", "display: none");
486
 
    openarea.setAttribute("style", "display: auto");
487
 
    textarea.setAttribute("style", "display: none");
 
491
    /* Clear the dropdown box */
488
492
    dom_removechildren(dropdown);
489
493
    var pleasewait = document.createElement("option");
490
494
    pleasewait.appendChild(document.createTextNode("Retrieving past attempts..."));
491
495
    dropdown.appendChild(pleasewait);
492
496
 
493
 
    var args = {"exercise": filename, "action": "getattempts"};
494
 
 
495
497
    /* Send the form as multipart/form-data, since we are sending a whole lump
496
498
     * of Python code, it should be treated like a file upload. */
497
499
    /* AJAX callback function */
527
529
                    opt.appendChild(document.createTextNode(" "));
528
530
                    var img = document.createElement("img");
529
531
                    img.setAttribute("src",
530
 
                        make_path("media/images/tutorial/tiny/complete.png"));
 
532
                        make_path("+media/ivle.webapp.tutorial/images/tiny/complete.png"));
531
533
                    img.setAttribute("alt", "Complete");
532
534
                    opt.appendChild(img);
533
535
                }
534
536
                dropdown.appendChild(opt);
535
537
            }
 
538
 
 
539
            /* Display the page elements */
 
540
            openbutton.setAttribute("style", "display: none");
 
541
            openarea.setAttribute("style", "display: auto");
 
542
            textarea.setAttribute("style", "display: none");
 
543
            attemptslist.setAttribute("style", "display: none");
 
544
            noattempts.setAttribute("style", "display: none");
 
545
            // NOTE: This must go after setting openarea to visible. For some
 
546
            // reason, Firefox will not display these elements otherwise.
 
547
            if (attempts.length > 0)
 
548
                attemptslist.setAttribute("style", "display: auto");
 
549
            else
 
550
                noattempts.setAttribute("style", "display: auto");
536
551
        }
537
 
    ajax_call(callback, "tutorialservice", "", args, "GET");
 
552
    attempts_path = "api/subjects/" + subject + "/" + year + "/" + semester + 
 
553
        "/+worksheets/" + worksheet + "/" + filename + '/+attempts/' + username;
 
554
    ajax_call(callback, attempts_path, "", {}, "GET");
538
555
}
539
556
 
540
557
function close_previous(exerciseid)
565
582
    var exercisediv = document.getElementById(exerciseid);
566
583
    var divs = exercisediv.getElementsByTagName("div");
567
584
    var attempthistory;
 
585
    var call_path
568
586
    for (var i=0; i<divs.length; i++)
569
587
        if (divs[i].getAttribute("class") == "attempthistory")
570
588
            attempthistory = divs[i];
574
592
    var textarea = attempthistory.getElementsByTagName("textarea")[0];
575
593
 
576
594
    /* Get the "value" of the selected option */
 
595
    if (dropdown.selectedIndex < 0)
 
596
        // Nothing is selected. Fail silently (should not occur in practice).
 
597
        return;
577
598
    var date = dropdown.options[dropdown.selectedIndex].getAttribute("value");
578
599
 
579
 
    var args = {"exercise": filename, "action": "getattempt", "date": date};
580
 
 
581
600
    /* Send the form as multipart/form-data, since we are sending a whole lump
582
601
     * of Python code, it should be treated like a file upload. */
583
602
    /* AJAX callback function */
605
624
            textarea.appendChild(document.createTextNode(attempt));
606
625
            textarea.setAttribute("style", "display: auto");
607
626
        }
608
 
    ajax_call(callback, "tutorialservice", "", args, "GET");
 
627
        
 
628
    call_path = "api/subjects/" + subject + "/" + year + "/" + semester + 
 
629
            '/+worksheets/' + worksheet + '/' + filename + '/+attempts/' 
 
630
            + username + '/' + date;
 
631
    ajax_call(callback, call_path, "", {}, "GET");
609
632
}