~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-12-23 04:48:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1065
Add some svn:ignores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    "missing": "missing.png",
67
67
    "deleted": "deleted.png",
68
68
    "modified": "modified.png",
 
69
    "conflicted": "conflicted.png",
69
70
    "revision": "revision.png"
70
71
};
71
72
 
104
105
/** The listing object returned by the server as JSON */
105
106
file_listing = null;
106
107
current_file = null;
 
108
current_revision = null;
107
109
current_path = "";
108
110
 
109
111
/** Filenames of all files selected
239
241
        return;
240
242
    }
241
243
 
 
244
    var subjects = null;
 
245
    var top_level_dir = path==username;
 
246
    if (top_level_dir)
 
247
    {
 
248
        var req = ajax_call(null, "userservice", "get_enrolments", null, "GET")
 
249
        subjects = decode_response(req);
 
250
    }
 
251
 
 
252
 
242
253
    /* This will always return a listing, whether it is a dir or a file.
243
254
     */
244
255
    var listing = response.responseText;
287
298
    current_file = file_listing["."];     /* Global */
288
299
    delete file_listing["."];
289
300
 
 
301
    if ('revision' in listing)
 
302
    {
 
303
        current_revision = listing.revision;
 
304
    }
 
305
 
290
306
    /* Check if this is a directory listing or file contents */
291
307
    var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
292
308
    if (isdir)
293
309
    {
294
 
        handle_dir_listing(path, listing);
 
310
        setup_for_listing();
 
311
        home_listing(listing, subjects, path);
295
312
    }
296
313
    else
297
314
    {
427
444
    files.appendChild(txt_elem);
428
445
}
429
446
 
 
447
/** Given a path, filename and optional revision, returns a URL to open that
 
448
 *  revision of that file.
 
449
 */
 
450
function build_revision_url(path, filename, revision)
 
451
{
 
452
    bits = {'path': app_path(this_app, path, filename)};
 
453
    if (current_revision)
 
454
    {
 
455
        bits['query_string'] = 'r=' + revision;
 
456
    }
 
457
    return build_url(bits);
 
458
}
 
459
 
430
460
/** Given a mime type, returns the path to the icon.
431
461
 * \param type String, Mime type.
432
462
 * \param sizelarge Boolean, optional.
492
522
 
493
523
/* Enable or disable actions1 moreactions actions. Takes either a single
494
524
 * name, or an array of them.*/
495
 
function set_action_state(names, which)
 
