From 475b8fe9ff3f4eee077fd649a1e5aea2568c06b4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 22 Apr 2009 16:09:57 +0000 Subject: Dragging from the thumbgrid to an album in the tree now works. Refactored the javascript to minimize duplication. --- modules/organize/helpers/organize_task.php | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'modules/organize/helpers/organize_task.php') diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php index f923fdc7..a6d89e37 100644 --- a/modules/organize/helpers/organize_task.php +++ b/modules/organize/helpers/organize_task.php @@ -27,7 +27,7 @@ class organize_task_Core { $context = unserialize($task->context); try { - $stop = $context["position"] + $context["batch"]; + $stop = min(count($context["items"]), $context["position"] + $context["batch"]); for (; $context["position"] < $stop; $context["position"]++ ) { $id = $context["items"][$context["position"]]; Database::instance() @@ -35,12 +35,37 @@ class organize_task_Core { } $task->state = "success"; } catch(Exception $e) { - $tast->status = $e->getMessage(); + $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->done = $context["position"] == $total || $task->state == "error"; + } + + static function move($task) { + $context = unserialize($task->context); + + 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"]]); + core::move_item($source, $target); + } + $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"; } } \ No newline at end of file -- cgit v1.2.3