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

« back to all changes in this revision

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

  • Committer: me at id
  • Date: 2009-01-14 22:42:10 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1133
install_proc.txt: Add dependencies on python-{storm,psycopg2}.

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",
 
63
    "unversioned": null,
64
64
    "normal": "normal.png",
65
65
    "added": "added.png",
66
66
    "missing": "missing.png",
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
379
377
    upload_callback_count++;
380
378
    if (upload_callback_count >= 2)
381
379
    {
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
380
        document.getElementsByName('data')[0].value = '';
392
381
        refresh();
393
382
    }
556
545
    }
557
546
}
558
547
 
559
 
/* Updates the list of available actions based on files selected */
560
548
function update_actions()
561
549
{
562
550
    var file;
563
551
    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
552
    if (numsel <= 1)
578
553
    {
579
554
        if (numsel == 0)
644
619
     */
645
620
    var run = document.getElementById("act_run");
646
621
     
647
 
    if (numsel <= 1 && !file.isdir && file.type == "text/x-python" 
648
 
            && current_file.svnstatus != 'revision')
 
622
    if (!file.isdir && file.type == "text/x-python" && numsel <= 1
 
623
        && current_file.svnstatus != 'revision')
649
624
    {
650
625
        if (numsel == 0)
651
626
        {
728
703
    var pubcond = numsel <= 1 && file.isdir;
729
704
    if (pubcond)
730
705
    {
 
706
        /* TODO: Work out of file is svn'd */
731
707
        /* If this dir is already published, call it "Unpublish" */
732
708
        if (file.published)
733
709
        {
734
710
            publish.setAttribute("value", "unpublish");
735
711
            publish.setAttribute("title" ,"Make it so this directory "
736
712
                + "can not be seen by anyone on the web");
737
 
            publish.firstChild.nodeValue = "Unpublish";
 
713
            publish.textContent = "Unpublish";
738
714
        } else {
739
715
            publish.setAttribute("value", "publish");
740
716
            publish.setAttribute("title","Make it so this directory "
741
717
                + "can be seen by anyone on the web");
742
 
            publish.firstChild.nodeValue = "Publish";
 
718
            publish.textContent = "Publish";
743
719
        }
744
720
    }
745
721
    set_action_state(["publish", "submit"], pubcond);
766
742
    /* Subversion actions */
767
743
    /* These are only useful if we are in a versioned directory and have some
768
744
     * 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
 
    
 
745
    set_action_state(["svnadd", "svnremove", "svnrevert", "svncommit"], numsel >= 1 && current_file.svnstatus);
 
746
 
774
747
    /* Diff, log and update only support one path at the moment, so we must
775
748
     * have 0 or 1 versioned files selected. If 0, the directory must be
776
749
     * versioned. */
787
760
    /* Log should be available for revisions as well. */
788
761
    set_action_state("svnlog", single_versioned_path, true);
789
762
 
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);
801
 
 
802
763
    /* There is currently nothing on the More Actions menu of use
803
764
     * when the current file is not a directory. Hence, just remove
804
765
     * it entirely.
853
814
        action_unpublish(selected_files);
854
815
        break;
855
816
    case "share":
856
 
        window.open(public_app_path("~" + current_path, filename), 'share')
 
817
        //alert("Not yet implemented: Sharing files");
 
818
        window.open(public_app_path(serve_app, current_path, filename), 'share')
857
819
        break;
858
820
    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
 
 
 
821
        // TODO
 
822
        alert("Not yet implemented: Submit");
878
823
        break;
879
824
    case "rename":
880
825
        action_rename(filename);
924
869
    case "svnlog":
925
870
        window.location = path_join(app_path('svnlog'), current_path, selected_files[0] || '');
926
871
        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(".");
935
 
        break;
936
872
    }
937
873
}
938
874
 
960
896
     * This causes the page to be populated with whatever is at that address,
961
897
     * whether it be a directory or a file.
962
898
     */
963
 
    var path = get_path();
964
 
    navigate(path);
965
 
}
966
 
 
967
 
/** Gets the current path of the window */
968
 
function get_path() {
969
899
    var path = parse_url(window.location.href).path;
970
900
    /* Strip out root_dir + "/files" from the front of the path */
971
901
    var strip = make_path(this_app);
988
918
        path = username;
989
919
    }
990
920
 
991
 
    return path;
 
921
    navigate(path);
992
922
}