diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-08-30 14:35:27 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-08-30 14:35:27 -0700 |
commit | d1ade6620e814ecf536dfde17c95593a311d1c2c (patch) | |
tree | 9be6f4d5e884affd81c02ec0b3468545f9b6431b | |
parent | fd954fe86e2852c245dd599f9476fdf8ea3642e4 (diff) |
Precalculate the organize tree based on the selected album and render
it right away while still allowing incremental tree loading.
-rw-r--r-- | modules/organize/controllers/organize.php | 17 | ||||
-rw-r--r-- | modules/organize/views/organize_tree.html.php | 9 |
2 files changed, 20 insertions, 6 deletions
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 3cbcfb28..24e5bf97 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -25,7 +25,7 @@ class Organize_Controller extends Controller { $v = new View("organize_dialog.html"); $v->album = $album; - $v->album_tree = self::_tree(ORM::factory("item", 1)); + $v->album_tree = self::_expanded_tree(ORM::factory("item", 1), $album); $v->micro_thumb_grid = self::_get_micro_thumb_grid($album, 0); print $v; } @@ -50,7 +50,7 @@ class Organize_Controller extends Controller { } print json_encode( - array("tree" => self::_tree(ORM::factory("item", 1))->__toString(), + array("tree" => self::_expanded_tree(ORM::factory("item", 1), $album)->__toString(), "grid" => self::_get_micro_thumb_grid($album, 0)->__toString())); } @@ -135,12 +135,19 @@ class Organize_Controller extends Controller { public function tree($album_id) { $album = ORM::factory("item", $album_id); access::required("view", $album); - print self::_tree($album); + + print self::_expanded_tree($album, $album); } - private static function _tree($album) { + /** + * Create an HTML representation of the tree from the root down to the selected album. We only + * include albums along the descendant hierarchy that includes the selected album, and the + * immediate child albums. + */ + private static function _expanded_tree($root, $selected_album) { $v = new View("organize_tree.html"); - $v->album = $album; + $v->album = $root; + $v->selected = $selected_album; return $v; } } diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 4677234c..a99d2337 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -3,11 +3,17 @@ ref="<?= $album->id ?>"> <span class="ui-icon ui-icon-minus"> </span> - <span class="gAlbumText" ref="<?= $album->id ?>"> + <span class="gAlbumText + <?= $album->id == $selected->id ? "selected" : "" ?> + " + ref="<?= $album->id ?>"> <?= p::clean($album->title) ?> </span> <ul> <? foreach ($album->children(null, 0, array("type" => "album")) as $child): ?> + <? if ($child->is_descendant($selected)): ?> + <?= View::factory("organize_tree.html", array("selected" => $selected, "album" => $child)); ?> + <? else: ?> <li class="gOrganizeAlbum ui-icon-left <?= access::can("edit", $child) ? "" : "gViewOnly" ?>" ref="<?= $child->id ?>"> <span class="ui-icon ui-icon-plus"> @@ -16,6 +22,7 @@ <?= p::clean($child->title) ?> </span> </li> + <? endif ?> <? endforeach ?> </ul> </li> |