~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-14 04:39:11 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:862
browser: Refactor the client-side actions1 processing! Kill off 100 lines
         of a 150 line block by creating a function to enable or disable
         an arbitrary option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
475
475
    div.appendChild(par2);
476
476
}
477
477
 
 
478
/* Enable or disable an actions1 moreactions action. */
 
479
function set_action_state(name, which)
 
480
{
 
481
    element = document.getElementById('act_' + name);
 
482
    if (which)
 
483
    {
 
484
        /* Enabling */
 
485
        element.setAttribute("class", "choice");
 
486
        element.removeAttribute("disabled");
 
487
    }
 
488
    else
 
489
    {
 
490
        /* Disabling */
 
491
        element.setAttribute("class", "disabled");
 
492
        element.setAttribute("disabled", "disabled");
 
493
    }
 
494
}
 
495
 
478
496
function update_actions()
479
497
{
480
498
    var file;
617
635
     * directory. */
618
636
    var publish = document.getElementById("act_publish");
619
637
    var submit = document.getElementById("act_submit");
620
 
    if (numsel <= 1 && file.isdir)
 
638
    var pubcond = numsel <= 1 && file.isdir;
 
639
    if (pubcond)
621
640
    {
622
641
        /* TODO: Work out of file is svn'd */
623
 
        publish.setAttribute("class", "choice");
624
 
        publish.removeAttribute("disabled");
625
642
        /* If this dir is already published, call it "Unpublish" */
626
643
        if (file.published)
627
644
        {
635
652
                + "can be seen by anyone on the web");
636
653
            publish.textContent = "Publish";
637
654
        }
638
 
        submit.setAttribute("class", "choice");
639
 
        submit.removeAttribute("disabled");
640
 
    }
641
 
    else
642
 
    {
643
 
        publish.setAttribute("class", "disabled");
644
 
        publish.setAttribute("disabled", "disabled");
645
 
        submit.setAttribute("class", "disabled");
646
 
        submit.setAttribute("disabled", "disabled");
647
 
    }
 
655
    }
 
656
    set_action_state("publish", pubcond);
 
657
    set_action_state("submit", pubcond);
648
658
 
649
659
    /* Share */
650
 
    /* If exactly 1 non-directory file is selected/opened, and its parent
 
660
    /* If exactly 1 non-directory file is selected, and its parent
651
661
     * directory is published.
652
662
     */
653
 
    var share = document.getElementById("act_share");
654
 
    if (numsel <= 1 && !file.isdir)
655
 
    {
656
 
        /* Work out if parent dir is published */
657
 
        parentdir = current_file;
658
 
        if (parentdir.published)
659
 
        {
660
 
            share.setAttribute("class", "choice");
661
 
            share.removeAttribute("disabled");
662
 
        } else {
663
 
            share.setAttribute("class", "disabled");
664
 
            share.setAttribute("disabled", "disabled");
665
 
        }
666
 
    }
667
 
    else
668
 
    {
669
 
        share.setAttribute("class", "disabled");
670
 
        share.setAttribute("disabled", "disabled");
671
 
    }
 
663
    set_action_state("share", numsel == 1 && !file.isdir &&
 
664
                     current_file.published);
672
665
 
673
666
    /* Rename */
674
667
    /* If exactly 1 file is selected */
675
 
    var rename = document.getElementById("act_rename");
676
 
    if (numsel == 1)
677
 
    {
678
 
        rename.setAttribute("class", "choice");
679
 
        rename.removeAttribute("disabled");
680
 
    }
681
 
    else
682
 
    {
683
 
        rename.setAttribute("class", "disabled");
684
 
        rename.setAttribute("disabled", "disabled");
685
 
    }
 
668
    set_action_state("rename", numsel == 1);
686
669
 
687
670
    /* Delete, cut, copy */
688
671
    /* If >= 1 file is selected */
689
 
    var act_delete = document.getElementById("act_delete");
690
 
    var cut = document.getElementById("act_cut");
691
 
    var copy = document.getElementById("act_copy");
692
 
    if (numsel >= 1)
693
 
    {
694
 
        act_delete.setAttribute("class", "choice");
695
 
        act_delete.removeAttribute("disabled");
696
 
        cut.setAttribute("class", "choice");
697
 
        cut.removeAttribute("disabled");
698
 
        copy.setAttribute("class", "choice");
699
 
        copy.removeAttribute("disabled");
700
 
    }
701
 
    else
702
 
    {
703
 
        act_delete.setAttribute("class", "disabled");
704
 
        act_delete.setAttribute("disabled", "disabled");
705
 
        cut.setAttribute("class", "disabled");
706
 
        cut.setAttribute("disabled", "disabled");
707
 
        copy.setAttribute("class", "disabled");
708
 
        copy.setAttribute("disabled", "disabled");
709
 
    }
 
672
    set_action_state("delete", numsel >= 1);
 
673
    set_action_state("cut", numsel >= 1);
 
674
    set_action_state("copy", numsel >= 1);
710
675
 
711
676
    /* Paste, new file, new directory, upload */
