364
366
statusbar.appendChild(document.createTextNode(statusmsg));
369
/** SORTING FUNCTIONS **/
371
/** Sorts the file table. Physically manipulates the DOM table to reflect the
372
* sorted nodes, and also updates the little sort arrow.
374
* \param sort_field The name of the field to sort on primarily. This can
375
* either be "filename", or one of the fields of a fileinfo object. Note that
376
* while this determines the primary sort key, the secondary sort keys are
377
* determined by the global sort_order. Calling sort_listing reorders
378
* sort_order, bringing the specified sort_field to the top.
379
* Also note that sorting by "isdir" is more prominent than whatever field is
381
* \param sort_ascending If true, sorts ascending. If false, descending.
383
function sort_listing(sort_field, sort_ascending)
386
var files = document.getElementById("files");
387
var files_children = files.childNodes;
388
var files_array = new Array(files_children.length);
389
/* Update sort_order, bringing sort_field to the top. */
392
/* Build an array of DOM tr elements (with the additional 'filename' and
393
* 'fileinfo' attributes as written when the listing is created). */
394
/* Note: Must manually create an array from files_children, which is a DOM
395
* NodeList, not an array. */
396
for (i=0; i<files_children.length; i++)
397
files_array[i] = files_children[i];
399
/* Sort this array */
400
files_array.sort(compare_files);
402
/* Clean out the table (the TRs are safely stored in the array) */
403
dom_removechildren(files);
405
/* Insert the TRs back into the table, in their sorted order */
406
for (i=0; i<files_array.length; i++)
407
files.appendChild(files_array[i]);
409
/* Fix the coloring classes on the rows so they are interleaved. */
415
/** Comparison function used for sorting. Compares two DOM tr nodes (with
416
* the additional 'filename' and 'fileinfo' attributes as written when the
417
* listing is created).
418
* Returns an integer, which is -1 if a < b, 0 if a == b, and 1 if a > b.
419
* The fields to compare by are determined by the global variable sort_order.
421
function compare_files(a, b)
423
if (a.fileinfo.isdir < b.fileinfo.isdir) return -1;
424
else if (a.fileinfo.isdir > b.fileinfo.isdir) return 1;
426
/* TEMP: Just sort by filename */
427
if (a.filename < b.filename) return -1;
428
else if (a.filename > b.filename) return 1;
367
435
/** Clears all selected files and causes the single file specified to become
369
437
* \param filename The file in the list to select.
421
489
filetablethead_tr.appendChild(filetablethead_th);
422
490
filetablethead_th.setAttribute("class", "col-check");
423
491
filetablethead_th = dom_make_link_elem("th", "Filename",
424
"Sort by filename", "")
492
"Sort by filename", null, "return sort_listing(\"filename\")");
425
493
filetablethead_tr.appendChild(filetablethead_th);
426
494
filetablethead_th.setAttribute("class", "col-filename");
427
495
filetablethead_th.setAttribute("colspan", 3);
428
496
filetablethead_th = dom_make_link_elem("th", "Size",
429
"Sort by file size", "")
497
"Sort by file size", null, "return sort_listing(\"size\")");
430
498
filetablethead_tr.appendChild(filetablethead_th);
431
499
filetablethead_th.setAttribute("class", "col-size");
432
500
filetablethead_th = dom_make_link_elem("th", "Modified",
433
"Sort by date modified", "")
501
"Sort by date modified", null, "return sort_listing(\"mtime\")");
434
502
filetablethead_tr.appendChild(filetablethead_th);
435
503
filetablethead_th.setAttribute("class", "col-date");