summaryrefslogtreecommitdiff
path: root/app/Controller/Column.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller/Column.php')
-rw-r--r--app/Controller/Column.php50
1 files changed, 29 insertions, 21 deletions
diff --git a/app/Controller/Column.php b/app/Controller/Column.php
index 3201c549..77204164 100644
--- a/app/Controller/Column.php
+++ b/app/Controller/Column.php
@@ -15,20 +15,12 @@ class Column extends Base
*
* @access public
*/
- public function index(array $values = array(), array $errors = array())
+ public function index()
{
$project = $this->getProject();
$columns = $this->board->getColumns($project['id']);
- foreach ($columns as $column) {
- $values['title['.$column['id'].']'] = $column['title'];
- $values['description['.$column['id'].']'] = $column['description'];
- $values['task_limit['.$column['id'].']'] = $column['task_limit'] ?: null;
- }
-
$this->response->html($this->helper->layout->project('column/index', array(
- 'errors' => $errors,
- 'values' => $values + array('project_id' => $project['id']),
'columns' => $columns,
'project' => $project,
'title' => t('Edit board')
@@ -36,33 +28,49 @@ class Column extends Base
}
/**
- * Validate and add a new column
+ * Show form to create a new column
*
* @access public
*/
- public function create()
+ public function create(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$columns = $this->board->getColumnsList($project['id']);
- $data = $this->request->getValues();
- $values = array();
- foreach ($columns as $column_id => $column_title) {
- $values['title['.$column_id.']'] = $column_title;
+ if (empty($values)) {
+ $values = array('project_id' => $project['id']);
}
- list($valid, $errors) = $this->columnValidator->validateCreation($data);
+ $this->response->html($this->template->render('column/create', array(
+ 'values' => $values,
+ 'errors' => $errors,
+ 'project' => $project,
+ 'title' => t('Add a new column')
+ )));
+ }
+
+ /**
+ * Validate and add a new column
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+
+ list($valid, $errors) = $this->columnValidator->validateCreation($values);
if ($valid) {
- if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) {
- $this->flash->success(t('Board updated successfully.'));
- $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id'])));
+ if ($this->board->addColumn($project['id'], $values['title'], $values['task_limit'], $values['description'])) {
+ $this->flash->success(t('Column created successfully.'));
+ return $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id'])), true);
} else {
- $this->flash->failure(t('Unable to update this board.'));
+ $errors['title'] = array(t('Another column with the same title exists in the project'));
}
}
- $this->index($values, $errors);
+ $this->create($values, $errors);
}
/**