~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-07 06:00:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:817
users.sql: Moved url from offering to subjects table.
    (The commit log in the previous revision which explains how to update your
    DB is still correct).

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
             * to the user */
144
144
            var error = response.getResponseHeader("X-IVLE-Action-Error");
145
145
            if (error != null)
146
 
                alert("Error: " + error.toString() + ".");
 
146
                /* Note: This header (in particular) comes URI-encoded, to
 
147
                 * allow multi-line error messages. Decode */
 
148
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
147
149
            /* Now read the response and set up the page accordingly */
148
150
            if (ignore_response != true)
149
 
                handle_response(path, response);
 
151
                handle_response(path, response, true);
150
152
        }
151
153
    /* Call the server and perform the action. This mutates the server. */
152
154
    ajax_call(callback, service_app, path, args, "POST", content_type);
165
167
    callback = function(response)
166
168
        {
167
169
            /* Read the response and set up the page accordingly */
168
 
            handle_response(path, response, url.args);
 
170
            handle_response(path, response, false, url.args);
169
171
        }
170
172
    /* Get any query strings */
171
173
    url = parse_url(window.location.href);
211
213
 * things) be used to update the URL in the location bar.
212
214
 * \param response XMLHttpRequest object returned by the server. Should
213
215
 * contain all the response data.
 
216
 * \param is_action Boolean. True if this is the response to an action, false
 
217
 * if this is the response to a simple listing. This is used in handling the
 
218
 * error.
214
219
 * \param url_args Arguments dict, for the arguments passed to the URL
215
220
 * in the browser's address bar (will be forwarded along).
216
221
 */
217
 
function handle_response(path, response, url_args)
 
222
function handle_response(path, response, is_action, url_args)
218
223
{
219
224
    /* TODO: Set location bar to "path" */
220
225
    current_path = path;
244
249
    }
245
250
    catch (e)
246
251
    {
247
 
        handle_error("The server returned an invalid directory listing");
 
252
        if (is_action)
 
253
        {
 
254
            var err = document.createElement("div");
 
255
            var p = dom_make_text_elem("p", "Error: "
 
256
                    + "There was an unexpected server error processing "
 
257
                    + "the selected command.");
 
258
            err.appendChild(p);
 
259
            p = dom_make_text_elem("p", "If the problem persists, please "
 
260
                    + "contact the system administrator.")
 
261
            err.appendChild(p);
 
262
            p = document.createElement("p");
 
263
            var refresh = document.createElement("input");
 
264
            refresh.setAttribute("type", "button");
 
265
            refresh.setAttribute("value", "Back to file view");
 
266
            refresh.setAttribute("onclick", "refresh()");
 
267
            p.appendChild(refresh);
 
268
            err.appendChild(p);
 
269
            handle_error(err);
 
270
        }
 
271
        else
 
272
        {
 
273
            var err = document.createElement("div");
 
274
            var p = dom_make_text_elem("p", "Error: "
 
275
                    + "There was an unexpected server error retrieving "
 
276
                    + "the requested file or directory.");
 
277
            err.appendChild(p);
 
278
            p = dom_make_text_elem("p", "If the problem persists, please "
 
279
                    + "contact the system administrator.")
 
280
            err.appendChild(p);
 
281
            handle_error(err);
 
282
        }
248
283
        return;
249
284
    }
250
285
    /* Get "." out, it's special */
351
386
/*** HANDLERS for different types of responses (such as dir listing, file,
352
387
 * etc). */
353
388
 
 
389
/* handle_error.
 
390
 * message may either be a string, or a DOM node, which will be placed inside
 
391
 * a div.
 
392
 */
