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