summaryrefslogtreecommitdiff
path: root/modules/organize/controllers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2011-01-05 02:00:40 -0800
committerBharat Mediratta <bharat@menalto.com>2011-01-05 02:00:40 -0800
commit372905bd1310fc446db795661e1eb013674e5a75 (patch)
tree135f75d44a8f7511128739f29313eb07066998b9 /modules/organize/controllers
parentc590f881ebbb005390f6e4f8a37a6252a5796f51 (diff)
Support moving an item before or after the target.
Diffstat (limited to 'modules/organize/controllers')
-rw-r--r--modules/organize/controllers/organize.php11
1 files changed, 8 insertions, 3 deletions
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php
index 18e6054b..c23d6d61 100644
--- a/modules/organize/controllers/organize.php
+++ b/modules/organize/controllers/organize.php
@@ -103,7 +103,7 @@ class Organize_Controller extends Controller {
json::reply(null);
}
- function move_before() {
+ function rearrange() {
access::verify_csrf();
$input = Input::instance();
@@ -125,20 +125,25 @@ class Organize_Controller extends Controller {
}
$source_ids = explode(",", $input->post("source_ids"));
+ $base_weight = $target->weight;
+ if ($input->post("relative") == "after") {
+ $base_weight++;
+ }
+
if ($source_ids) {
// Make a hole the right size
db::build()
->update("items")
->set("weight", db::expr("`weight` + " . count($source_ids)))
->where("parent_id", "=", $album->id)
- ->where("weight", ">=", $target->weight)
+ ->where("weight", ">=", $base_weight)
->execute();
// Move all the source items to the right spots.
for ($i = 0; $i < count($source_ids); $i++) {
$source = ORM::factory("item", $source_ids[$i]);
if ($source->parent_id = $album->id) {
- $source->weight = $target->weight + $i;
+ $source->weight = $base_weight + $i;
$source->save();
}
}