From 65c850c393ce6159289e3fd05056c33e7d62e961 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 10:26:11 -0700 Subject: Revert "Revert "Checkpoint the organize module rewrite. At this point, it doesn't really do"" This reverts commit 397468c47b8fc3fefeb54ff19a73980ed1dd8c20. --- modules/organize/helpers/organize_task.php | 131 ---------------------------- modules/organize/helpers/organize_theme.php | 3 +- 2 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 modules/organize/helpers/organize_task.php (limited to 'modules/organize/helpers') diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php deleted file mode 100644 index dc474818..00000000 --- a/modules/organize/helpers/organize_task.php +++ /dev/null @@ -1,131 +0,0 @@ -context); - $taskType = $context["type"]; - - try { - $target = ORM::factory("item", $context["target"]); - $total = count($context["items"]); - $stop = min($total - $context["position"], $context["batch"]); - $context["post_process"] = array(); - for ($offset = 0; $offset < $stop; $offset++) { - $current_id = $context["position"] + $offset; - $id = $context["items"][$current_id]; - switch ($taskType) { - case "move": - $source = ORM::factory("item", $id); - access::required("view", $source); - access::required("view", $target); - access::required("edit", $source); - access::required("edit", $target); - - item::move($source, $target); - break; - - case "rearrange": - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("edit", $item); - - Database::instance() - ->query("Update {items} set weight = {$context["position"]} where id=$id;"); - break; - - case "rotateCcw": - case "rotateCw": - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("edit", $item); - - if ($item->is_photo()) { - $context["post_process"]["reload"][] = - self::_do_rotation($item, $taskType == "rotateCcw" ? -90 : 90); - } - break; - - case "albumCover": - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("view", $item->parent()); - access::required("edit", $item->parent()); - - item::make_album_cover($item); - break; - - case "delete": - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("edit", $item); - - $item->delete(); - $context["post_process"]["remove"][] = array("id" => $id); - break; - - default: - throw new Exception("Task '$taskType' is not implemented"); - } - } - $context["position"] += $stop; - $task->state = "success"; - } catch(Exception $e) { - $task->status = $e->getMessage(); - $task->state = "error"; - $task->save(); - throw $e; - } - $task->context = serialize($context); - $total = count($context["items"]); - $task->percent_complete = $context["position"] / (float)$total * 100; - $task->done = $context["position"] == $total || $task->state == "error"; - } - - private static function _do_rotation($item, $degrees) { - // This code is copied from Quick_Controller::rotate - graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees)); - - list($item->width, $item->height) = getimagesize($item->file_path()); - $item->resize_dirty= 1; - $item->thumb_dirty= 1; - $item->save(); - - graphics::generate($item); - - $parent = $item->parent(); - if ($parent->album_cover_item_id == $item->id) { - copy($item->thumb_path(), $parent->thumb_path()); - $parent->thumb_width = $item->thumb_width; - $parent->thumb_height = $item->thumb_height; - $parent->save(); - } - list ($height, $width) = $item->scale_dimensions(90); - $margin_top = (90 - $height) / 20; - - return array("src" => $item->thumb_url() . "?rnd=" . rand(), - "id" => $item->id, - "marginTop" => "{$margin_top}em", "width" => $width, "height" => $height); - } -} \ No newline at end of file diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php index e4feba2b..f01ab88b 100644 --- a/modules/organize/helpers/organize_theme.php +++ b/modules/organize/helpers/organize_theme.php @@ -19,8 +19,7 @@ */ class organize_theme { static function head($theme) { - // @tdo remove the addition css and organize.js (just here to test) - $theme->script("organize_init.js"); + //$theme->script("organize_init.js"); $theme->script("organize.js"); $theme->css("organize.css"); } -- cgit v1.2.3 From 8131e6fa380d52faa7c1dc9a59c2e83a4adb9134 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 6 Aug 2009 06:33:17 -0700 Subject: Tighten up the code by loading all the albums in the tree at once, removing the events to populate the button bar. --- modules/organize/controllers/organize.php | 67 +++++---------- modules/organize/helpers/organize.php | 94 ---------------------- modules/organize/js/organize.js | 47 +---------- .../organize/views/organize_button_pane.html.php | 5 -- modules/organize/views/organize_dialog.html.php | 9 ++- modules/organize/views/organize_tree.html.php | 17 ++-- 6 files changed, 35 insertions(+), 204 deletions(-) delete mode 100644 modules/organize/helpers/organize.php delete mode 100644 modules/organize/views/organize_button_pane.html.php (limited to 'modules/organize/helpers') 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 @@ - "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('
'); $("#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(""); - 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 @@ - -
- -
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 @@
-

