summaryrefslogtreecommitdiff
path: root/app/Controller/Swimlane.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller/Swimlane.php')
-rw-r--r--app/Controller/Swimlane.php97
1 files changed, 76 insertions, 21 deletions
diff --git a/app/Controller/Swimlane.php b/app/Controller/Swimlane.php
index 4e8c2863..8270a16f 100644
--- a/app/Controller/Swimlane.php
+++ b/app/Controller/Swimlane.php
@@ -36,7 +36,7 @@ class Swimlane extends Base
*
* @access public
*/
- public function index(array $values = array(), array $errors = array())
+ public function index()
{
$project = $this->getProject();
@@ -44,10 +44,24 @@ class Swimlane extends Base
'default_swimlane' => $this->swimlane->getDefault($project['id']),
'active_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::ACTIVE),
'inactive_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::INACTIVE),
+ 'project' => $project,
+ 'title' => t('Swimlanes')
+ )));
+ }
+
+ /**
+ * Create a new swimlane
+ *
+ * @access public
+ */
+ public function create(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->template->render('swimlane/create', array(
'values' => $values + array('project_id' => $project['id']),
'errors' => $errors,
'project' => $project,
- 'title' => t('Swimlanes')
)));
}
@@ -67,11 +81,28 @@ class Swimlane extends Base
$this->flash->success(t('Your swimlane have been created successfully.'));
$this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
} else {
- $this->flash->failure(t('Unable to create your swimlane.'));
+ $errors = array('name' => array(t('Another swimlane with the same name exists in the project')));
}
}
- $this->index($values, $errors);
+ $this->create($values, $errors);
+ }
+
+ /**
+ * Edit default swimlane (display the form)
+ *
+ * @access public
+ */
+ public function editDefault(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+ $swimlane = $this->swimlane->getDefault($project['id']);
+
+ $this->response->html($this->helper->layout->project('swimlane/edit_default', array(
+ 'values' => empty($values) ? $swimlane : $values,
+ 'errors' => $errors,
+ 'project' => $project,
+ )));
}
/**
@@ -79,23 +110,23 @@ class Swimlane extends Base
*
* @access public
*/
- public function change()
+ public function updateDefault()
{
$project = $this->getProject();
$values = $this->request->getValues() + array('show_default_swimlane' => 0);
- list($valid, ) = $this->swimlaneValidator->validateDefaultModification($values);
+ list($valid, $errors) = $this->swimlaneValidator->validateDefaultModification($values);
if ($valid) {
if ($this->swimlane->updateDefault($values)) {
$this->flash->success(t('The default swimlane have been updated successfully.'));
- $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
+ $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])), true);
} else {
$this->flash->failure(t('Unable to update this swimlane.'));
}
}
- $this->index();
+ $this->editDefault($values, $errors);
}
/**
@@ -112,7 +143,6 @@ class Swimlane extends Base
'values' => empty($values) ? $swimlane : $values,
'errors' => $errors,
'project' => $project,
- 'title' => t('Swimlanes')
)));
}
@@ -133,7 +163,7 @@ class Swimlane extends Base
$this->flash->success(t('Swimlane updated successfully.'));
$this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
} else {
- $this->flash->failure(t('Unable to update this swimlane.'));
+ $errors = array('name' => array(t('Another swimlane with the same name exists in the project')));
}
}
@@ -153,7 +183,6 @@ class Swimlane extends Base
$this->response->html($this->helper->layout->project('swimlane/remove', array(
'project' => $project,
'swimlane' => $swimlane,
- 'title' => t('Remove a swimlane')
)));
}
@@ -198,6 +227,25 @@ class Swimlane extends Base
}
/**
+ * Disable default swimlane
+ *
+ * @access public
+ */
+ public function disableDefault()
+ {
+ $this->checkCSRFParam();
+ $project = $this->getProject();
+
+ if ($this->swimlane->disableDefault($project['id'])) {
+ $this->flash->success(t('Swimlane updated successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to update this swimlane.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
+ }
+
+ /**
* Enable a swimlane
*
* @access public
@@ -218,32 +266,39 @@ class Swimlane extends Base
}
/**
- * Move up a swimlane
+ * Enable default swimlane
*
* @access public
*/
- public function moveup()
+ public function enableDefault()
{
$this->checkCSRFParam();
$project = $this->getProject();
- $swimlane_id = $this->request->getIntegerParam('swimlane_id');
- $this->swimlane->moveUp($project['id'], $swimlane_id);
+ if ($this->swimlane->enableDefault($project['id'])) {
+ $this->flash->success(t('Swimlane updated successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to update this swimlane.'));
+ }
+
$this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
}
/**
- * Move down a swimlane
+ * Move swimlane position
*
* @access public
*/
- public function movedown()
+ public function move()
{
- $this->checkCSRFParam();
$project = $this->getProject();
- $swimlane_id = $this->request->getIntegerParam('swimlane_id');
+ $values = $this->request->getJson();
- $this->swimlane->moveDown($project['id'], $swimlane_id);
- $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])));
+ if (! empty($values) && isset($values['swimlane_id']) && isset($values['position'])) {
+ $result = $this->swimlane->changePosition($project['id'], $values['swimlane_id'], $values['position']);
+ return $this->response->json(array('result' => $result));
+ }
+
+ $this->forbidden();
}
}