diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-22 23:23:15 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-22 23:23:15 +0000 |
commit | 933770cf0ece55ff98a098456807764caf07b767 (patch) | |
tree | c2ba4e022dd58fb988f8bf7b2f406c8e9640d784 | |
parent | 79712cb0b4c73e8bc73f4f694018fb2e6308c935 (diff) |
1) Fix index overflow issue.
2) Fix where the microthumb was removed even if the move was cancelled
-rw-r--r-- | modules/organize/helpers/organize_task.php | 18 | ||||
-rw-r--r-- | modules/organize/js/organize.js | 6 |
2 files changed, 17 insertions, 7 deletions
diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php index a6d89e37..bb6321fa 100644 --- a/modules/organize/helpers/organize_task.php +++ b/modules/organize/helpers/organize_task.php @@ -27,12 +27,15 @@ class organize_task_Core { $context = unserialize($task->context); try { - $stop = min(count($context["items"]), $context["position"] + $context["batch"]); - for (; $context["position"] < $stop; $context["position"]++ ) { - $id = $context["items"][$context["position"]]; + $total = count($context["items"]); + $stop = min($total - $context["position"], $context["batch"]); + for ($offset = 0; $offset < $stop; $offset++) { + $current_id = $context["position"] + $offset; + $id = $context["items"][$current_id]; Database::instance() ->query("Update {items} set weight = {$context["position"]} where id=$id;"); } + $context["position"] += $stop; $task->state = "success"; } catch(Exception $e) { $task->status = $e->getMessage(); @@ -51,11 +54,14 @@ class organize_task_Core { try { $target = ORM::factory("item", $context["target"]); - $stop = min(count($context["items"]), $context["position"] + $context["batch"]); - for (; $context["position"] < $stop; $context["position"]++ ) { - $source = ORM::factory("item", $context["items"][$context["position"]]); + $total = count($context["items"]); + $stop = min($total - $context["position"], $context["batch"]); + for ($offset = 0; $offset < $stop; $offset++) { + $current_id = $context["position"] + $offset; + $source = ORM::factory("item", $context["items"][$current_id]); core::move_item($source, $target); } + $context["position"] += $stop; $task->state = "success"; } catch(Exception $e) { $task->status = $e->getMessage(); diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 75d5ccd2..4ca7e844 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -115,18 +115,22 @@ var treeDroppable = { var targetItemId = $(this).attr("ref"); if ($(this).hasClass("gBranchSelected")) { // @todo Error message for moving onto self + ui.draggable.trigger("stop", event); return false; } var okToMove = true; $("#gDragHelper li").each(function(i) { moveItems += "&item[]=" + $(this).attr("ref"); okToMove &= targetItemId != $(this).attr("ref"); - $("#thumb_" + $(this).attr("ref")).remove(); }); if (!okToMove) { // @todo Error message for moving onto self + ui.draggable.trigger("stop", event); return false; } + $("#gDragHelper li").each(function(i) { + $("#thumb_" + $(this).attr("ref")).remove(); + }); $.ajax({ data: moveItems, dataType: "json", |