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

« back to all changes in this revision

Viewing changes to www/media/browser/browser.js

  • Committer: mattgiuca
  • Date: 2008-07-21 09:09:07 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:923
users.sql: Added groups_student_permissions column to offering table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
default_type_icon = "txt.png";
56
56
 
57
57
/* Relative to IVLE root */
58
 
type_icons_path = "+media/ivle.webapp.core/images/mime";
59
 
type_icons_path_large = "+media/ivle.webapp.core/images/mime/large";
 
58
type_icons_path = "media/images/mime";
 
59
type_icons_path_large = "media/images/mime/large";
60
60
 
61
61
/* Mapping SVN status to icons, just the file's basename */
62
62
svn_icons = {
87
87
default_svn_icon = null;
88
88
default_svn_nice = "Unknown status";
89
89
 
90
 
svn_icons_path = "+media/ivle.webapp.core/images/svn";
 
90
svn_icons_path = "media/images/svn";
91
91
 
92
 
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
 
92
published_icon = "media/images/interface/published.png";
93
93
 
94
94
/* List of MIME types considered "executable" by the system.
95
95
 * Executable files offer a "run" link, implying that the "serve"
134
134
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
135
135
 *      Defaults to "application/x-www-form-urlencoded".
136
136
 *      "multipart/form-data" is recommended for large uploads.
137
 
 * \param callback, optional.
138
 
 *      A callback function for after the action has been handled.
139
137
 */
140
 
function do_action(action, path, args, content_type, callback)
 
138
function do_action(action, path, args, content_type, ignore_response)
141
139
{
142
140
    args.action = action;
143
141
    /* Callback action, when the server returns */
144
 
    var callback_inner = function(response)
 
142
    var callback = function(response)
145
143
        {
146
144
            /* Check for action errors reported by the server, and report them
147
145
             * to the user */
148
146
            var error = response.getResponseHeader("X-IVLE-Action-Error");
149
 
            if (error != null && error != "")
 
147
            if (error != null)
150
148
                /* Note: This header (in particular) comes URI-encoded, to
151
149
                 * allow multi-line error messages. Decode */
152
150
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
153
151
            /* Now read the response and set up the page accordingly */
154
 
            if (callback != null)
155
 
                callback(path, response);
 
152
            if (ignore_response != true)
 
153
                handle_response(path, response, true);
156
154
        }
157
155
    /* Call the server and perform the action. This mutates the server. */
158
 
    ajax_call(callback_inner, service_app, path, args, "POST", content_type);
 
156
    ajax_call(callback, service_app, path, args, "POST", content_type);
159
157
}
160
158
 
161
159
/** Calls the server using Ajax, requesting a directory listing. This should
243
241
        return;
244
242
    }
245
243
 
246
 
    var subjects = null;
247
 
    var top_level_dir = path==username;
248
 
    if (top_level_dir)
249
 
    {
250
 
        var req = ajax_call(null, "userservice", "get_enrolments", null, "GET")
251
 
        subjects = decode_response(req);
252
 
    }
253
 
 
254
 
 
255
244
    /* This will always return a listing, whether it is a dir or a file.
256
245
     */
257
246
    var listing = response.responseText;
309
298
    var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
310
299
    if (isdir)
311
300
    {
312
 
        setup_for_listing();
313
 
        home_listing(listing, subjects, path);
 
301
        handle_dir_listing(path, listing);
314
302
    }
315
303
    else
316
304
    {
379
367
    upload_callback_count++;
380
368
    if (upload_callback_count >= 2)
381
369
    {
382
 
        myFrame = frames['upload_iframe'].document;
383
 
        /* Browsers will turn the raw returned JSON into an HTML document. We
384
 
         * need to get the <pre> from inside the <body>, and look at its text.
385
 
         */
386
 
        data = myFrame.firstChild.getElementsByTagName(
387
 
            'body')[0].firstChild.firstChild.nodeValue;
388
 
        data = JSON.parse(data);
389
 
        if ('Error' in data)
390
 
            alert("Error: " + decodeURIComponent(data['Error']));
391
370
        document.getElementsByName('data')[0].value = '';
392
371
        refresh();
393
372
    }
556
535
    }
557
536
}
558
537
 
559
 
