Browse files

show next picture after delete instead of returning to album view

  • Loading branch information...
1 parent fb82ea4 commit ab4363233a62e128f950742b32a9e48cdc6fb0c6 @taarraas taarraas committed Feb 28, 2014
Showing with 16 additions and 2 deletions.
  1. +16 −2 modules/gallery/controllers/quick.php
View
18 modules/gallery/controllers/quick.php
@@ -95,7 +95,7 @@ public function delete($id) {
$msg = t("Deleted photo <b>%title</b>", array("title" => html::purify($item->title)));
}
- $parent = $item->parent();
+ $redirect = $item->parent(); // redirect to this item, if current item was deleted
if ($item->is_album()) {
// Album delete will trigger deletes for all children. Do this in a batch so that we can be
@@ -104,6 +104,20 @@ public function delete($id) {
$item->delete();
batch::stop();
} else {
+ $where = array(array("type", "!=", "album")); // evaluate redirect item before delete of current item
+ $position = item::get_position($item, $where);
+ if ($position > 1) {
+ list ($previous_item, $ignore, $next_item) =
+ $item->parent()->viewable()->children(3, $position - 2, $where);
+ } else {
+ $previous_item = null;
+ list ($next_item) = $item->parent()->viewable()->children(1, $position, $where);
+ }
+ if ($next_item) {
+ $redirect = $next_item;
+ } else if ($previous_item) {
+ $redirect = $previous_item;
+ }
$item->delete();
}
message::success($msg);
@@ -113,7 +127,7 @@ public function delete($id) {
$from_id != $id /* deleted the item we were viewing */) {
json::reply(array("result" => "success", "reload" => 1));
} else {
- json::reply(array("result" => "success", "location" => $parent->url()));
+ json::reply(array("result" => "success", "location" => $redirect->url()));
}
}

0 comments on commit ab43632

Please sign in to comment.