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

« back to all changes in this revision

Viewing changes to www/media/common/util.js

  • Committer: mattgiuca
  • Date: 2008-07-15 09:18:02 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:877
pulldown_subj/__init__.py: Added "enrol_user" function which pulls down a user
    and also enrols them in the database.
Added script enrolallusers.py which scriptulously performs automatic
enrolments of all users in the system, similar to remakeallusers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
620
620
    return str.join('');
621
621
}
622
622
 
623
 
/** Makes an XMLHttpRequest call to the server.
 
623
/** Makes an asynchronous XMLHttpRequest call to the server.
624
624
 * Sends the XMLHttpRequest object containing the completed response to a
625
625
 * specified callback function.
626
626
 *
627
627
 * \param callback A callback function. Will be called when the response is
628
628
 *      complete. Passed 1 parameter, an XMLHttpRequest object containing the
629
 
 *      completed response. If callback is null this is a syncronous request 
630
 
 *      otherwise this is an asynchronous request.
 
629
 *      completed response.
631
630
 * \param app IVLE app to call (such as "fileservice").
632
631
 * \param path URL path to make the request to, within the application.
633
632
 * \param args Argument object, as described in parse_url and friends.
647
646
     * used within this function) */
648
647
    var boundary = random_string(20);
649
648
    var xhr = new_xmlhttprequest();
650
 
    var asyncronous = callback != null;
651
 
    if (asyncronous)
652
 
    {
653
 
        xhr.onreadystatechange = function()
 
649
    xhr.onreadystatechange = function()
 
650
        {
 
651
            if (xhr.readyState == 4)
654
652
            {
655
 
                if (xhr.readyState == 4)
656
 
                {
657
 
                    callback(xhr);
658
 
                }
 
653
                callback(xhr);
659
654
            }
660
 
    }
 
655
        }
661
656
    if (method == "GET")
662
657
    {
663
658
        /* GET sends the args in the URL */
664
659
        url = build_url({"path": path, "args": args});
665
660
        /* open's 3rd argument = true -> asynchronous */
666
 
        xhr.open(method, url, asyncronous);
 
661
        xhr.open(method, url, true);
667
662
        xhr.send(null);
668
663
    }
669
664
    else
670
665
    {
671
666
        /* POST sends the args in application/x-www-form-urlencoded */
672
667
        url = encodeURI(path);
673
 
        xhr.open(method, url, asyncronous);
 
668
        xhr.open(method, url, true);
674
669
        var message;
675
670
        if (content_type == "multipart/form-data")
676
671
        {
685
680
        }
686
681
        xhr.send(message);
687
682
    }
688
 
    /* Only return the XHR for syncronous requests */
689
 
    if (!asyncronous)
690
 
    { 
691
 
        return xhr;
692
 
    }
693
683
}
694
684
 
695
 
/** Attempts to JSON decodes a response object
696
 
 * If a non-200 response or the JSON decode fails then returns null
697
 
 */
698
 
function decode_response(response)
699
 
{
700
 
    if (response.status == 200)
701
 
    {
702
 
        try
703
 
        {
704
 
            var responseText = response.responseText;
705
 
            return JSON.parse(responseText);
706
 
        }
707
 
        catch (e)
708
 
        {
709
 
            // Pass
710
 
        }
711
 
     }
712
 
    
713
 
     return null;
714
 
}