p::purify($item->title))) ?>

+

p::purify($title))) ?>

@@ -12,7 +12,7 @@
-
    "> +
@@ -27,7 +27,10 @@
- +
+ +
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 @@ title) ?>
- -
- -
    "> - - - -
- +
    "> +
  •  
  • + + + +
-- cgit v1.2.3 From 794a7a5abf38ed828329cb0023df938479e90901 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 6 Aug 2009 14:55:03 -0700 Subject: Leverage the gallery.dialog/js functionality in order to reduce duplicate code --- modules/organize/helpers/organize_event.php | 2 +- modules/organize/helpers/organize_theme.php | 7 +- modules/organize/js/organize.js | 131 +++++++++--------------- modules/organize/views/organize_dialog.html.php | 10 ++ 4 files changed, 61 insertions(+), 89 deletions(-) (limited to 'modules/organize/helpers') diff --git a/modules/organize/helpers/organize_event.php b/modules/organize/helpers/organize_event.php index 99a28673..887d9c2d 100644 --- a/modules/organize/helpers/organize_event.php +++ b/modules/organize/helpers/organize_event.php @@ -23,7 +23,7 @@ class organize_event_Core { if ($item && access::can("edit", $item) && $item->is_album()) { $menu->get("options_menu") - ->append(Menu::factory("link") + ->append(Menu::factory("dialog") ->id("organize") ->label(t("Organize Album")) ->css_id("gOrganizeLink") diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php index f01ab88b..0fd117c3 100644 --- a/modules/organize/helpers/organize_theme.php +++ b/modules/organize/helpers/organize_theme.php @@ -19,8 +19,9 @@ */ class organize_theme { static function head($theme) { - //$theme->script("organize_init.js"); - $theme->script("organize.js"); - $theme->css("organize.css"); + if (access::can("view", $theme->item()) && access::can("edit", $theme->item())) { + $theme->script("organize.js"); + $theme->css("organize.css"); + } } } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 3e58f3f3..e4d4a9a2 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,91 +1,52 @@ (function($) { - $.fn.organize = function() { - var size = $.getViewportSize(); - var height = size.height() - 100; // Leave 50 pixels on the top and bottom of the dialog - var width = size.width() - 100; // Leave 50 pixels on the left and right of the dialog - return this.each(function() { - $(this).click(function(event) { - var href = event.target.href; - - $("body").append('
'); - - $("#gOrganizeDialog").dialog({ - autoOpen: false, - modal: true, - resizable: false, - width: width, - height: height, - position: "center", - close: function () { - $("#gOrganizeDialog").dialog("destroy").remove(); - document.location.reload(); - }, - zIndex: 75 - }); - $.get(href, _init); - return false; + $.organize = { + /** + * Dynamically initialize the organize dialog when it is displayed + */ + init: function(data) { + // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) + $(".sf-menu li.sfHover ul").css("z-index", 70); + + var height = $("#gOrganizeDetail").innerHeight(); + $("#gMicroThumbPanel").height(height - $("#gOrganizeEditDrawerHandle").outerHeight()); + + $("#gDialog #gMicroThumbDone").click(function(event) { + $("#gDialog").dialog("close"); + window.location.reload(); }); - }); - }; - - /** - * Dynamically initialize the organize dialog when it is displayed - */ - function _init(data) { - // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) - $(".sf-menu li.sfHover ul").css("z-index", 70); - $("#gOrganizeDialog").html(data); - $("#gOrganizeDialog").dialog("open"); - - var height = $("#gOrganizeDetail").innerHeight(); - $("#gMicroThumbPanel").height(height - $("#gOrganizeEditDrawerHandle").outerHeight()); - - if ($("#gOrganizeDialog h1").length) { - $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog h1:eq(0)").html()); - } else if ($("#gOrganizeDialog fieldset legend").length) { - $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog fieldset legend:eq(0)").html()); + $(".gBranchText span").click($.organize.collapse_or_expand_tree); + $(".gBranchText").click($.organize.setContents); + }, + + /** + * Open or close a branch. If the children is a div placeholder, replace with
    + */ + collapse_or_expand_tree: function (event) { + event.stopPropagation(); + if ($(event.currentTarget).hasClass("ui-icon-minus")) { + $(event.currentTarget).removeClass("ui-icon-minus").addClass("ui-icon-plus"); + } else { + $(event.currentTarget).removeClass("ui-icon-plus").addClass("ui-icon-minus"); + } + $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); + }, + + /** + * When the text of a selection is clicked, then show that albums contents + */ + setContents: function(event) { + event.preventDefault(); + if ($(event.currentTarget).hasClass("gBranchSelected")) { + return; + } + var id = $(event.currentTarget).attr("ref"); + $(".gBranchSelected").removeClass("gBranchSelected"); + $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); + var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); + $.get(url, function(data) { + $("#gMicroThumbGrid").html(data); + }); } - - $("#gOrganizeDialog #gMicroThumbDone").click(function(event) { - $("#gOrganizeDialog").dialog("close"); - }); - - $(".gBranchText span").click(_collapse_or_expanded_tree); - $(".gBranchText").click(_setContents); }; - - /** - * Open or close a branch. If the children is a div placeholder, replace with
      - */ - function _collapse_or_expanded_tree(event) { - event.stopPropagation(); - if ($(event.currentTarget).hasClass("ui-icon-minus")) { - $(event.currentTarget).removeClass("ui-icon-minus").addClass("ui-icon-plus"); - } else { - $(event.currentTarget).removeClass("ui-icon-plus").addClass("ui-icon-minus"); - } - $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); - } - - /** - * When the text of a selection is clicked, then show that albums contents - */ - function _setContents(event) { - event.preventDefault(); - if ($(event.currentTarget).hasClass("gBranchSelected")) { - return; - } - var id = $(event.currentTarget).attr("ref"); - $(".gBranchSelected").removeClass("gBranchSelected"); - $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); - var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); - $.get(url, function(data) { - $("#gMicroThumbGrid").html(data); - }); - } })(jQuery); - -$("document").ready(function() { - $("#gOrganizeLink").organize(); -}); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 4f10297e..11ce0a37 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -38,3 +38,13 @@
