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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-01-16 21:41:56 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:234
browser/listing.js:
    * No longer use row indices to identify rows (since rows may be out of
      order if they are sorted).
    * Store filename/fileinfo in the DOM nodes so given a DOM node you can
      get the file information without having to parse it back up (ew).
util.js: dom_make_img_node now performs url encoding on the src attribute.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * Handles directory listings on the client side.
23
23
 */
24
24
 
25
 
/* TODO: encodeURI on all generated paths for links */
 
25
/* Note: The DOM "tr" nodes of the file listing have extra attributes added
 
26
 * to them: "filename" and "fileinfo", which stores the key and value as
 
27
 * returned by the server. */
26
28
 
27
29
/* DOM nodeType constants */
28
30
ELEMENT_NODE = 1;
364
366
 
365
367
/** Clears all selected files and causes the single file specified to become
366
368
 * selected.
367
 
 * \param fileid The index of the file in the list to select.
 
369
 * \param filename The file in the list to select.
368
370
 */
369
 
function select_file(fileid)
 
371
function select_file(filename)
370
372
{
371
373
    var files_children = document.getElementById("files").childNodes;
372
374
    var checkbox;
 
375
    var tr;
373
376
    for (var i=0; i<files_children.length; i++)
374
377
    {
375
378
        tr = files_children[i];
376
379
        checkbox = tr.firstChild.firstChild;
377
 
        checkbox.checked = i == fileid;
 
380
        checkbox.checked = tr.filename == filename;
378
381
    }
379
382
    update_selection();
380
383
}
454
457
    setmode(false);
455
458
    setup_for_dir_listing();
456
459
    var row_toggle = 1;
457
 
    var i;
458
460
    /* Nav through the top-level of the JSON to the actual listing object. */
459
461
    var listing = listing.listing;
460
462
    file_listing = listing;     /* Global */
474
476
    var selection_string;
475
477
 
476
478
    /* Create all of the files */
477
 
    i = 0;
478
479
    for (var filename in listing)
479
480
    {
480
 
        selection_string = "select_file(" + i.toString() + ")";
 
481
        selection_string = "select_file(" + repr(filename) + ")";
481
482
        file = listing[filename];
482
 
        /* Make a 'tr' element */
 
483
        /* Make a 'tr' element. Store the filename and fileinfo in
 
484
         * here. */
483
485
        row = document.createElement("tr");
 
486
        row.filename = filename;
 
487
        row.fileinfo = file;
484
488
        /* Column 1: Selection checkbox */
485
489
        row.setAttribute("class", "row" + row_toggle.toString())
486
490
        row_toggle = row_toggle == 1 ? 2 : 1;
550
554
        td.setAttribute("onclick", selection_string);
551
555
        row.appendChild(td);
552
556
        files.appendChild(row);
553
 
        i++;
554
557
    }
555
558
 
556
559
    /* Do a selection update (create initial elements for side panel and