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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-07-08 02:22:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:824
Setup: Try to make this `rm -rf` a little bit more safe. Don't let it cross FS 
boundaries.

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"
108
104
/** The listing object returned by the server as JSON */
109
105
file_listing = null;
110
106
current_file = null;
111
 
current_revision = null;
112
107
current_path = "";
113
108
 
114
109
/** Filenames of all files selected
137
132
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
138
133
 *      Defaults to "application/x-www-form-urlencoded".
139
134
 *      "multipart/form-data" is recommended for large uploads.
140
 
 * \param callback, optional.
141
 
 *      A callback function for after the action has been handled.
142
135
 */
143
 
function do_action(action, path, args, content_type, callback)
 
136
function do_action(action, path, args, content_type, ignore_response)
144
137
{
145
138
    args.action = action;
146
139
    /* Callback action, when the server returns */
147
 
    var callback_inner = function(response)
 
140
    var callback = function(response)
148
141
        {
149
142
            /* Check for action errors reported by the server, and report them
150
143
             * to the user */
151
144
            var error = response.getResponseHeader("X-IVLE-Action-Error");
152
 
            if (error != null && error != "")
 
145
            if (error != null)
153
146
                /* Note: This header (in particular) comes URI-encoded, to
154
147
                 * allow multi-line error messages. Decode */
155
148
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
156
149
            /* Now read the response and set up the page accordingly */
157
 
            if (callback != null)
158
 
                callback(path, response);
 
150
            if (ignore_response != true)
 
151
                handle_response(path, response, true);
159
152
        }
160
153
    /* Call the server and perform the action. This mutates the server. */
161
 
    ajax_call(callback_inner, service_app, path, args, "POST", content_type);
 
154
    ajax_call(callback, service_app, path, args, "POST", content_type);
162
155
}
163
156
 
164
157
/** Calls the server using Ajax, requesting a directory listing. This should
188
181
 */
189
182
function refresh()
190
183
{
191
 
    if (maybe_save('All changes since the last save will be lost!'))
192
 
        navigate(current_path);
 
184
    navigate(current_path);
193
185
}
194
186
 
195
187
/** Determines the "handler type" from a MIME type.
246
238
        return;
247
239
    }
248
240
 
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
241
    /* This will always return a listing, whether it is a dir or a file.
262
242
     */
263
243
    var listing = response.responseText;
306
286
    current_file = file_listing["."];     /* Global */
307
287
    delete file_listing["."];
308
288
 
309
 
    if ('revision' in listing)
310
 
    {
311
 
        current_revision = listing.revision;
312
 
    }
313
 
 
314
289
    /* Check if this is a directory listing or file contents */
315
290
    var isdir = response.getResponseHeader("X-IVLE-Return") == "Dir";
316
291
    if (isdir)
317
292
    {
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
 
        }
 
293
        handle_dir_listing(path, listing);
329
294
    }
330
295
    else
331
296
    {
393
358
     */
394
359
    upload_callback_count++;
395
360
    if (upload_callback_count >= 2)
396
 
    {
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
 
        document.getElementsByName('data')[0].value = '';
407
361
        refresh();
408
 
    }
409
362
}
410
363
 
411
364
/** Deletes all "dynamic" content on the page.
417
370
    dom_removechildren(document.getElementById("filesbody"));
418
371
}
419
372
 
420
 
/* Checks if a file needs to be saved. If it does, the user will be asked
421
 
 * if they want to continue anyway. The caller must specify a warning
422
 
 * sentence which indicates the consequences of continuing.
423
 
 * Returns true if we should continue, and false if we should not.
424
 
 */
425
 
function maybe_save(warning)
426
 
{
427
 
    if (warning == null) warning = '';
428
 
    if (current_file == null || current_file.isdir) return true;
429
 
    if (document.getElementById("save_button").disabled) return true;
430
 
    return confirm("This file has unsaved changes. " + warning +
431
 
                   "\nAre you sure you wish to continue?");
432
 
}
433
 
 
434
373
/** Deletes all "dynamic" content on the page necessary to navigate from
435
374
 * one directory listing to another (does not clear as much as clearpage
436
375
 * does).
470
409
    files.appendChild(txt_elem);
471
410
}
472
411
 
473
 
/** Given a path, filename and optional revision, returns a URL to open that
474
 
 *  revision of that file.
475
 
 */
476
 
function build_revision_url(path, filename, revision)
477
 