+ \ No newline at end of file -- cgit v1.2.3 From a245c57400398d2b4b1c2aea94f590a9c0a7d8a8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 6 Aug 2009 21:36:17 -0700 Subject: Further streamline the code. Organize_Controller: * Remove unnecessary constants * Rename index() to dialog() * Simplify _get_micro_thumb_grid organize.js: * Move sizing code in here from organize_dialog.html.php organize_dialog.html.php: * Move CSS and JS links in here so that we only load them when we need them. * Move sizing code into organize.js organize_thumb_grid.html.php: * Move pagination logic in here, since it's view centric * Collapse the css class determination code and inline it --- modules/organize/controllers/organize.php | 22 +++++---------- modules/organize/helpers/organize_event.php | 2 +- modules/organize/helpers/organize_theme.php | 27 ------------------- modules/organize/js/organize.js | 6 +++++ modules/organize/views/organize_dialog.html.php | 9 +++---- .../organize/views/organize_thumb_grid.html.php | 31 +++++++++++----------- modules/organize/views/organize_tree.html.php | 2 -- 7 files changed, 33 insertions(+), 66 deletions(-) delete mode 100644 modules/organize/helpers/organize_theme.php (limited to 'modules/organize/helpers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 95d71e9c..3a81ef4f 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -18,10 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Organize_Controller extends Controller { - private static $_MICRO_THUMB_SIZE = 90; - private static $_MICRO_THUMB_PADDING = 10; - - function index($item_id) { + function dialog($item_id) { $item = ORM::factory("item", $item_id); $root = $item->id == 1 ? $item : ORM::factory("item", 1); access::required("view", $item); @@ -36,26 +33,21 @@ class Organize_Controller extends Controller { $parents[$item->id] = 1; $v->album_tree = $this->_tree($root, $parents); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); + $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item, 0); print $v; } - function content($item_id, $offset=0) { + function content($item_id, $offset) { $item = ORM::factory("item", $item_id); access::required("view", $item); access::required("edit", $item); - - $v = $this->_get_micro_thumb_grid($item, $offset); - print $v->__toString(); + print $this->_get_micro_thumb_grid($item, $offset); } - private function _get_micro_thumb_grid($item, $offset=0) { + private function _get_micro_thumb_grid($item, $offset) { $v = new View("organize_thumb_grid.html"); - $v->item_id = $item->id; - $v->children = $item->children(25, $offset); - $v->thumbsize = self::$_MICRO_THUMB_SIZE; - $v->offset = $offset + 25; - + $v->item = $item; + $v->offset = $offset; return $v; } diff --git a/modules/organize/helpers/organize_event.php b/modules/organize/helpers/organize_event.php index 887d9c2d..7d6b3e24 100644 --- a/modules/organize/helpers/organize_event.php +++ b/modules/organize/helpers/organize_event.php @@ -27,7 +27,7 @@ class organize_event_Core { ->id("organize") ->label(t("Organize Album")) ->css_id("gOrganizeLink") - ->url(url::site("organize/index/{$item->id}"))); + ->url(url::site("organize/dialog/{$item->id}"))); } } } diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php deleted file mode 100644 index 0fd117c3..00000000 --- a/modules/organize/helpers/organize_theme.php +++ /dev/null @@ -1,27 +0,0 @@ -item()) && access::can("edit", $theme->item())) { - $theme->script("organize.js"); - $theme->css("organize.css"); - } - } -} diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index d2006c27..6b4a5934 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -4,6 +4,12 @@ * Dynamically initialize the organize dialog when it is displayed */ init: function(data) { + // Resize with 50 pixels padding all around + var size = $.getViewportSize(); + $("#gDialog").dialog("option", "height", size.height() - 100) + .dialog("option", "width", size.width() - 100) + .dialog("option", "position", "center"); + // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) $(".sf-menu li.sfHover ul").css("z-index", 70); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 11ce0a37..6001e038 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,4 +1,5 @@ +" />

p::purify($title))) ?>