712
677
    /* Disable if the current file is not a directory */
713
 
    if (!current_file.isdir)
714
 
    {
715
 
        var paste = document.getElementById("act_paste");
716
 
        var newfile = document.getElementById("act_newfile");
717
 
        var mkdir = document.getElementById("act_mkdir");
718
 
        var upload = document.getElementById("act_upload");
719
 
        paste.setAttribute("class", "disabled");
720
 
        paste.setAttribute("disabled", "disabled");
721
 
        newfile.setAttribute("class", "disabled");
722
 
        newfile.setAttribute("disabled", "disabled");
723
 
        mkdir.setAttribute("class", "disabled");
724
 
        mkdir.setAttribute("disabled", "disabled");
725
 
        upload.setAttribute("class", "disabled");
726
 
        upload.setAttribute("disabled", "disabled");
727
 
    }
 
678
    set_action_state("paste", current_file.isdir);
 
679
    set_action_state("newfile", current_file.isdir);
 
680
    set_action_state("mkdir", current_file.isdir);
 
681
    set_action_state("upload", current_file.isdir);
728
682
 
729
683
    /* Subversion actions */
730
 
    var svnadd = document.getElementById("act_svnadd");
731
684
    var svndiff = document.getElementById("act_svndiff");
732
 
    var svnrevert = document.getElementById("act_svnrevert");
733
 
    var svncommit = document.getElementById("act_svncommit");
734
685
    var svnlog = document.getElementById("act_svnlog");
735
686
    /* These are only useful if we are in a versioned directory and have some
736
687
     * files selected. */
737
 
    if (numsel >= 1 && current_file.svnstatus)
738
 
    {
739
 
        svnadd.setAttribute("class", "choice");
740
 
        svnadd.removeAttribute("disabled");
741
 
        svnrevert.setAttribute("class", "choice");
742
 
        svnrevert.removeAttribute("disabled");
743
 
        svncommit.setAttribute("class", "choice");
744
 
        svncommit.removeAttribute("disabled");
745
 
    }
746
 
    else
747
 
    {
748
 
        svnadd.setAttribute("class", "disabled");
749
 
        svnadd.setAttribute("disabled", "disabled");
750
 
        svnrevert.setAttribute("class", "disabled");
751
 
        svnrevert.setAttribute("disabled", "disabled");
752
 
        svncommit.setAttribute("class", "disabled");
753
 
        svncommit.setAttribute("disabled", "disabled");
754
 
    }
 
688
    set_action_state("svnadd", numsel >= 1 && current_file.svnstatus);
 
689
    set_action_state("svnrevert", numsel >= 1 && current_file.svnstatus);
 
690
    set_action_state("svncommit", numsel >= 1 && current_file.svnstatus);
755
691
 
756
692
    /* Diff and log only support one path at the moment. */
757
 
    if (numsel == 1)
758
 
    {
759
 
        svnst = file_listing[selected_files[0]].svnstatus;
760
 
 
761
 
        /* Diff and log also don't like unversioned paths, and diffs on unchanged
762
 
         * files are pointless. */
763
 
        if (svnst && svnst != "unversioned")
764
 
        {
765
 
            if (svnst != "normal")
766
 
            {
767
 
                svndiff.setAttribute("class", "choice");
768
 
                svndiff.removeAttribute("disabled");
769
 
            }
770
 
            else
771
 
            {
772
 
                svndiff.setAttribute("class", "disabled");
773
 
                svndiff.setAttribute("disabled", "disabled");
774
 
            }
775
 
        
776
 
            svnlog.setAttribute("class", "choice");
777
 
            svnlog.removeAttribute("disabled");
778
 
        }
779
 
    }
780
 
    else
781
 
    {
782
 
        svndiff.setAttribute("class", "disabled");
783
 
        svndiff.setAttribute("disabled", "disabled");
784
 
        svnlog.setAttribute("class", "disabled");
785
 
        svnlog.setAttribute("disabled", "disabled");
786
 
    }
787
 
 
788
 
    var svncheckout = document.getElementById("act_svncheckout");
 
693
    single_versioned_path = (numsel == 1 &&
 
694
                             (svnst = file_listing[selected_files[0]].svnstatus) &&
 
695
                             svnst != "unversioned");
 
696
    set_action_state("svnlog", single_versioned_path);
 
697
    set_action_state("svndiff", single_versioned_path && svnst != "normal");
 
698
 
789
699
    /* current_path == username: We are at the top level */
790
 
    if (current_path == username)
791
 
    {
792
 
        svncheckout.setAttribute("class", "choice");
793
 
        svncheckout.removeAttribute("disabled");
794
 
    }
795
 
    else
796
 
    {
797
 
        svncheckout.setAttribute("class", "disabled");
798
 
        svncheckout.setAttribute("disabled", "disabled");
799
 
    }
 
700
    set_action_state("svncheckout", current_path == username);
800
701
 
801
702
    /* There is currently nothing on the More Actions menu of use
802
703
     * when the current file is not a directory. Hence, just remove