525
function set_action_state(names, which, allow_on_revision)
496
526
{
497
527
    if (!(names instanceof Array)) names = Array(names);
498
528
 
499
529
    for (var i=0; i < names.length; i++)
500
530
    {
501
531
        element = document.getElementById('act_' + names[i]);
502
 
        if (which)
 
532
        if (which &&
 
533
            !(current_file.svnstatus == 'revision' && !allow_on_revision))
503
534
        {
504
535
            /* Enabling */
505
536
            element.setAttribute("class", "choice");
549
580
        else
550
581
            open.setAttribute("title",
551
582
                "Edit or view this file");
552
 
        open.setAttribute("href", app_path(this_app, current_path, filename));
 
583
        open.setAttribute("href", build_revision_url(current_path, filename,
 
584
                                                     current_revision));
553
585
    }
554
586
    else
555
587
    {
562
594
    /* Available if zero or one files are selected,
563
595
     * and only if this is a file, not a directory */
564
596
    var serve = document.getElementById("act_serve");
565
 
    if (numsel <= 1 && !file.isdir)
 
597
    if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
566
598
    {
567
599
        serve.setAttribute("class", "choice");
568
600
        serve.setAttribute("onclick",
587
619
     */
588
620
    var run = document.getElementById("act_run");
589
621
     
590
 
    if (!file.isdir && file.type == "text/x-python" && numsel <= 1)
 
622
    if (!file.isdir && file.type == "text/x-python" && numsel <= 1
 
623
        && current_file.svnstatus != 'revision')
591
624
    {
592
625
        if (numsel == 0)
593
626
        {
609
642
    }
610
643
 
611
644
    /* Download */
612
 
    /* Always available.
 
645
    /* Always available for current files.
613
646
     * If 0 files selected, download the current file or directory as a ZIP.
614
647
     * If 1 directory selected, download it as a ZIP.
615
648
     * If 1 non-directory selected, download it.
616
649
     * If >1 files selected, download them all as a ZIP.
617
650
     */
618
651
    var download = document.getElementById("act_download");
619
 
    if (numsel <= 1)
620
 
    {
 
652
    if (current_file.svnstatus == 'revision')
 
653
    {
 
654
        download.setAttribute("class", "disabled");
 
655
        download.removeAttribute("onclick");
 
656
    }
 
657
    else if (numsel <= 1)
 
658
    {
 
659
        download.setAttribute("class", "choice")
621
660
        if (numsel == 0)
622
661
        {
623
662
            download.setAttribute("href",
648
687
        for (var i=0; i<numsel; i++)
649
688
            dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
650
689
        dlpath = dlpath.substr(0, dlpath.length-1);
 
690
        download.setAttribute("class", "choice")
651
691
        download.setAttribute("href", dlpath);
652
692
        download.setAttribute("title",
653
693
            "Download the selected files as a ZIP file");
702
742
    /* Subversion actions */
703
743
    /* These are only useful if we are in a versioned directory and have some
704
744
     * files selected. */
705
 
    set_action_state(["svnadd", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
706
 
 
707
 
    /* Diff and log only support one path at the moment. */
708
 
    single_versioned_path = (numsel == 1 &&
709
 
                             (svnst = file_listing[selected_files[0]].svnstatus) &&
710
 
                             svnst != "unversioned");
711
 
    set_action_state("svnlog", single_versioned_path);
712
 
    set_action_state("svndiff", single_versioned_path && svnst != "normal");
713
 
 
714
 
    /* current_path == username: We are at the top level */
715
 
    set_action_state("svncheckout", current_path == username);
 
745
    set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
 
746
 
 
747
    /* Diff, log and update only support one path at the moment, so we must
 
748
     * have 0 or 1 versioned files selected. If 0, the directory must be
 
749
     * versioned. */
 
750
    single_versioned_path = (
 
751
         (
 
752
          (numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
 
753
          (numsel == 0 && (svnst = current_file.svnstatus))
 
754
         ) && svnst != "unversioned");
 
755
    set_action_state(["svndiff", "svnupdate"], single_versioned_path);
 
756
 
 
757
    /* We can resolve if we have a file selected and it is conflicted. */
 
758
    set_action_state("svnresolved", single_versioned_path && numsel == 1 && svnst == "conflicted");
 
759
 
 
760
    /* Log should be available for revisions as well. */
 
761
    set_action_state("svnlog", single_versioned_path, true);
716
762
 
717
763
    /* There is currently nothing on the More Actions menu of use
718
764
     * when the current file is not a directory. Hence, just remove
725
771
    {
726
772
        var actions2_directory = document.getElementById("actions2_directory");
727
773
        actions2_directory.setAttribute("style", "display: inline;");
 
774
        var moreactions = document.getElementById("moreactions_area");
 
775
        moreactions.setAttribute("style", "display: inline;");
728
776
    }
729
777
    else
730
778
    {
731
779
        var actions2_file = document.getElementById("actions2_file");
732
780
        actions2_file.setAttribute("style", "display: inline;");
733
 
        var moreactions = document.getElementById("moreactions_area");
734
 
        moreactions.setAttribute("style", "display: none;");
735
781
    }
736
782
 
737
783
    return;
779
825
        action_rename(filename);
780
826
        break;
781
827
    case "delete":
782
 
        action_remove(selected_files);
 
828
        action_delete(selected_files);
783
829
        break;
784
830
    case "copy":
785
831
        action_copy(selected_files);
802
848
    case "svnadd":
803
849
        action_add(selected_files);
804
850
        break;
 
851
    case "svnremove":
 
852
        action_remove(selected_files);
 
853
        break;
805
854
    case "svnrevert":
806
855
        action_revert(selected_files);
807
856
        break;
808
857
    case "svndiff":
809
 
        window.location = path_join(app_path('diff'), current_path, selected_files[0]);
 
858
        window.location = path_join(app_path('diff'), current_path, selected_files[0] || '');
 
859
        break;
 
860
    case "svnupdate":
 
861
        action_update(selected_files);
 
862
        break;
 
863
    case "svnresolved":
 
864
        action_resolved(selected_files);
810
865
        break;
811
866
    case "svncommit":
812
867
        action_commit(selected_files);
813
868
        break;
814
869
    case "svnlog":
815
 
        window.location = path_join(app_path('svnlog'), current_path, selected_files[0]);
816
 
        break;
817
 
    case "svncheckout":
818
 
        action_checkout();
 
870
        window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
819
871
        break;
820
872
    }
821
873
}