@@ -38,13 +39,9 @@
+ \ No newline at end of file + diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index e6b7aec0..0d54c5c8 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,19 +1,20 @@ - $child): ?> - - is_album()): ?> - - -
  • - thumb_img(array("class" => "gThumbnail"), $thumbsize, true) ?> -
  • +children(25, $offset) as $child): ?> +
  • " + ref="id ?>"> + thumb_img(array("class" => "gThumbnail"), 90, true) ?> +
  • -= 25): ?> + +children_count() > $offset): ?> - \ No newline at end of file + diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 280bdc5f..99b0dc1a 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,6 +1,5 @@
  • -
    gBranchText">
  • - -- cgit v1.2.3 From 3823f65dfb4114caf9bd9cfbf730638927f6c970 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 12 Aug 2009 21:55:25 -0700 Subject: Implement the first part of drag functionality. Having trouble getting visual feedback of the drop position between thumbnails, so this commit provides a checkpoint for trying various options --- modules/organize/controllers/organize.php | 9 +-- modules/organize/css/organize.css | 9 ++- modules/organize/helpers/organize_theme.php | 28 +++++++++ modules/organize/js/organize.js | 73 +++++++++++++++++++++- modules/organize/views/organize_dialog.html.php | 4 +- .../organize/views/organize_thumb_grid.html.php | 2 +- modules/organize/views/organize_tree.html.php | 4 +- 7 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 modules/organize/helpers/organize_theme.php (limited to 'modules/organize/helpers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 3a81ef4f..6f83f940 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -60,13 +60,14 @@ class Organize_Controller extends Controller { $v->album_icon = "gBranchEmpty"; $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); - if ($albums->count()) { - $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; - - foreach ($albums as $album) { + foreach ($albums as $album) { + if (access::can("view", $album)) { $v->children[] = $this->_tree($album, $parents); } } + if (count($v->children)) { + $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; + } return $v; } } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index a4b5fdbd..1cc7c92c 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -1,3 +1,4 @@ + /******************************************************************* * Dialog wide stylings */ @@ -92,7 +93,7 @@ } #gMicroThumbGrid { - padding: .5em; + padding: 1em; } .gMicroThumb { @@ -107,10 +108,14 @@ width: 9em; } -.gMicroThumb.ui-selected { +.gMicroThumb.ui-state-selected { opacity: 1; } +.ui-selectable-lasso { + z-index: 2000 !important; + border: 1px dashed #13A; +} .gThumbnail { padding: .5em; diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php new file mode 100644 index 00000000..de812261 --- /dev/null +++ b/modules/organize/helpers/organize_theme.php @@ -0,0 +1,28 @@ +item(); + if ($item && access::can("edit", $item) && $item->is_album()) { + $theme->script("organize.js"); + $theme->css("organize.css"); + } + } +} diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 05693200..c9408673 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,15 +1,83 @@ (function($) { $.organize = { + micro_thumb_draggable: { + distance: 10, + cursorAt: { left: -10, top: -10}, + appendTo: "#gOrganizeContentPane", + helper: function(event, ui) { + var selected = $("li.ui-state-selected img"), + set = $('
    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), + offset = $(this).offset(), + click = { left: event.pageX - offset.left, top: event.pageY - offset.top }; + + selected.each(function(i) { + var row = parseInt(i / 5); + var j = i - (row * 5); + + var o = $(this).offset(); + + var copy = $(this).clone() + .css({ + width: $(this).width(), height: $(this).height(), display: "block", + margin: 0, position: 'absolute', outline: '5px solid #fff', + left: o.left - event.pageX, top: o.top - event.pageY + }) + .appendTo(set) + .animate({width: 10, height: 10, outlineWidth: 1, margin: 1, left: (20 * j), top: (row * 20)}, 500); + }); + return set; + }, + start: function(event, ui) { + $("#gMicroThumbPanel").prepend("
    "); + + $("#gMicroThumbPanel li.ui-state-selected").hide(); + }, + drag: function(event, ui) { + var container = $("#gMicroThumbPanel").get(0); + var scrollTop = container.scrollTop; + var height = $(container).height(); + if (event.pageY > height + scrollTop) { + container.scrollTop += height; + } else if (event.pageY < scrollTop) { + container.scrollTop -= height; + } + }, + stop: function(event, ui) { + $("li.ui-state-selected").show(); + } + }, + + droppable: { + accept: "*", + tolerance: "pointer", + greedy: true, + drop: function(event, ui) { + // @todo do a ajax call to send the rearrange request to the zerver + // organize/move/target_id/ + // post parameters + // before=id|after=id + // source=[id1, id2, ...] + // before or after not supplied then append to end + // return: json { + // result: success | msg, + // tree: null | new tree, + // content: new thumbgrid + // } + } + }, + /** * Dynamically initialize the organize dialog when it is displayed */ init: function(data) { + var self = this; // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) $(".sf-menu li.sfHover ul").css("z-index", 68); $("#gDialog").dialog("option", "zIndex", 70); $("#gDialog").bind("dialogopen", function(event, ui) { $("#gOrganize").height($("#gDialog").innerHeight() - 20); $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); + $("#gOrganizeAlbumTree").height($("#gDialog").innerHeight() - 59); }); $("#gDialog").bind("dialogclose", function(event, ui) { @@ -23,7 +91,10 @@ $(".gBranchText span").click($.organize.collapse_or_expand_tree); $(".gBranchText").click($.organize.show_album); - $("#gMicroThumbGrid").selectable({filter: ".gMicroThumb"}); + $("#gMicroThumbPanel").selectable({filter: "li"}); + $("#gMicroThumbPanel img").draggable($.organize.micro_thumb_draggable); + $(".gOrganizeBranch").droppable($.organize.droppable); + $("#gMicroThumbPanel").droppable($.organize.droppable); }, /** diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index b946d82b..f8d6d792 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,5 +1,4 @@ -" />

    p::purify($title))) ?>

    @@ -11,7 +10,7 @@
    -
    +
      @@ -39,7 +38,6 @@
    - diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index 0d54c5c8..b6e3aa11 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -3,7 +3,7 @@
  • " ref="id ?>"> - thumb_img(array("class" => "gThumbnail"), 90, true) ?> + thumb_img(array("class" => "gThumbnail", "ref" => $child->id), 90, true) ?>
  • diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 99b0dc1a..d2ef287a 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,11 +1,11 @@
  • gBranchText"> + class=""> - title) ?> + title) ?>
      "> -- cgit v1.2.3