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

« back to all changes in this revision

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

  • Committer: wagrant
  • Date: 2008-07-21 00:03:16 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:914
remakeuser.py: Destroy!
remakeallusers.py: Rename to remakeuser.py. It now takes a username to
      rebuild, or -a to rebuild everyone.

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 = {
63
 
    "unversioned": "unversioned.png",
64
 
    "ignored": null,                    /* Supposed to be innocuous */
 
63
    "unversioned": null,
65
64
    "normal": "normal.png",
66
65
    "added": "added.png",
67
66
    "missing": "missing.png",
68
67
    "deleted": "deleted.png",
69
 
    "replaced": "replaced.png",
70
68
    "modified": "modified.png",
71
 
    "conflicted": "conflicted.png",
72
69
    "revision": "revision.png"
73
70
};
74
71
 
75
72
/* Mapping SVN status to "nice" strings */
76
73
svn_nice = {
77
74
    "unversioned": "Temporary file",
78
 
    "ignored": "Temporary file (ignored)",
79
75
    "normal": "Permanent file",
80
76
    "added": "Temporary file (scheduled to be added)",
81
77
    "missing": "Permanent file (missing)",
90
86
default_svn_icon = null;
91
87
default_svn_nice = "Unknown status";
92
88
 
93
 
svn_icons_path = "+media/ivle.webapp.core/images/svn";
 
89
svn_icons_path = "media/images/svn";
94
90
 
95
 
published_icon = "+media/ivle.webapp.core/images/interface/published.png";
 
91
published_icon = "media/images/interface/published.png";
96
92
 
97
93
/* List of MIME types considered "executable" by the system.
98
94
 * Executable files offer a "run" link, implying that the "serve"
137
133
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
138
134
 *      Defaults to "application/x-www-form-urlencoded".
139
135
 *      "multipart/form-data" is recommended for large uploads.
140
 
 * \param callback, optional.
141
 
 *      A callback function for after the action has been handled.
142
136
 */
143
 
function do_action(action, path, args, content_type, callback)
 
137
function do_action(action, path, args, content_type, ignore_response)
144
138
{
145
139
    args.action = action;
146
140
    /* Callback action, when the server returns */
147
 
    var callback_inner = function(response)
 
141
    var callback = function(response)
148
142
        {
149
143
            /* Check for action errors reported by the server, and report them
150
144
             * to the user */
151
145
            var error = response.getResponseHeader("X-IVLE-Action-Error");
152
 
            if (error != null && error != "")
 
146
            if (error != null)
153
147
                /* Note: This header (in particular) comes URI-encoded, to
154
148
                 * allow multi-line error messages. Decode */
155
149
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
156
150
            /* Now read the response and set up the page accordingly */
157
 
            if (callback != null)
158
 
                callback(path, response);
 
151
            if (ignore_response != true)
 
152
                handle_response(path, response, true);
159
153
        }
160
154
    /* Call the server and perform the action. This mutates the server. */
161
 
    ajax_call(callback_inner, service_app, path, args, "POST", content_type);
 
155
    ajax_call(callback, service_app, path, args, "POST", content_type);
162
156
}
163
157
 
164
158
/** Calls the server using Ajax, requesting a directory listing. This should
246
240
        return;
247
241
    }
248
242
 
249
 
    var subjects = null;
250
 
    /* Remove trailing slash (or path==username won't compare properly) */
251
 
    if (path[path.length-1] == "/")
252
 
        path = path.substr(0, path.length-1);
253
 
    var top_level_dir = path==username;
254
 
    if (top_level_dir)
255
 
    {
256
 
        var req = ajax_call(null, "userservice", "get_enrolments", null, "GET")
257
 
        subjects = decode_response(req);
258
 
    }
259
 
 
260
 
 
261
243
    /* This will always return a listing, whether it is a dir or a file.
262
244
     */
263
245
    var listing = response.responseText;
315
297
    var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
316
298
    if (isdir)
317
299
    {
318
 
        setup_for_listing();
319
 
        if (top_level_dir)
320
 
        {
321
 
            /* Top-level dir, with subjects */
322
 
            special_home_listing(listing, subjects, path);
323
 
        }
324
 
        else
325
 
        {
326
 
            /* Not the top-level dir. Do a normal dir listing. */
327
 
            handle_dir_listing(path, listing.listing);
328
 
        }
 
300
        handle_dir_listing(path, listing);
329
301
    }
330
302
    else
331
303
    {
394
366
    upload_callback_count++;
395
367
    if (upload_callback_count >= 2)
396
368
    {
397
 
        myFrame = frames['upload_iframe'].document;
398
 
        /* Browsers will turn the raw returned JSON into an HTML document. We
399
 
         * need to get the <pre> from inside the <body>, and look at its text.
400
 
         */
401
 
        data = myFrame.firstChild.getElementsByTagName(
402
 
            'body')[0].firstChild.firstChild.nodeValue;
403
 
        data = JSON.parse(data);
404
 
        if ('Error' in data)
405
 
            alert("Error: " + decodeURIComponent(data['Error']));
406
369
        document.getElementsByName('data')[0].value = '';
407
370
        refresh();
408
371
    }
425
388
function maybe_save(warning)
426
389
{
427
390
    if (warning == null) warning = '';
428
 
    if (current_file == null || current_file.isdir) return true;
 
391
    if (current_file.isdir) return true;
429
392
    if (document.getElementById("save_button").disabled) return true;
430
393
    return confirm("This file has unsaved changes. " + warning +
431
394
                   "\nAre you sure you wish to continue?");
528
491
        return default_svn_nice;
529
492
}
530
493
 
531
 
/** Returns true if a file is versioned (not unversioned or ignored).
532
 
 */
533
 
function svnstatus_versioned(svnstatus)
534
 
{
535
 
    return svnstatus != "unversioned" && svnstatus != "ignored";
536
 
}
537
 
 
538
494
/** Displays a download link to the binary file.
539
495
 */
540
496
function handle_binary(path)
543
499
    var div = document.createElement("div");
544
500
    files.appendChild(div);
545
501
    div.setAttribute("class", "padding");
546
 
    var download_link = app_url(download_app, path);
 
502
    var download_link = app_path(download_app, path);
547
503
    var par1 = dom_make_text_elem("p",
548
504
        "The file " + path + " is a binary file. To download this file, " +
549
505
        "click the following link:");
578
534
    }
579
535
}
580
536
 