{
478
 
    bits = {'path': app_path(this_app, path, filename)};
479
 
    if (current_revision)
480
 
    {
481
 
        bits['query_string'] = 'r=' + revision;
482
 
    }
483
 
    return build_url(bits);
484
 
}
485
 
 
486
412
/** Given a mime type, returns the path to the icon.
487
413
 * \param type String, Mime type.
488
414
 * \param sizelarge Boolean, optional.
528
454
        return default_svn_nice;
529
455
}
530
456
 
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
457
/** Displays a download link to the binary file.
539
458
 */
540
459
function handle_binary(path)
543
462
    var div = document.createElement("div");
544
463
    files.appendChild(div);
545
464
    div.setAttribute("class", "padding");
546
 
    var download_link = app_url(download_app, path);
 
465
    var download_link = app_path(download_app, path);
547
466
    var par1 = dom_make_text_elem("p",
548
467
        "The file " + path + " is a binary file. To download this file, " +
549
468
        "click the following link:");
553
472
    div.appendChild(par2);
554
473
}
555
474
 
556
 
/* Enable or disable actions1 moreactions actions. Takes either a single
557
 
 * name, or an array of them.*/
558
 
function set_action_state(names, which, allow_on_revision)
559
 
{
560
 
    if (!(names instanceof Array)) names = Array(names);
561
 
 
562
 
    for (var i=0; i < names.length; i++)
563
 
    {
564
 
        element = document.getElementById('act_' + names[i]);
565
 
        if (which &&
566
 
            !(current_file.svnstatus == 'revision' && !allow_on_revision))
567
 
        {
568
 
            /* Enabling */
569
 
            element.setAttribute("class", "choice");
570
 
            element.removeAttribute("disabled");
571
 
        }
572
 
        else
573
 
        {
574
 
            /* Disabling */
575
 
            element.setAttribute("class", "disabled");
576
 
            element.setAttribute("disabled", "disabled");
577
 
        }
578
 
    }
579
 
}
580
 
 
581
 
/* Updates the list of available actions based on files selected */
582
475
function update_actions()
583
476
{
584
477
    var file;
585
478
    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
479
    if (numsel <= 1)
600
480
    {
601
481
        if (numsel == 0)
627
507
        else
628
508
            open.setAttribute("title",
629
509
                "Edit or view this file");
630
 
        open.setAttribute("href", build_revision_url(current_path, filename,
631
 
                                                     current_revision));
 
510
        open.setAttribute("href", app_path(this_app, current_path, filename));
632
511
    }
633
512
    else
634
513
    {
641
520
    /* Available if zero or one files are selected,
642
521
     * and only if this is a file, not a directory */
643
522
    var serve = document.getElementById("act_serve");
644
 
    if (numsel <= 1 && !file.isdir && current_file.svnstatus != 'revision')
 
523
    if (numsel <= 1 && !file.isdir)
645
524
    {
646
525
        serve.setAttribute("class", "choice");
647
 
        serve.setAttribute("onclick",
648
 
              "return maybe_save('The last saved version will be served.')");
649
526
        if (numsel == 0)
650
527
            serve.setAttribute("href",
651
 
                app_url(serve_app, current_path));
 
528
                app_path(serve_app, current_path));
652
529
        else
653
530
            serve.setAttribute("href",
654
 
                app_url(serve_app, current_path, filename));
 
531
                app_path(serve_app, current_path, filename));
655
532
    }
656
533
    else
657
534
    {
658
535
        serve.setAttribute("class", "disabled");
659
536
        serve.removeAttribute("href");
660
 
        serve.removeAttribute("onclick");
661
537
    }
662
538
 
663
539
    /* Run */
666
542
     */
667
543
    var run = document.getElementById("act_run");
668
544
     
669
 
    if (numsel <= 1 && !file.isdir && file.type == "text/x-python" 
670
 
            && current_file.svnstatus != 'revision')
671
 
    {
672
 
        if (numsel == 0)
673
 
        {
674
 
            // In the edit window
675
 
            var localpath = path_join('/home', current_path);
676
 
        }
677
 
        else
678
 
        {
679
 
            // In the browser window
680
 
            var localpath = path_join('/home', current_path, filename);
681
 
        }
682
 
        run.setAttribute("class", "choice");
 
545
    if (numsel == 0 && !file.isdir && file.type == "text/x-python")
 
546
    {
 
547
        // In the edit window
 
548
        run.setAttribute("class", "choice");
 
549
        localpath = app_path('home',current_path);
 
550
        run.setAttribute("onclick", "runfile('" + localpath + "')");
 
551
    }
 
552
    else if (numsel == 1 && !file.isdir && file.type == "text/x-python")
 
553
    {
 
554
        // In the browser window
 
555
        run.setAttribute("class", "choice");
 
556
        localpath = app_path('home',current_path,filename);
683
557
        run.setAttribute("onclick", "runfile('" + localpath + "')");
684
558
    }
685
559
    else
689
563
    }
