From 2d27c36a71f08bea60a992b051bfb8a2d8bd06b6 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 20 Feb 2016 10:46:10 -0500 Subject: Use inline popup to create new columns --- ChangeLog | 1 + app/Controller/Column.php | 50 +++++++++++++++++++++++---------------- app/Template/column/create.php | 41 ++++++++++++++++++++++++++++++++ app/Template/column/index.php | 44 +++++----------------------------- app/Validator/ColumnValidator.php | 35 ++++++++++++++++++++------- 5 files changed, 103 insertions(+), 68 deletions(-) create mode 100644 app/Template/column/create.php diff --git a/ChangeLog b/ChangeLog index fa2c2597..31b089b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ New features: Improvements: +* Use inline popup to create new columns * Improve filter box design * Improve image thumbnails and files table * Add confirmation inline popup to remove custom filter 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); } /** diff --git a/app/Template/column/create.php b/app/Template/column/create.php new file mode 100644 index 00000000..58b130f5 --- /dev/null +++ b/app/Template/column/create.php @@ -0,0 +1,41 @@ + +
+ + form->csrf() ?> + + form->hidden('project_id', $values) ?> + + form->label(t('Title'), 'title') ?> + form->text('title', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?> + + form->label(t('Task limit'), 'task_limit') ?> + form->number('task_limit', $values, $errors) ?> + + form->label(t('Description'), 'description') ?> + +
+
+ form->textarea('description', $values, $errors) ?> +
+
+
+
+
    +
  • + +
  • +
  • + +
  • +
+
+
url->doc(t('Write your text in Markdown'), 'syntax-guide') ?>
+ +
+ + + url->link(t('cancel'), 'column', 'index', array('project_id' => $project['id']), false, 'close-popover') ?> +
+
\ No newline at end of file diff --git a/app/Template/column/index.php b/app/Template/column/index.php index 85d46f26..8d95dd48 100644 --- a/app/Template/column/index.php +++ b/app/Template/column/index.php @@ -1,5 +1,11 @@ @@ -52,41 +58,3 @@ - -

-
- - form->csrf() ?> - - form->hidden('project_id', $values) ?> - - form->label(t('Title'), 'title') ?> - form->text('title', $values, $errors, array('required', 'maxlength="50"')) ?> - - form->label(t('Task limit'), 'task_limit') ?> - form->number('task_limit', $values, $errors) ?> - - form->label(t('Description'), 'description') ?> - -
-
- form->textarea('description', $values, $errors) ?> -
-
-
-
-
    -
  • - -
  • -
  • - -
  • -
-
-
url->doc(t('Write your text in Markdown'), 'syntax-guide') ?>
- -
- -
-
\ No newline at end of file diff --git a/app/Validator/ColumnValidator.php b/app/Validator/ColumnValidator.php index 4c644e8a..f0f1659b 100644 --- a/app/Validator/ColumnValidator.php +++ b/app/Validator/ColumnValidator.php @@ -22,11 +22,12 @@ class ColumnValidator extends Base */ public function validateModification(array $values) { - $v = new Validator($values, array( - new Validators\Integer('task_limit', t('This value must be an integer')), - new Validators\Required('title', t('The title is required')), - new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), - )); + $rules = array( + new Validators\Required('id', t('This value is required')), + new Validators\Integer('id', t('This value must be an integer')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -43,16 +44,32 @@ class ColumnValidator extends Base */ public function validateCreation(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('project_id', t('The project id is required')), new Validators\Integer('project_id', t('This value must be an integer')), - new Validators\Required('title', t('The title is required')), - new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), $v->getErrors() ); } + + /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Integer('task_limit', t('This value must be an integer')), + new Validators\GreaterThan('task_limit', t('This value must be greater than %d', -1), -1), + new Validators\Required('title', t('The title is required')), + new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), + ); + } } -- cgit v1.2.3