581
 
/* Updates the list of available actions based on files selected */
582
537
function update_actions()
583
538
{
584
539
    var file;
585
540
    var numsel = selected_files.length;
586
 
    var svn_selection = false;
587
 
    
588
 
    if (numsel > 0)
589
 
    {
590
 
        svn_selection = true;
591
 
        for (var i = 0; i < selected_files.length; i++){
592
 
            if (!svnstatus_versioned(file_listing[selected_files[i]].svnstatus))
593
 
            {
594
 
                svn_selection = false;
595
 
            }
596
 
        }
597
 
    }
598
 
    
599
541
    if (numsel <= 1)
600
542
    {
601
543
        if (numsel == 0)
648
590
              "return maybe_save('The last saved version will be served.')");
649
591
        if (numsel == 0)
650
592
            serve.setAttribute("href",
651
 
                app_url(serve_app, current_path));
 
593
                app_path(serve_app, current_path));
652
594
        else
653
595
            serve.setAttribute("href",
654
 
                app_url(serve_app, current_path, filename));
 
596
                app_path(serve_app, current_path, filename));
655
597
    }
656
598
    else
657
599
    {
666
608
     */
667
609
    var run = document.getElementById("act_run");
668
610
     
669
 
    if (numsel <= 1 && !file.isdir && file.type == "text/x-python" 
670
 
            && current_file.svnstatus != 'revision')
 
611
    if (!file.isdir && file.type == "text/x-python" && numsel <= 1
 
612
        && current_file.svnstatus != 'revision')
671
613
    {
672
614
        if (numsel == 0)
673
615
        {
707
649
        if (numsel == 0)
708
650
        {
709
651
            download.setAttribute("href",
710
 
                app_url(download_app, current_path));
 
652
                app_path(download_app, current_path));
711
653
            if (file.isdir)
712
654
                download.setAttribute("title",
713
655
                    "Download the current directory as a ZIP file");
718
660
        else
719
661
        {
720
662
            download.setAttribute("href",
721
 
                app_url(download_app, current_path, filename));
 
663
                app_path(download_app, current_path, filename));
722
664
            if (file.isdir)
723
665
                download.setAttribute("title",
724
666
                    "Download the selected directory as a ZIP file");
730
672
    else
731
673
    {
732
674
        /* Make a query string with all the files to download */
733
 
        var dlpath = app_url(download_app, current_path) + "?";
 
675
        var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
734
676
        for (var i=0; i<numsel; i++)
735
677
            dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
736
678
        dlpath = dlpath.substr(0, dlpath.length-1);
750
692
    var pubcond = numsel <= 1 && file.isdir;
751
693
    if (pubcond)
752
694
    {
 
695
        /* TODO: Work out of file is svn'd */
753
696
        /* If this dir is already published, call it "Unpublish" */
754
697
        if (file.published)
755
698
        {
756
699
            publish.setAttribute("value", "unpublish");
757
700
            publish.setAttribute("title" ,"Make it so this directory "
758
701
                + "can not be seen by anyone on the web");
759
 
            publish.firstChild.nodeValue = "Unpublish";
 
702
            publish.textContent = "Unpublish";
760
703
        } else {
761
704
            publish.setAttribute("value", "publish");
762
705
            publish.setAttribute("title","Make it so this directory "
763
706
                + "can be seen by anyone on the web");
764
 
            publish.firstChild.nodeValue = "Publish";
 
707
            publish.textContent = "Publish";
765
708
        }
766
709
    }
767
710
    set_action_state(["publish", "submit"], pubcond);
788
731
    /* Subversion actions */
789
732
    /* These are only useful if we are in a versioned directory and have some
790
733
     * files selected. */
791
 
    set_action_state(["svnadd"], numsel >= 1 && current_file.svnstatus);
792
 
    /* And these are only useful is ALL the selected files are versioned */
793
 
    set_action_state(["svnremove", "svnrevert", "svncopy", "svncut"],
794
 
            numsel >= 1 && current_file.svnstatus && svn_selection);
795
 
    /* Commit is useful if ALL selected files are versioned, or the current
796
 
     * directory is versioned */
797
 
    set_action_state(["svncommit"], current_file.svnstatus &&
798
 
            (numsel >= 1 && svn_selection || numsel == 0));
 
734
    set_action_state(["svnadd", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
799
735
 
800
 
    /* Diff, log and update only support one path at the moment, so we must
801
 
     * have 0 or 1 versioned files selected. If 0, the directory must be
802
 
     * versioned. */
 
736
    /* Diff and log only support one path at the moment, so we must have 0 or 1
 
737
     * versioned files selected. If 0, the directory must be versioned. */
803
738
    single_versioned_path = (
804
739
         (
805
740
          (numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
741
          (numsel == 0 && (svnst = current_file.svnstatus))
807
 
         ) && svnstatus_versioned(svnst));
808
 
    set_action_state(["svndiff", "svnupdate"], single_versioned_path);
809
 
 
810
 
    /* We can resolve if we have a file selected and it is conflicted. */
811
 
    set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
 
742
         ) && svnst != "unversioned");
 
743
    set_action_state("svndiff", single_versioned_path);
812
744
 
813
745
    /* Log should be available for revisions as well. */
814
746
    set_action_state("svnlog", single_versioned_path, true);
815
747
 
816
 
    /* Cleanup should be available for revisions as well. */
817
 
    set_action_state("svncleanup", single_versioned_path, true);
818
 
 
819
 
    single_ivle_versioned_path = (
820
 
         (
821
 
          (numsel == 1 && (stat = file_listing[selected_files[0]])) ||
822
 
          (numsel == 0 && (stat = current_file))
823
 
         ) && svnstatus_versioned(stat.svnstatus)
824
 
           && stat.svnurl
825
 
           && stat.svnurl.substr(0, svn_base.length) == svn_base);
826
 
    set_action_state(["submit"], single_ivle_versioned_path);
 
748
    /* current_path == username: We are at the top level */
 
749
    set_action_state("svncheckout", current_path == username);
827
750
 
828
751
    /* There is currently nothing on the More Actions menu of use
829
752
     * when the current file is not a directory. Hence, just remove
879
802
        action_unpublish(selected_files);
880
803
        break;
881
804
    case "share":
882
 
        window.open(public_app_url("~" + current_path, filename), 'share')
 
805
        //alert("Not yet implemented: Sharing files");
 
806
        window.open(public_app_path(serve_app, current_path, filename), 'share')
883
807
        break;
884
808
    case "submit":
885
 
        if (selected_files.length == 1)
886
 
            stat = file_listing[selected_files[0]];
887
 
        else
888
 
            stat = current_file;
889
 
        url = stat.svnurl.substr(svn_base.length);      // URL-encoded
890
 
        path = decodeURIComponent(url);
891
 
 
892
 
        /* The working copy might not have an up-to-date version of the
893
 
         * directory. While submitting like this could yield unexpected
894
 
         * results, we should really submit the latest revision to minimise
895
 
         * terrible mistakes - so we run off and ask fileservice for the
896
 
         * latest revision.*/
897
 
        $.post(app_path(service_app, current_path),
898
 
            {"action": "svnrepostat", "path": path},
899
 
            function(result)
900
 
            {
901
 
                window.location = path_join(app_path('+submit'), url) + '?revision=' + result.svnrevision;
902
 
            },
903
 
            "json");
904
 
 
 
809
        // TODO
 
810
        alert("Not yet implemented: Submit");
905
811
        break;
906
812
    case "rename":
907
813
        action_rename(filename);
908
814
        break;
909
815
    case "delete":
910
 
        action_delete(selected_files);
 
816
        action_remove(selected_files);
911
817
        break;
912
818
    case "copy":
913
819
        action_copy(selected_files);
930
836
    case "svnadd":
931
837
        action_add(selected_files);
932
838
        break;
933
 
    case "svnremove":
934
 
        action_remove(selected_files);
935
 
        break;
936
839
    case "svnrevert":
937
840
        action_revert(selected_files);
938
841
        break;
939
842
    case "svndiff":
940
 
        window.location = path_join(app_url('diff'), current_path, selected_files[0] || '');
941
 
        break;
942
 
    case "svnupdate":
943
 
        action_update(selected_files);
944
 
        break;
945
 
    case "svnresolved":
946
 
        action_resolved(selected_files);
 
843
        window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
947
844
        break;
948
845
    case "svncommit":
949
846
        action_commit(selected_files);
950
847
        break;
951
848
    case "svnlog":
952
 
        window.location = path_join(app_url('svnlog'), current_path, selected_files[0] || '');
953
 
        break;
954
 
    case "svncopy":
955
 
        action_svncopy(selected_files);
956
 
        break;
957
 
    case "svncut":
958
 
        action_svncut(selected_files);
959
 
        break;
960
 
    case "svncleanup":
961
 
        action_svncleanup(".");
 
849
        window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
 
850
        break;
 
851
    case "svncheckout":
 
852
        action_checkout();
962
853
        break;
963
854
    }
964
855
}
987
878
     * This causes the page to be populated with whatever is at that address,
988
879
     * whether it be a directory or a file.
989
880
     */
990
 
    var path = get_path();
991
 
    navigate(path);
992
 
}
993
 
 
994
 
/** Gets the current path of the window */
995
 
function get_path() {
996
881
    var path = parse_url(window.location.href).path;
997
882
    /* Strip out root_dir + "/files" from the front of the path */
998
883
    var strip = make_path(this_app);
1015
900
        path = username;
1016
901
    }
1017
902
 
1018
 
    return path;
 
903
    navigate(path);
1019
904
}