~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-01-12 16:38:24 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:205
browser.js: Added appropriate handlers for error, text, and binary data.
They now correctly display the error message, text box, and download link
respectively, and clear away the "dir listing" table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
/* Url names for apps */
24
24
this_app = "files";
25
25
service_app = "fileservice";
 
26
serve_app = "serve";
 
27
download_app = "download";
26
28
 
27
29
/* Mapping MIME types onto handlers.
28
30
 * "text" : When navigating to a text file, the text editor is opened.
234
236
 
235
237
function handle_error(message)
236
238
{
237
 
    /* TODO: Find a better place to put this message. */
238
 
    var files = document.getElementById("files");
239
 
    var tr = document.createElement("tr");
240
 
    var td = document.createElement("td");
241
 
    tr.appendChild(td);
242
 
    var td = document.createElement("td");
243
 
    tr.appendChild(td);
244
 
    var td = document.createElement("td");
245
 
    tr.appendChild(td);
246
 
    var txt_elem = dom_make_text_elem("td", "Error: "
 
239
    var files = document.getElementById("filesbody");
 
240
    var txt_elem = dom_make_text_elem("div", "Error: "
247
241
        + message.toString() + ".")
248
 
    txt_elem.setAttribute("class", "error");
249
 
    tr.appendChild(txt_elem);
250
 
    var td = document.createElement("td");
251
 
    tr.appendChild(td);
252
 
    var td = document.createElement("td");
253
 
    tr.appendChild(td);
254
 
    files.appendChild(tr);
 
242
    txt_elem.setAttribute("class", "padding error");
 
243
    files.appendChild(txt_elem);
255
244
}
256
245
 
257
246
/** Presents a path list (address bar inside the page) for clicking.
477
466
 */
478
467
function handle_text(path, text)
479
468
{
480
 
    /* TODO */
481
 
    alert(text);
 
469
    /* Create a textarea with the text in it
 
470
     * (The makings of a primitive editor).
 
471
     */
 
472
    var files = document.getElementById("filesbody");
 
473
    var div = document.createElement("div");
 
474
    files.appendChild(div);
 
475
    div.setAttribute("class", "padding");
 
476
    var txt_elem = dom_make_text_elem("textarea",
 
477
        text.toString())
 
478
    div.appendChild(txt_elem);
 
479
    txt_elem.setAttribute("id", "editbox");
 
480
    /* TODO: Make CSS height: 100% work */
 
481
    txt_elem.setAttribute("rows", "20");
482
482
}
483
483
 
484
484
/** Displays a download link to the binary file.
485
485
 */
486
486
function handle_binary(path)
487
487
{
488
 
    /* TODO */
489
 
    alert(path);
 
488
 
 
489
    var files = document.getElementById("filesbody");
 
490
    var div = document.createElement("div");
 
491
    files.appendChild(div);
 
492
    div.setAttribute("class", "padding");
 
493
    var download_link = make_path(path_join(download_app, path));
 
494
    var par1 = dom_make_text_elem("p",
 
495
        "The file " + path + " is a binary file. To download this file, " +
 
496
        "click the following link:");
 
497
    var par2 = dom_make_link_elem("p",
 
498
        "Download " + path, "Download " + path, download_link);
 
499
    div.appendChild(par1);
 
500
    div.appendChild(par2);
490
501
}
491
502
 
492
503
/** Called when the page loads initially.