353
353
return make_path(path_join(svn_icons_path, filename));
356
/** Initialises the DOM elements required to present a dir listing,
357
* assuming that clear_page has just been called or the page just
358
* loaded for the first time.
360
function setup_for_dir_listing()
362
var filesbody = document.getElementById("filesbody");
364
/* Using a table-based layout, for reasons of sanity */
365
/* One row, 2 columns */
366
var middle = document.createElement("table");
367
filesbody.appendChild(middle);
368
middle.setAttribute("id", "middle");
369
var middle_tbody = document.createElement("tbody");
370
middle.appendChild(middle_tbody);
371
var middle_tr = document.createElement("tr");
372
middle_tbody.appendChild(middle_tr);
374
/* Column 1: File table */
375
var filetable = document.createElement("td");
376
middle_tr.appendChild(filetable);
377
filetable.setAttribute("id", "filetable");
378
var filetablediv = document.createElement("div");
379
filetable.appendChild(filetablediv);
380
filetablediv.setAttribute("id", "filetablediv");
381
/* A nested table within this div - the actual files listing */
382
var filetabletable = document.createElement("table");
383
filetablediv.appendChild(filetabletable);
384
filetabletable.setAttribute("width", "100%");
385
var filetablethead = document.createElement("thead");
386
filetabletable.appendChild(filetablethead);
387
var filetablethead_tr = document.createElement("tr");
388
filetablethead.appendChild(filetablethead_tr);
389
filetablethead_tr.setAttribute("class", "rowhead");
391
var filetablethead_th = document.createElement("th");
392
filetablethead_tr.appendChild(filetablethead_th);
393
filetablethead_th.setAttribute("class", "col-check");
394
filetablethead_th = dom_make_link_elem("th", "Filename",
395
"Sort by filename", "")
396
filetablethead_tr.appendChild(filetablethead_th);
397
filetablethead_th.setAttribute("class", "col-filename");
398
filetablethead_th.setAttribute("colspan", 3);
399
filetablethead_th = dom_make_link_elem("th", "Size",
400
"Sort by file size", "")
401
filetablethead_tr.appendChild(filetablethead_th);
402
filetablethead_th.setAttribute("class", "col-size");
403
filetablethead_th = dom_make_link_elem("th", "Modified",
404
"Sort by date modified", "")
405
filetablethead_tr.appendChild(filetablethead_th);
406
filetablethead_th.setAttribute("class", "col-date");
408
var filetabletbody = document.createElement("tbody");
409
filetabletable.appendChild(filetabletbody);
410
filetabletbody.setAttribute("id", "files");
412
/* Column 2: Side-panel */
413
var sidepanel = document.createElement("td");
414
middle_tr.appendChild(sidepanel);
415
sidepanel.setAttribute("id", "sidepanel");
418
/* Now after the table "middle", there is a status bar */
419
var statusbar = document.createElement("div");
420
filesbody.appendChild(statusbar);
421
statusbar.setAttribute("id", "statusbar");
424
/** Presents the directory listing.
426
function handle_dir_listing(path, listing)
429
setup_for_dir_listing();
431
/* Nav through the top-level of the JSON to the actual listing object. */
432
var listing = listing.listing;
434
/* Get "." out, it's special */
435
var thisdir = listing["."];
437
/* Is this dir under svn? */
438
var under_subversion = "svnstatus" in thisdir;
440
var files = document.getElementById("files");
447
var total_file_size = 0; /* In bytes */
449
/* Create all of the files */
450
for (var filename in listing)
452
file = listing[filename];
455
total_file_size += file.size;
456
/* Make a 'tr' element */
457
row = document.createElement("tr");
458
/* Column 1: Selection checkbox */
459
row.setAttribute("class", "row" + row_toggle.toString())
460
row_toggle = row_toggle == 1 ? 2 : 1;
461
td = document.createElement("td");
462
checkbox = document.createElement("input");
463
checkbox.setAttribute("type", "checkbox");
464
checkbox.setAttribute("title", "Select this file");
465
td.appendChild(checkbox);
469
/* Column 2: Filetype and subversion icons. */
470
td = document.createElement("td");
471
td.setAttribute("class", "thincol");
472
td.appendChild(dom_make_img(mime_type_to_icon("text/directory"),
475
td = document.createElement("td");
476
td.setAttribute("class", "thincol");
477
if (under_subversion)
478
td.appendChild(dom_make_img(svnstatus_to_icon(file.svnstatus),
479
22, 22, file.svnstatus));
481
/* Column 3: Filename */
482
row.appendChild(dom_make_link_elem("td", filename,
483
"Navigate to " + path_join(path, filename),
484
make_path(path_join(this_app, path, filename)),
485
"navigate(" + path_join(path, filename) + ")"));
489
/* Column 2: Filetype and subversion icons. */
490
td = document.createElement("td");
491
td.setAttribute("class", "thincol");
492
td.appendChild(dom_make_img(mime_type_to_icon(file.type),
495
td = document.createElement("td");
496
td.setAttribute("class", "thincol");
497
if (under_subversion)
498
td.appendChild(dom_make_img(svnstatus_to_icon(file.svnstatus),
499
22, 22, file.svnstatus));
501
/* Column 3: Filename */
502
row.appendChild(dom_make_text_elem("td", filename));
505
row.appendChild(dom_make_text_elem("td", nice_filesize(file.size)));
507
row.appendChild(dom_make_text_elem("td", file.mtime_short,
509
files.appendChild(row);
512
/* Write to the status bar */
513
var statusbar = document.getElementById("statusbar");
514
var statusmsg = total_files.toString() + " files, "
515
+ nice_filesize(total_file_size);
516
dom_removechildren(statusbar);
517
statusbar.appendChild(document.createTextNode(statusmsg));
520
356
/** Presents the text editor.
522
358
function handle_text(path, text, handler_type)