354
393
function handle_error(message)
355
394
{
356
395
    var files = document.getElementById("filesbody");
357
 
    var txt_elem = dom_make_text_elem("div", "Error: "
358
 
        + message.toString() + ".")
 
396
    var txt_elem;
 
397
    if (typeof(message) == "string")
 
398
    {
 
399
        txt_elem = dom_make_text_elem("div", "Error: "
 
400
                   + message.toString() + ".")
 
401
    }
 
402
    else
 
403
    {
 
404
        /* Assume message is a DOM node */
 
405
        txt_elem = document.createElement("div");
 
406
        txt_elem.appendChild(message);
 
407
    }
359
408
    txt_elem.setAttribute("class", "padding error");
360
409
    files.appendChild(txt_elem);
361
410
}
468
517
    }
469
518
 
470
519
    /* Serve */
471
 
    /* Available if exactly one file is selected,
 
520
    /* Available if zero or one files are selected,
472
521
     * and only if this is a file, not a directory */
473
522
    var serve = document.getElementById("act_serve");
474
 
    if (numsel == 1 && !file.isdir)
 
523
    if (numsel <= 1 && !file.isdir)
475
524
    {
476
525
        serve.setAttribute("class", "choice");
477
 
        serve.setAttribute("href",
478
 
            app_path(serve_app, current_path, filename));
 
526
        if (numsel == 0)
 
527
            serve.setAttribute("href",
 
528
                app_path(serve_app, current_path));
 
529
        else
 
530
            serve.setAttribute("href",
 
531
                app_path(serve_app, current_path, filename));
479
532
    }
480
533
    else
481
534
    {
564
617
    if (numsel <= 1 && file.isdir)
565
618
    {
566
619
        /* TODO: Work out of file is svn'd */
567
 
        /* TODO: If this dir is already published, call it "Unpublish" */
568
620
        publish.setAttribute("class", "choice");
569
621
        publish.removeAttribute("disabled");
 
622
        /* If this dir is already published, call it "Unpublish" */
 
623
        if (file.published)
 
624
        {
 
625
            publish.setAttribute("value", "unpublish");
 
626
            publish.setAttribute("title" ,"Make it so this directory "
 
627
                + "can not be seen by anyone on the web");
 
628
            publish.textContent = "Unpublish";
 
629
        } else {
 
630
            publish.setAttribute("value", "publish");
 
631
            publish.setAttribute("title","Make it so this directory "
 
632
                + "can be seen by anyone on the web");
 
633
            publish.textContent = "Publish";
 
634
        }
570
635
        submit.setAttribute("class", "choice");
571
636
        submit.removeAttribute("disabled");
572
637
    }
585
650
    var share = document.getElementById("act_share");
586
651
    if (numsel <= 1 && !file.isdir)
587
652
    {
588
 
        /* TODO: Work out if parent dir is published */
589
 
        share.setAttribute("class", "choice");
590
 
        share.removeAttribute("disabled");
 
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
        }
591
663
    }
592
664
    else
593
665
    {
634
706
    }
635
707
 
636
708
    /* Paste, new file, new directory, upload */
637
 
    /* Always enabled (assuming this is a directory) */
 
709
    /* Disable if the current file is not a directory */
 
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
    }
638
725
 
639
726
    /* Subversion actions */
640
727
    /* TODO: Work out when these are appropriate */
663
750
        svncheckout.setAttribute("disabled", "disabled");
664
751
    }
665
752
 
 
753
    /* There is currently nothing on the More Actions menu of use
 
754
     * when the current file is not a directory. Hence, just remove
 
755
     * it entirely.
 
756
     * (This makes some of the above decisions somewhat redundant).
 
757
     */
 
758
    if (!(current_file.isdir))
 
759
    {
 
760
        var moreactions = document.getElementById("moreactions_area");
 
761
        moreactions.setAttribute("style", "display: none;");
 
762
    }
 
763
 
666
764
    return;
667
765
}
668
766
 
697
795
        action_unpublish(selected_files);
698
796
        break;
699
797
    case "share":
700
 
        // TODO
701
 
        alert("Not yet implemented: Sharing files");
 
798
        //alert("Not yet implemented: Sharing files");
 
799
        window.open(public_app_path(serve_app, current_path, filename), 'share')
702
800
        break;
703
801
    case "submit":
704
802
        // TODO