/* Updates the list of available actions based on files selected */
560
538
function update_actions()
561
539
{
562
540
    var file;
563
541
    var numsel = selected_files.length;
564
 
    var svn_selection = false;
565
 
    
566
 
    if (numsel > 0)
567
 
    {
568
 
        svn_selection = true;
569
 
        for (var i = 0; i < selected_files.length; i++){
570
 
            if (file_listing[selected_files[i]]["svnstatus"] == "unversioned")
571
 
            {
572
 
                svn_selection = false;        
573
 
            }
574
 
        }
575
 
    }
576
 
    
577
542
    if (numsel <= 1)
578
543
    {
579
544
        if (numsel == 0)
644
609
     */
645
610
    var run = document.getElementById("act_run");
646
611
     
647
 
    if (numsel <= 1 && !file.isdir && file.type == "text/x-python" 
648
 
            && current_file.svnstatus != 'revision')
 
612
    if (!file.isdir && file.type == "text/x-python" && numsel <= 1
 
613
        && current_file.svnstatus != 'revision')
649
614
    {
650
615
        if (numsel == 0)
651
616
        {
728
693
    var pubcond = numsel <= 1 && file.isdir;
729
694
    if (pubcond)
730
695
    {
 
696
        /* TODO: Work out of file is svn'd */
731
697
        /* If this dir is already published, call it "Unpublish" */
732
698
        if (file.published)
733
699
        {
734
700
            publish.setAttribute("value", "unpublish");
735
701
            publish.setAttribute("title" ,"Make it so this directory "
736
702
                + "can not be seen by anyone on the web");
737
 
            publish.firstChild.nodeValue = "Unpublish";
 
703
            publish.textContent = "Unpublish";
738
704
        } else {
739
705
            publish.setAttribute("value", "publish");
740
706
            publish.setAttribute("title","Make it so this directory "
741
707
                + "can be seen by anyone on the web");
742
 
            publish.firstChild.nodeValue = "Publish";
 
708
            publish.textContent = "Publish";
743
709
        }
744
710
    }
745
711
    set_action_state(["publish", "submit"], pubcond);
766
732
    /* Subversion actions */
767
733
    /* These are only useful if we are in a versioned directory and have some
768
734
     * files selected. */
769
 
    set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
770
 
    /* And these are only usefull is ALL the selected files are versioned */
771
 
    set_action_state(["svnremove", "svnrevert", "svncommit", "svncopy", 
772
 
            "svncut"], numsel >= 1 && current_file.svnstatus && svn_selection);
773
 
    
 
735
    set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
 
736
 
774
737
    /* Diff, log and update only support one path at the moment, so we must
775
738
     * have 0 or 1 versioned files selected. If 0, the directory must be
776
739
     * versioned. */
787
750
    /* Log should be available for revisions as well. */
788
751
    set_action_state("svnlog", single_versioned_path, true);
789
752
 
790
 
    /* Cleanup should be available for revisions as well. */
791
 
    set_action_state("svncleanup", single_versioned_path, true);
792
 
 
793
 
    single_ivle_versioned_path = (
794
 
         (
795
 
          (numsel == 1 && (stat = file_listing[selected_files[0]])) ||
796
 
          (numsel == 0 && (stat = current_file))
797
 
         ) && stat.svnstatus != "unversioned"
798
 
           && stat.svnurl
799
 
           && stat.svnurl.substr(0, svn_base.length) == svn_base);
800
 
    set_action_state(["submit"], single_ivle_versioned_path);
 
753
    /* current_path == username: We are at the top level */
 
754
    set_action_state("svncheckout", current_path == username);
801
755
 
802
756
    /* There is currently nothing on the More Actions menu of use
803
757
     * when the current file is not a directory. Hence, just remove
853
807
        action_unpublish(selected_files);
854
808
        break;
855
809
    case "share":
856
 
        window.open(public_app_path("~" + current_path, filename), 'share')
 
810
        //alert("Not yet implemented: Sharing files");
 
811
        window.open(public_app_path(serve_app, current_path, filename), 'share')
857
812
        break;
858
813
    case "submit":
859
 
        if (selected_files.length == 1)
860
 
            stat = file_listing[selected_files[0]];
861
 
        else
862
 
            stat = current_file;
863
 
        path = stat.svnurl.substr(svn_base.length);
864
 
 
865
 
        /* The working copy might not have an up-to-date version of the
866
 
         * directory. While submitting like this could yield unexpected
867
 
         * results, we should really submit the latest revision to minimise
868
 
         * terrible mistakes - so we run off and ask fileservice for the
869
 
         * latest revision.*/
870
 
        $.post(app_path(service_app, current_path),
871
 
            {"action": "svnrepostat", "path": path},
872
 
            function(result)
873
 
            {
874
 
                window.location = path_join(app_path('+submit'), path) + '?revision=' + result.svnrevision;
875
 
            },
876
 
            "json");
877
 
 
 
814
        // TODO
 
815
        alert("Not yet implemented: Submit");
878
816
        break;
879
817
    case "rename":
880
818
        action_rename(filename);
924
862
    case "svnlog":
925
863
        window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
926
864
        break;
927
 
    case "svncopy":
928
 
        action_svncopy(selected_files);
929
 
        break;
930
 
    case "svncut":
931
 
        action_svncut(selected_files);
932
 
        break;
933
 
    case "svncleanup":
934
 
        action_svncleanup(".");
 
865
    case "svncheckout":
 
866
        action_checkout();
935
867
        break;
936
868
    }
937
869
}
960
892
     * This causes the page to be populated with whatever is at that address,
961
893
     * whether it be a directory or a file.
962
894
     */
963
 
    var path = get_path();
964
 
    navigate(path);
965
 
}
966
 
 
967
 
/** Gets the current path of the window */
968
 
function get_path() {
969
895
    var path = parse_url(window.location.href).path;
970
896
    /* Strip out root_dir + "/files" from the front of the path */
971
897
    var strip = make_path(this_app);
988
914
        path = username;
989
915
    }
990
916
 
991
 
    return path;
 
917
    navigate(path);
992
918
}