diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-06 06:33:17 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-06 06:33:17 -0700 |
commit | 8131e6fa380d52faa7c1dc9a59c2e83a4adb9134 (patch) | |
tree | 87f87c7da29d66c681908c90396f99df0c72648b /modules | |
parent | 26362ae7e2917a33858ebde7274ccb0f90351293 (diff) |
Tighten up the code by loading all the albums in the tree at once, removing
the events to populate the button bar.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/organize/controllers/organize.php | 67 | ||||
-rw-r--r-- | modules/organize/helpers/organize.php | 94 | ||||
-rw-r--r-- | modules/organize/js/organize.js | 47 | ||||
-rw-r--r-- | modules/organize/views/organize_button_pane.html.php | 5 | ||||
-rw-r--r-- | modules/organize/views/organize_dialog.html.php | 9 | ||||
-rw-r--r-- | modules/organize/views/organize_tree.html.php | 17 |
6 files changed, 35 insertions, 204 deletions
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index cbaaca6e..95d71e9c 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -23,21 +23,20 @@ class Organize_Controller extends Controller { function index($item_id) { $item = ORM::factory("item", $item_id); - $root = ($item->id == 1) ? $item : ORM::factory("item", 1); + $root = $item->id == 1 ? $item : ORM::factory("item", 1); access::required("view", $item); access::required("edit", $item); $v = new View("organize_dialog.html"); - $v->root = $root; - $v->item = $item; - $v->album_tree = $this->_tree($item, $root); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); - $v->button_pane = new View("organize_button_pane.html"); - $buttons = (object)array("left" => array(), "middle" =>array(), "right" => array(), - "item" => $item); - module::event("organize_format_button_pane", $buttons); + $v->title = $item->title; + $parents = array(); + foreach ($item->parents() as $parent) { + $parents[$parent->id] = 1; + } + $parents[$item->id] = 1; - $v->button_pane->buttons = $buttons; + $v->album_tree = $this->_tree($root, $parents); + $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); print $v; } @@ -50,28 +49,6 @@ class Organize_Controller extends Controller { print $v->__toString(); } - function children($item_id) { - $item = ORM::factory("item", $item_id); - access::required("view", $item); - access::required("edit", $item); - - $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); - - $children = ""; - foreach ($albums as $album) { - $v = new View("organize_tree.html"); - $v->album = $album; - $v->selected = false; - $v->children = array(); - $v->album_icon = - $album->children_count(array("type" => "album")) ? "ui-icon-plus" : "gBranchEmpty"; - - $children .= $v->__toString(); - } - - print $children; - } - private function _get_micro_thumb_grid($item, $offset=0) { $v = new View("organize_thumb_grid.html"); $v->item_id = $item->id; @@ -82,28 +59,20 @@ class Organize_Controller extends Controller { return $v; } - private function _tree($item, $parent, $depth=0) { - $albums = $parent->children(null, 0, array("type" => "album"), array("title" => "ASC")); - + private function _tree($item, $parents) { $v = new View("organize_tree.html"); - $v->album = $parent; - - if ($parent->id == $item->id) { - $v->selected = true; - $depth = 1; - } else { - $v->selected = false; - } + $v->album = $item; + $keys = array_keys($parents); + $v->selected = end($keys) == $item->id; $v->children = array(); $v->album_icon = "gBranchEmpty"; + + $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); if ($albums->count()) { - $v->album_icon = "ui-icon-plus"; + $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; - if ($depth <= 1) { - $v->album_icon = "ui-icon-minus"; - foreach ($albums as $album) { - $v->children[] = $this->_tree($item, $album, ++$depth); - } + foreach ($albums as $album) { + $v->children[] = $this->_tree($album, $parents); } } return $v; diff --git a/modules/organize/helpers/organize.php b/modules/organize/helpers/organize.php deleted file mode 100644 index 25284771..00000000 --- a/modules/organize/helpers/organize.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access."); -/** - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2009 Bharat Mediratta - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. - */ -class organize_Core { - static function get_general_edit_form($item) { - $generalPane = new Forge("organize/__FUNCTION__", "", "post", - array("id" => "gEditGeneral", "ref" => "general")); - // In this case we know there is only 1 item, but in general we should loop - // and create multiple hidden items. - $generalPane->hidden("item[]")->value($item->id); - $generalPane->input("title")->label(t("Title"))->value($item->title); - $generalPane->textarea("description")->label(t("Description"))->value($item->description); - $generalPane->input("dirname")->label(t("Path Name"))->value($item->name) - ->callback("item::validate_no_slashes") - ->error_messages("no_slashes", t("The directory name can't contain a \"/\"")) - ->callback("item::validate_no_trailing_period") - ->error_messages("no_trailing_period", t("The directory name can't end in \".\"")) - ->callback("item::validate_no_name_conflict") - ->error_messages("conflict", t("The path name is not unique")); - - return $generalPane; - } - - static function get_sort_edit_form($item) { - $sortPane = new Forge("organize/__FUNCTION__", "", "post", - array("id" => "gEditSort", "ref" => "sort")); - $sortPane->hidden("item[]")->value($item->id); - $sortPane->dropdown("column", array("id" => "gAlbumSortColumn")) - ->label(t("Sort by")) - ->options(array("weight" => t("Order Added"), - "captured" => t("Capture Date"), - "created" => t("Creation Date"), - "title" => t("Title"), - "updated" => t("Updated Date"), - "view_count" => t("Number of views"), - "rand_key" => t("Random"))) - ->selected($item->sort_column); - $sortPane->dropdown("direction", array("id" => "gAlbumSortDirection")) - ->label(t("Order")) - ->options(array("ASC" => t("Ascending"), - "DESC" => t("Descending"))) - ->selected($item->sort_order); - - return $sortPane; - } - - static function get_tag_form($itemids) { - $tagPane = new Forge("organize/__FUNCTION__", "", "post", - array("id" => "gEditTags", "ref" => "edit_tags")); - $tagPane->hidden("item")->value(implode("|", $itemids)); - $item_count = count($itemids); - $ids = implode(", ", $itemids); - - // Lame stopgap security check. This code is going to get rewritten anyway. - foreach ($itemids as $id) { - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("edit", $item); - } - - $tags = Database::instance()->query( - "SELECT t.name, COUNT(it.item_id) as count - FROM {items_tags} it, {tags} t - WHERE it.tag_id = t.id - AND it.item_id in($ids) - GROUP BY it.tag_id - ORDER BY t.name ASC"); - $taglist = array(); - foreach ($tags as $tag) { - $taglist[] = $tag->name . ($item_count > $tag->count ? "*" : ""); - } - $taglist = implode("; ", $taglist); - $tagPane->textarea("tags")->label(t("Tags"))->value($taglist); - - return $tagPane; - } - -}
\ No newline at end of file diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 12712ff1..0a7576b0 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -12,7 +12,6 @@ $("body").append('<div id="gOrganizeDialog"></div>'); $("#gOrganizeDialog").dialog(opts); - // Pass the approx height and width of the thumb grid to optimize thumb retrieval $.get(href, _init); return false; }); @@ -45,8 +44,7 @@ var heightMicroThumbPanel = $("#gOrganizeDialog").innerHeight(); heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom")); - heightMicroThumbPanel -= $("#gMessage").outerHeight(); - heightMicroThumbPanel = Math.floor(heightMicroThumbPanel); + heightMicroThumbPanel = Math.floor(heightMicroThumbPanel - 10 - $("#gMessage").outerHeight()); $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight(); @@ -65,15 +63,6 @@ $(".gBranchText span").click(_collapse_or_expanded_tree); $(".gBranchText").click(_setContents); - $(".gAlbum img.gThumbnail").live("dblclick", _openAlbum); - - //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); - //$(".gBranchText").droppable(treeDroppable); - - //$("#gMicroThumbPanel").droppable(thumbDroppable); - //$("#gMicroThumbPanel").selectable(selectable); - //$("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick); - }; function _dialog_close(event) { @@ -86,26 +75,12 @@ */ function _collapse_or_expanded_tree(event) { event.stopPropagation(); - var id = $(event.currentTarget).attr("ref"); if ($(event.currentTarget).hasClass("ui-icon-minus")) { - $(event.currentTarget).removeClass("ui-icon-minus"); - $(event.currentTarget).addClass("ui-icon-plus"); - $("#gOrganizeChildren-" + id).hide(); + $(event.currentTarget).removeClass("ui-icon-minus").addClass("ui-icon-plus"); } else { - if ($("#gOrganizeChildren-" + id).is("div")) { - $("#gOrganizeChildren-" + id).remove(); - $("#gOrganizeBranch-" + id).after("<ul id=\"gOrganizeChildren-" + id + "></ul>"); - var url = $("#gOrganizeAlbumTree").attr("ref").replace("__ITEM_ID__", id); - $.get(url, function(data) { - $("#gOrganizeChildren-" + id).html(data); - $(".gBranchText span").click(_collapse_or_expanded_tree); - $(".gBranchText").click(_setContents); - }); - } - $("#gOrganizeChildren-" + id).show(); - $(event.currentTarget).removeClass("ui-icon-plus"); - $(event.currentTarget).addClass("ui-icon-minus"); + $(event.currentTarget).removeClass("ui-icon-plus").addClass("ui-icon-minus"); } + $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); } /** @@ -118,26 +93,12 @@ } var id = $(event.currentTarget).attr("ref"); $(".gBranchSelected").removeClass("gBranchSelected"); - $(event.currentTarget).addClass("gBranchSelected"); - var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); - $.get(url, function(data) { - $("#gMicroThumbGrid").html(data); - }); - } - - function _openAlbum(event) { - event.preventDefault(); - var id = $(event.target).parent().attr("ref"); - $(".gBranchSelected").removeClass("gBranchSelected"); $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); - // @todo load the branch elements if required. $.get(url, function(data) { $("#gMicroThumbGrid").html(data); - // $(".gAlbum img.gThumbnail").dblclick(_openAlbum); }); } - })(jQuery); $("document").ready(function() { diff --git a/modules/organize/views/organize_button_pane.html.php b/modules/organize/views/organize_button_pane.html.php deleted file mode 100644 index 8eced107..00000000 --- a/modules/organize/views/organize_button_pane.html.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<div id="gOrganizeEditHandleButtonsRight"> - <a id="gMicroThumbDone" href="#" ref="done" - class="gButtonLink ui-corner-all ui-state-default"><?= t("Close") ?></a> -</div> diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 1e6646e4..4f10297e 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <div id="gOrganize"> - <h1 style="display:none"><?= t("Organize %name", array("name" => p::purify($item->title))) ?></h1> + <h1 style="display:none"><?= t("Organize %name", array("name" => p::purify($title))) ?></h1> <div id="bd"> <div class="yui-gf"> <div class="yui-u first"> @@ -12,7 +12,7 @@ </div> <div class="yui-gf"> <div id="gOrganizeTreeContainer" class="yui-u first"> - <ul id="gOrganizeAlbumTree" ref="<?= url::site("organize/children/__ITEM_ID__") ?>"> + <ul id="gOrganizeAlbumTree"> <?= $album_tree ?> </ul> </div> @@ -27,7 +27,10 @@ <div id="gOrganizeEditDrawerPanel" class="yui-gf"> </div> <div id="gOrganizeEditDrawerHandle"> - <?= $button_pane ?> + <div id="gOrganizeEditHandleButtonsRight"> + <a id="gMicroThumbDone" href="#" ref="done" + class="gButtonLink ui-corner-all ui-state-default"><?= t("Close") ?></a> + </div> </div> </div> </div> diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index d64410d8..280bdc5f 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -8,15 +8,12 @@ </span> <?= p::clean($album->title) ?> </div> - <? if (empty($children)): ?> - <div id="gOrganizeChildren-<?= $album->id ?>"></div> - <? else: ?> - <ul id="gOrganizeChildren-<?= $album->id ?>" - class="<?= $album_icon == "ui-icon-plus" ? "gBranchCollapsed" : "" ?>"> - <? foreach ($children as $child): ?> - <?= $child ?> - <? endforeach ?> - </ul> - <? endif ?> + <ul id="gOrganizeChildren-<?= $album->id ?>" + class="<?= $album_icon == "ui-icon-plus" ? "gBranchCollapsed" : "" ?>"> + <li style="display:none"> </li> + <? foreach ($children as $child): ?> + <?= $child ?> + <? endforeach ?> + </ul> </li> |