From 954bed954f6c81cbcdb217966dcc9e008e7dd149 Mon Sep 17 00:00:00 2001
From: Frédéric Guillot <fred@kanboard.net>
Date: Thu, 4 Sep 2014 20:14:26 -0700
Subject: Task move position refactoring

---
 app/Controller/Board.php | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

(limited to 'app/Controller')

diff --git a/app/Controller/Board.php b/app/Controller/Board.php
index e2c10f58..4724cae5 100644
--- a/app/Controller/Board.php
+++ b/app/Controller/Board.php
@@ -396,27 +396,31 @@ class Board extends Base
      */
     public function save()
     {
-        if ($this->request->isAjax()) {
+        $project_id = $this->request->getIntegerParam('project_id');
 
-            $project_id = $this->request->getIntegerParam('project_id');
-            $values = $this->request->getValues();
+        if ($project_id > 0 && $this->request->isAjax()) {
 
-            if ($project_id > 0 && ! $this->project->isUserAllowed($project_id, $this->acl->getUserId())) {
-                $this->response->text('Not Authorized', 401);
+            if (! $this->project->isUserAllowed($project_id, $this->acl->getUserId())) {
+                $this->response->status(401);
             }
 
-            if (isset($values['positions'])) {
-                $this->board->saveTasksPosition($values['positions'], $values['selected_task_id']);
+            $values = $this->request->getValues();
+
+            if ($this->task->movePosition($project_id, $values['task_id'], $values['column_id'], $values['position'])) {
+
+                $this->response->html(
+                    $this->template->load('board_show', array(
+                        'current_project_id' => $project_id,
+                        'board' => $this->board->get($project_id),
+                        'categories' => $this->category->getList($project_id, false),
+                    )),
+                    201
+                );
             }
+            else {
 
-            $this->response->html(
-                $this->template->load('board_show', array(
-                    'current_project_id' => $project_id,
-                    'board' => $this->board->get($project_id),
-                    'categories' => $this->category->getList($project_id, false),
-                )),
-                201
-            );
+                $this->response->status(400);
+            }
         }
         else {
             $this->response->status(401);
-- 
cgit v1.2.3