690
564
 
691
565
    /* Download */
692
 
    /* Always available for current files.
 
566
    /* Always available.
693
567
     * If 0 files selected, download the current file or directory as a ZIP.
694
568
     * If 1 directory selected, download it as a ZIP.
695
569
     * If 1 non-directory selected, download it.
696
570
     * If >1 files selected, download them all as a ZIP.
697
571
     */
698
572
    var download = document.getElementById("act_download");
699
 
    if (current_file.svnstatus == 'revision')
700
 
    {
701
 
        download.setAttribute("class", "disabled");
702
 
        download.removeAttribute("onclick");
703
 
    }
704
 
    else if (numsel <= 1)
705
 
    {
706
 
        download.setAttribute("class", "choice")
 
573
    if (numsel <= 1)
 
574
    {
707
575
        if (numsel == 0)
708
576
        {
709
577
            download.setAttribute("href",
710
 
                app_url(download_app, current_path));
 
578
                app_path(download_app, current_path));
711
579
            if (file.isdir)
712
580
                download.setAttribute("title",
713
581
                    "Download the current directory as a ZIP file");
718
586
        else
719
587
        {
720
588
            download.setAttribute("href",
721
 
                app_url(download_app, current_path, filename));
 
589
                app_path(download_app, current_path, filename));
722
590
            if (file.isdir)
723
591
                download.setAttribute("title",
724
592
                    "Download the selected directory as a ZIP file");
730
598
    else
731
599
    {
732
600
        /* Make a query string with all the files to download */
733
 
        var dlpath = app_url(download_app, current_path) + "?";
 
601
        var dlpath = urlencode_path(app_path(download_app, current_path)) + "?";
734
602
        for (var i=0; i<numsel; i++)
735
603
            dlpath += "path=" + encodeURIComponent(selected_files[i]) + "&";
736
604
        dlpath = dlpath.substr(0, dlpath.length-1);
737
 
        download.setAttribute("class", "choice")
738
605
        download.setAttribute("href", dlpath);
739
606
        download.setAttribute("title",
740
607
            "Download the selected files as a ZIP file");
747
614
     * directory. */
748
615
    var publish = document.getElementById("act_publish");
749
616
    var submit = document.getElementById("act_submit");
750
 
    var pubcond = numsel <= 1 && file.isdir;
751
 
    if (pubcond)
 
617
    if (numsel <= 1 && file.isdir)
752
618
    {
 
619
        /* TODO: Work out of file is svn'd */
 
620
        publish.setAttribute("class", "choice");
 
621
        publish.removeAttribute("disabled");
753
622
        /* If this dir is already published, call it "Unpublish" */
754
623
        if (file.published)
755
624
        {
756
625
            publish.setAttribute("value", "unpublish");
757
626
            publish.setAttribute("title" ,"Make it so this directory "
758
627
                + "can not be seen by anyone on the web");
759
 
            publish.firstChild.nodeValue = "Unpublish";
 
628
            publish.textContent = "Unpublish";
760
629
        } else {
761
630
            publish.setAttribute("value", "publish");
762
631
            publish.setAttribute("title","Make it so this directory "
763
632
                + "can be seen by anyone on the web");
764
 
            publish.firstChild.nodeValue = "Publish";
 
633
            publish.textContent = "Publish";
765
634
        }
766
 
    }
767
 
    set_action_state(["publish", "submit"], pubcond);
 
635
        submit.setAttribute("class", "choice");
 
636
        submit.removeAttribute("disabled");
 
637
    }
 
638
    else
 
639
    {
 
640
        publish.setAttribute("class", "disabled");
 
641
        publish.setAttribute("disabled", "disabled");
 
642
        submit.setAttribute("class", "disabled");
 
643
        submit.setAttribute("disabled", "disabled");
 
644
    }
768
645
 
769
646
    /* Share */
770
 
    /* If exactly 1 non-directory file is selected, and its parent
 
647
    /* If exactly 1 non-directory file is selected/opened, and its parent
771
648
     * directory is published.
772
649
     */
773
 
    set_action_state("share", numsel == 1 && !file.isdir &&
774
 
                     current_file.published);
 
650
    var share = document.getElementById("act_share");
 
651
    if (numsel <= 1 && !file.isdir)
 
652
    {
 
653
        /* Work out if parent dir is published */
 
654
        parentdir = current_file;
 
655
        if (parentdir.published)
 
656
        {
 
657
            share.setAttribute("class", "choice");
 
658
            share.removeAttribute("disabled");
 
659
        } else {
 
660
            share.setAttribute("class", "disabled");
 
661
            share.setAttribute("disabled", "disabled");
 
662
        }
 
663
    }
 
664
    else
 
665
    {
 
666
        share.setAttribute("class", "disabled");
 
667
        share.setAttribute("disabled", "disabled");
 
668
    }
775
669
 
776
670
    /* Rename */
777
671
    /* If exactly 1 file is selected */
778
 
    set_action_state("rename", numsel == 1);
 
672
    var rename = document.getElementById("act_rename");
 
673
    if (numsel == 1)
 
674
    {
 
675
        rename.setAttribute("class", "choice");
 
676
        rename.removeAttribute("disabled");
 
677
    }
 
678
    else
 
679
    {
 
680
        rename.setAttribute("class", "disabled");
 
681
        rename.setAttribute("disabled", "disabled");
 
682
    }
779
683
 
780
684
    /* Delete, cut, copy */
781
685
    /* If >= 1 file is selected */
782
 
    set_action_state(["delete", "cut", "copy"], numsel >= 1);
 
686
    var act_delete = document.getElementById("act_delete");
 
687
    var cut = document.getElementById("act_cut");
 
688
    var copy = document.getElementById("act_copy");
 
689
    if (numsel >= 1)
 
690
    {
 
691
        act_delete.setAttribute("class", "choice");
 
692
        act_delete.removeAttribute("disabled");
 
693
        cut.setAttribute("class", "choice");
 
694
        cut.removeAttribute("disabled");
 
695
        copy.setAttribute("class", "choice");
 
696
        copy.removeAttribute("disabled");
 
697
    }
 
698
    else
 
699
    {
 
700
        act_delete.setAttribute("class", "disabled");
 
701
        act_delete.setAttribute("disabled", "disabled");
 
702
        cut.setAttribute("class", "disabled");
 
703
        cut.setAttribute("disabled", "disabled");
 
704
        copy.setAttribute("class", "disabled");
 
705
        copy.setAttribute("disabled", "disabled");
 
706
    }
783
707
 
784
708
    /* Paste, new file, new directory, upload */
785
709
    /* Disable if the current file is not a directory */
786
 
    set_action_state(["paste", "newfile", "mkdir", "upload"], current_file.isdir);
 
710
    if (!current_file.isdir)
 
711
    {
 
712
        var paste = document.getElementById("act_paste");
 
713
        var newfile = document.getElementById("act_newfile");
 
714
        var mkdir = document.getElementById("act_mkdir");
 
715
        var upload = document.getElementById("act_upload");
 
716
        paste.setAttribute("class", "disabled");
 
717
        paste.setAttribute("disabled", "disabled");
 
718
        newfile.setAttribute("class", "disabled");
 
719
        newfile.setAttribute("disabled", "disabled");
 
720
        mkdir.setAttribute("class", "disabled");
 
721
        mkdir.setAttribute("disabled", "disabled");
 
722
        upload.setAttribute("class", "disabled");
 
723
        upload.setAttribute("disabled", "disabled");
 
724
    }
787
725
 
788
726
    /* Subversion actions */
789
 
    /* These are only useful if we are in a versioned directory and have some
790
 
     * 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));
799
 
 
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. */
803
 
    single_versioned_path = (
804
 
         (
805
 
          (numsel == 1 && (svnst = file_listing[selected_files[0]].svnstatus)) ||
806
 
          (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");
812
 
 
813
 
    /* Log should be available for revisions as well. */
814
 
    set_action_state("svnlog", single_versioned_path, true);
815
 
 
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);
 
727
    /* TODO: Work out when these are appropriate */
 
728
    var svnadd = document.getElementById("act_svnadd");
 
729
    var svnrevert = document.getElementById("act_svnrevert");
 
730
    var svncommit = document.getElementById("act_svncommit");
 
731
    if (true)
 
732
    {
 
733
        svnadd.setAttribute("class", "choice");
 
734
        svnadd.removeAttribute("disabled");
 
735
        svnrevert.setAttribute("class", "choice");
 
736
        svnrevert.removeAttribute("disabled");
 
737
        svncommit.setAttribute("class", "choice");
 
738
        svncommit.removeAttribute("disabled");
 
739
    }
 
740
    var svncheckout = document.getElementById("act_svncheckout");
 
741
    /* current_path == username: We are at the top level */
 
742
    if (current_path == username)
 
743
    {
 
744
        svncheckout.setAttribute("class", "choice");
 
745
        svncheckout.removeAttribute("disabled");
 
746
    }
 
747
    else
 
748
    {
 
749
        svncheckout.setAttribute("class", "disabled");
 
750
        svncheckout.setAttribute("disabled", "disabled");
 
751
    }
827
752
 
828
753
    /* There is currently nothing on the More Actions menu of use
829
754
     * when the current file is not a directory. Hence, just remove
830
755
     * it entirely.
831
756
     * (This makes some of the above decisions somewhat redundant).
832
 
     * We also take this opportunity to show the appropriate actions2
833
 
     * bar for this path. It should either be a save or upload widget.
834
757
     */
835
 
    if (current_file.isdir)
 
758
    if (!(current_file.isdir))
836
759
    {
837
 
        var actions2_directory = document.getElementById("actions2_directory");
838
 
        actions2_directory.setAttribute("style", "display: inline;");
839
760
        var moreactions = document.getElementById("moreactions_area");
840
 
        moreactions.setAttribute("style", "display: inline;");
841
 
    }
842
 
    else
843
 
    {
844
 
        var actions2_file = document.getElementById("actions2_file");
845
 
        actions2_file.setAttribute("style", "display: inline;");
 
761
        moreactions.setAttribute("style", "display: none;");
846
762
    }
847
763
 
848
764
    return;
879
795
        action_unpublish(selected_files);
880
796
        break;
881
797
    case "share":
882
 
        window.open(public_app_url("~" + current_path, filename), 'share')
 
798
        //alert("Not yet implemented: Sharing files");
 
799
        window.open(public_app_path(serve_app, current_path, filename), 'share')
883
800
        break;
884
801
    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
 
 
 
802
        // TODO
 
803
        alert("Not yet implemented: Submit");
905
804
        break;
906
805
    case "rename":
907
806
        action_rename(filename);
908
807
        break;
909
808
    case "delete":
910
 
        action_delete(selected_files);
 
809
        action_remove(selected_files);
911
810
        break;
912
811
    case "copy":
913
812
        action_copy(selected_files);
930
829
    case "svnadd":
931
830
        action_add(selected_files);
932
831
        break;
933
 
    case "svnremove":
934
 
        action_remove(selected_files);
935
 
        break;
936
832
    case "svnrevert":
937
833
        action_revert(selected_files);
938
834
        break;
939
 
    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);
947
 
        break;
948
835
    case "svncommit":
949
836
        action_commit(selected_files);
950
837
        break;
951
 
    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(".");
 
838
    case "svncheckout":
 
839
        action_checkout();
962
840
        break;
963
841
    }
964
842
}
968
846
 */
969
847
function runfile(localpath)
970
848
{
971
 
    if (!maybe_save('The last saved version will be run.')) return false;
972
 
 
973
849
    /* Dump the entire file to the console */
974
850
    var callback = function()
975
851
    {
981
857
 
982
858
/** Called when the page loads initially.
983
859
 */
984
 
function browser_init()
 
860
window.onload = function()
985
861
{
986
862
    /* Navigate (internally) to the path in the URL bar.
987
863
     * This causes the page to be populated with whatever is at that address,
988
864
     * whether it be a directory or a file.
989
865
     */
990
 
    var path = get_path();
991
 
    navigate(path);
992
 
}
993
 
 
994
 
/** Gets the current path of the window */
995
 
function get_path() {
996
866
    var path = parse_url(window.location.href).path;
997
867
    /* Strip out root_dir + "/files" from the front of the path */
998
868
    var strip = make_path(this_app);
1015
885
        path = username;
1016
886
    }
1017
887
 
1018
 
    return path;
 
888
    navigate(path);
 
889
 
 
890
    /* Set up the console plugin to display as a popup window */
 
891
    console_init(true);
1019
892
}