From cb2171d0825251d619b53f6f80d217326fb6bab5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 28 Aug 2009 14:27:37 -0700 Subject: Display the sort order in the Organize dialog, and allow users to change the sort order on the fly. --- modules/organize/js/organize.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'modules/organize/js') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index ec6bd924..96309787 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -125,9 +125,8 @@ $("#gOrganize .gProgressBar").progressbar("value", data.percent_complete); if (data.done) { var height = $("#gOrganizeProgress").height(); - $("#gOrganizeProgress").toggle(); + $("#gOrganizeProgress").slideUp(); $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); - //$("#gMicroThumbPanel").height($("#gMicroThumbPanel").height() + height); if (data.tree) { $("#gOrganizeAlbumTree").html(data.tree); } @@ -171,10 +170,14 @@ window.location.reload(); }); - $("#gDialog #gMicroThumbDone").click(function(event) { + $("#gDialog #gOrganizeClose").click(function(event) { $("#gDialog").dialog("close"); }); + $("#gOrganizeSortColumn,#gOrganizeSortDir").change(function(event) { + $.organize.resort($("#gOrganizeSortColumn").attr("value"), $("#gOrganizeSortDir").attr("value")); + }); + $.organize.set_handlers(); }, @@ -219,6 +222,19 @@ $("#gMicroThumbGrid").html(data); $.organize.set_handlers(); }); + }, + + /** + * Change the sort order. + */ + resort: function(column, dir) { + var url = sort_order_url + .replace("__COL__", column) + .replace("__DIR__", dir); + $.get(url, function(data) { + $("#gMicroThumbGrid").html(data); + $.organize.set_handlers(); + }); } }; })(jQuery); -- cgit v1.2.3 From f257cd3d69a771ce245c432e37c9f9e7e53ad03d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 29 Aug 2009 10:00:47 -0700 Subject: Major refactor of organize: * Clean up naming conventions for variables in the controller so that we specifically refer to albums with $album_id, etc. * Move complexity for drawing tree out of the controller and into the view. * Simplify task definitions to get rid of extraneous text * Change __PLACEHOLDERS__ to clearly define which is the album and which is the item that we're moving before/after * Remove as many CSS ids as we can from the tree view to keep things simple --- modules/organize/controllers/organize.php | 127 +++++++++------------ modules/organize/css/organize.css | 17 +-- modules/organize/js/organize.js | 60 +++++----- modules/organize/views/organize_dialog.html.php | 9 +- .../organize/views/organize_thumb_grid.html.php | 6 +- modules/organize/views/organize_tree.html.php | 56 ++++++--- 6 files changed, 140 insertions(+), 135 deletions(-) (limited to 'modules/organize/js') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 10b109f6..f25a41ca 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -18,40 +18,35 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Organize_Controller extends Controller { - function dialog($item_id) { - $item = ORM::factory("item", $item_id); - $root = $item->id == 1 ? $item : ORM::factory("item", 1); - access::required("view", $item); - access::required("edit", $item); + function dialog($album_id) { + $album = ORM::factory("item", $album_id); + access::required("view", $album); + access::required("edit", $album); $v = new View("organize_dialog.html"); - $v->album = $item; - $parents = array(); - foreach ($item->parents() as $parent) { - $parents[$parent->id] = 1; - } - $parents[$item->id] = 1; - - $v->album_tree = self::_tree($root, $parents); - $v->micro_thumb_grid = self::_get_micro_thumb_grid($item, 0); + $v->album = $album; + $v->album_tree = self::_tree($album); + $v->micro_thumb_grid = self::_get_micro_thumb_grid($album, 0); print $v; } - function content($item_id, $offset) { - $item = ORM::factory("item", $item_id); - access::required("view", $item); - access::required("edit", $item); - print self::_get_micro_thumb_grid($item, $offset); + function album($album_id, $offset) { + $album = ORM::factory("item", $album_id); + access::required("view", $album); + access::required("edit", $album); + + print json_encode( + array("grid" => self::_get_micro_thumb_grid($album, $offset)->__toString(), + "sort_column" => $album->sort_column, + "sort_order" => $album->sort_order)); } - function move($target_id) { + function move_to($album_id) { access::verify_csrf(); $task_def = Task_Definition::factory() - ->callback("Organize_Controller::move_task_handler") - ->description(t("Move images")) - ->name(t("Move Images")); - $task = task::create($task_def, array("target_id" => $target_id, + ->callback("Organize_Controller::move_task_handler"); + $task = task::create($task_def, array("album_id" => $album_id, "source_ids" => $this->input->post("source_ids"))); print json_encode( @@ -62,20 +57,19 @@ class Organize_Controller extends Controller { function rearrange($target_id, $before_or_after) { access::verify_csrf(); + $target = ORM::factory("item", $target_id); $parent = $target->parent(); access::required("view", $parent); access::required("edit", $parent); $task_def = Task_Definition::factory() - ->callback("Organize_Controller::rearrange_task_handler") - ->description(t("Rearrange Image")) - ->name(t("Rearrange Images")); + ->callback("Organize_Controller::rearrange_task_handler"); $task = task::create( $task_def, array("target_id" => $target_id, + "album_id" => $parent->id, "before_or_after" => $before_or_after, - "parent_id" => $parent->id, "source_ids" => $this->input->post("source_ids"))); print json_encode( @@ -84,10 +78,10 @@ class Organize_Controller extends Controller { "url" => url::site("organize/run/$task->id?csrf=" . access::csrf_token()))); } - function resort($target_id, $col, $dir) { + function sort_order($album_id, $col, $dir) { access::verify_csrf(); - $album = ORM::factory("item", $target_id); + $album = ORM::factory("item", $album_id); access::required("view", $album); access::required("edit", $album); @@ -100,12 +94,15 @@ class Organize_Controller extends Controller { $album->sort_order = $dir; $album->save(); - print self::_get_micro_thumb_grid($album, 0); + print json_encode( + array("grid" => self::_get_micro_thumb_grid($album, 0)->__toString(), + "sort_column" => $album->sort_column, + "sort_order" => $album->sort_order)); } - private static function _get_micro_thumb_grid($item, $offset) { + private static function _get_micro_thumb_grid($album, $offset) { $v = new View("organize_thumb_grid.html"); - $v->item = $item; + $v->album = $album; $v->offset = $offset; return $v; } @@ -124,33 +121,23 @@ class Organize_Controller extends Controller { $task = task::run($task_id); $results = array("done" => $task->done, "status" => $task->status, "percent_complete" => $task->percent_complete); - foreach (array("tree", "content") as $data) { - $value = $task->get($data, false); - if ($value !== false) { - $results[$data] = $value; - } + + $album = ORM::factory("item", $task->get("album_id")); + $result = array( + "done" => $task->done, + "status" => $task->status, + "percent_complete" => $task->percent_complete); + if ($task->done) { + $result["tree"] = self::_tree($album)->__toString(); + $result["grid"] = self::_get_micro_thumb_grid($album, 0)->__toString(); } - print json_encode($results); + print json_encode($result); } - private static function _tree($item, $parents) { + private static function _tree($album) { $v = new View("organize_tree.html"); - $v->album = $item; - $keys = array_keys($parents); - $v->selected = end($keys) == $item->id; - $v->can_edit= access::can("edit", $item); - $v->children = array(); - $v->album_icon = "gBranchEmpty"; - - $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); - foreach ($albums as $album) { - if (access::can("view", $album)) { - $v->children[] = self::_tree($album, $parents); - } - } - if (count($v->children)) { - $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; - } + $v->parents = $album->parents(); + $v->album = $album; return $v; } @@ -160,30 +147,25 @@ class Organize_Controller extends Controller { batch::start(); } - $target = ORM::factory("item", $task->get("target_id")); + $target_album = ORM::factory("item", $task->get("album_id")); $source_ids = $task->get("source_ids", array()); $idx = $task->get("current", 0); $count = 0; for (; $idx < count($source_ids) && microtime(true) - $start < 0.5; $idx++) { - item::move(ORM::factory("item", $source_ids[$idx]), $target); + item::move(ORM::factory("item", $source_ids[$idx]), $target_album); $count++; } $task->set("current", $idx); $task->percent_complete = (int)($idx / count($source_ids) * 100); - $task->status = t2("Moved one file", "Moved %count files", $count); if ($task->percent_complete == 100) { batch::stop(); $task->done = true; $task->state = "success"; $parents = array(); - foreach ($target->parents() as $parent) { + foreach ($target_album->parents() as $parent) { $parents[$parent->id] = 1; } - $parents[$target->id] = 1; - // @TODO do we want to set a flag and then generate them in the run method so we don't - // potentially store large data items in the task? - $task->set("tree", self::_tree(ORM::factory("item", 1), $parents)->__toString()); - $task->set("content", self::_get_micro_thumb_grid($target, 0)->__toString()); + $parents[$target_album->id] = 1; } } @@ -197,7 +179,7 @@ class Organize_Controller extends Controller { while (microtime(true) - $start < 1.5) { switch ($mode) { case "init": - $album = ORM::factory("item", $task->get("parent_id")); + $album = ORM::factory("item", $task->get("album_id")); if ($album->sort_column != "weight") { $mode = "convert-to-weight-order"; } else { @@ -207,7 +189,7 @@ class Organize_Controller extends Controller { case "convert-to-weight-order": $i = 0; - $album = ORM::factory("item", $task->get("parent_id")); + $album = ORM::factory("item", $task->get("album_id")); foreach ($album->children() as $child) { // Do this directly in the database to avoid sending notifications Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id)); @@ -220,8 +202,8 @@ class Organize_Controller extends Controller { break; case "find-insertion-point": - $target = ORM::factory("item", $task->get("target_id")); - $target_weight = $target->weight; + $album = ORM::factory("item", $task->get("album_id")); + $target_weight = $album->weight; if ($task->get("before_or_after") == "after") { $target_weight++; @@ -235,11 +217,11 @@ class Organize_Controller extends Controller { $target_weight = $task->get("target_weight"); $source_ids = $task->get("source_ids"); $count = count($source_ids); - $parent_id = $task->get("parent_id"); + $album_id = $task->get("album_id"); Database::Instance()->query( "UPDATE {items} " . "SET `weight` = `weight` + $count " . - "WHERE `weight` >= $target_weight AND `parent_id` = {$parent_id}"); + "WHERE `weight` >= $target_weight AND `parent_id` = {$album_id}"); $mode = "insert-source-items"; $task->percent_complete = 80; @@ -255,13 +237,12 @@ class Organize_Controller extends Controller { break; case "done": - $album = ORM::factory("item", $task->get("parent_id")); + $album = ORM::factory("item", $task->get("album_id")); module::event("album_rearrange", $album); batch::stop(); $task->done = true; $task->state = "success"; $task->percent_complete = 100; - $task->set("content", self::_get_micro_thumb_grid($album, 0)->__toString()); break; } } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 52de87fc..85168810 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -51,30 +51,23 @@ padding-left: 1.2em; } -.gBranchText:hover { +.gAlbumText:hover { border: 1px dashed #999; + padding: 1px; } -.gBranchEmpty { - visibility: hidden; -} - -.gBranchSelected { +#gOrganizeAlbumTree .selected { background-color: #cfdeff !important; border-bottom: 1px solid #999 !important; display: block; padding: .3em 0; } -.gBranchCollapsed { - display: none; -} - -.gOrganizeBranch span { +.gOrganizeAlbum span { cursor: pointer; } -.gBranchText { +.gAlbumText { cursor: pointer; width: auto; } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 96309787..5e7bd47c 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -28,7 +28,8 @@ 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); + .animate({ width: 10, height: 10, outlineWidth: 1, margin: 1, + left: (20 * j), top: (row * 20) }, 500); }); return set; } @@ -58,6 +59,7 @@ $.organize.do_drop({ url: rearrange_url .replace("__TARGET_ID__", $(".currentDropTarget").attr("ref")) + .replace("__ALBUM_ID__", $(".currentDropTarget").attr("ref")) .replace("__BEFORE__", $(".currentDropTarget").css("borderLeftStyle") == "solid" ? "before" : "after"), source: $(ui.helper).children("img") }); @@ -74,14 +76,14 @@ $(".gMicroThumbGridCell").css("borderStyle", "none"); } else { $.organize.do_drop({ - url: move_url.replace("__TARGET_ID__", $(event.target).attr("ref")), + url: move_url.replace("__ALBUM_ID__", $(event.target).attr("ref")), source: $(ui.helper).children("img") }); } } }, - do_drop:function(options) { + do_drop: function(options) { $("#gMicroThumbPanel").selectable("destroy"); var source_ids = []; $(options.source).each(function(i) { @@ -105,7 +107,6 @@ data: { "source_ids[]": source_ids }, dataType: "json", success: function(data, textStatus) { - $("#gStatus").html(data.status); $("#gOrganize .gProgressBar").progressbar("value", data.percent_complete); setTimeout(function() { $.organize._run_task(data.url); }, 0); } @@ -121,7 +122,6 @@ async: false, dataType: "json", success: function(data, textStatus) { - $("#gStatus").html(data.status); $("#gOrganize .gProgressBar").progressbar("value", data.percent_complete); if (data.done) { var height = $("#gOrganizeProgress").height(); @@ -130,8 +130,10 @@ if (data.tree) { $("#gOrganizeAlbumTree").html(data.tree); } - if (data.content) { - $("#gMicroThumbGrid").html(data.content); + if (data.grid) { + $("#gMicroThumbGrid").html(data.grid); + $("#gOrganizeSortColumn").attr("value", data.sort_column); + $("#gOrganizeSortOrder").attr("value", data.sort_order); } $.organize.set_handlers(); } else { @@ -174,8 +176,8 @@ $("#gDialog").dialog("close"); }); - $("#gOrganizeSortColumn,#gOrganizeSortDir").change(function(event) { - $.organize.resort($("#gOrganizeSortColumn").attr("value"), $("#gOrganizeSortDir").attr("value")); + $("#gOrganizeSortColumn,#gOrganizeSortOrder").change(function(event) { + $.organize.resort($("#gOrganizeSortColumn").attr("value"), $("#gOrganizeSortOrder").attr("value")); }); $.organize.set_handlers(); @@ -187,26 +189,17 @@ $(".gMicroThumbGridCell").draggable($.organize.micro_thumb_draggable); $(".gMicroThumbGridCell").mousemove($.organize.mouse_move_handler); - $(".gOrganizeBranch").droppable($.organize.branch_droppable); - $(".gBranchText").click($.organize.show_album); - $(".gOrganizeBranch .ui-icon").click($.organize.collapse_or_expand_tree); + $(".gOrganizeAlbum").droppable($.organize.branch_droppable); + $(".gAlbumText").click($.organize.show_album); }, - /** - * Open or close a branch. - */ - collapse_or_expand_tree: function(event) { - event.stopPropagation(); - $(event.currentTarget).toggleClass("ui-icon-minus").toggleClass("ui-icon-plus"); - $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); - }, /** * When the text of a selection is clicked, then show that albums contents */ show_album: function(event) { event.preventDefault(); - if ($(event.currentTarget).hasClass("gBranchSelected")) { + if ($(event.currentTarget).hasClass("selected")) { return; } var parent = $(event.currentTarget).parents(".gOrganizeBranch"); @@ -215,13 +208,17 @@ } $("#gMicroThumbPanel").selectable("destroy"); var id = $(event.currentTarget).attr("ref"); - $(".gBranchSelected").removeClass("gBranchSelected"); - $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); + $("#gOrganizeAlbumTree .selected").removeClass("selected"); + $(".gAlbumText[ref=" + id + "]").addClass("selected"); var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); $.get(url, function(data) { - $("#gMicroThumbGrid").html(data); - $.organize.set_handlers(); - }); + $("#gMicroThumbGrid").html(data.grid); + $("#gOrganizeSortColumn").attr("value", data.sort_column); + $("#gOrganizeSortOrder").attr("value", data.sort_order); + $.organize.set_handlers(); + }, + function() { }, + "json"); }, /** @@ -229,12 +226,17 @@ */ resort: function(column, dir) { var url = sort_order_url + .replace("__ALBUM_ID__", $("#gOrganizeAlbumTree .selected").attr("ref")) .replace("__COL__", column) .replace("__DIR__", dir); $.get(url, function(data) { - $("#gMicroThumbGrid").html(data); - $.organize.set_handlers(); - }); + $("#gMicroThumbGrid").html(data.grid); + $("#gOrganizeSortColumn").attr("value", data.sort_column); + $("#gOrganizeSortOrder").attr("value", data.sort_order); + $.organize.set_handlers(); + }, + function() { }, + "json"); } }; })(jQuery); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index a3aae05b..7ade91a2 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,8 +1,8 @@

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

@@ -23,7 +23,7 @@
"> + ref="">
@@ -34,12 +34,11 @@
"gOrganizeSortColumn"), album::get_sort_order_options(), $album->sort_column) ?> - "gOrganizeSortDir"), array("ASC" => "Ascending", "DESC" => "Descending"), $album->sort_order) ?> + "gOrganizeSortOrder"), array("ASC" => "Ascending", "DESC" => "Descending"), $album->sort_order) ?>
diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index 5adb487a..31dc9af5 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,5 +1,5 @@ -children(25, $offset) as $child): ?> +children(25, $offset) as $child): ?>
  • "> @@ -8,10 +8,10 @@
  • -children_count() > $offset): ?> +children_count() > $offset): ?>