diff options
-rw-r--r-- | app/Controller/Task.php | 31 | ||||
-rw-r--r-- | app/Core/Listener.php | 4 | ||||
-rw-r--r-- | app/Model/TaskValidator.php | 24 | ||||
-rw-r--r-- | app/Templates/task_edit.php | 83 | ||||
-rw-r--r-- | assets/css/app.css | 4 | ||||
-rw-r--r-- | jsonrpc.php | 2 |
6 files changed, 85 insertions, 63 deletions
diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 28db5c28..fc7103ef 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -160,23 +160,25 @@ class Task extends Base } $task['score'] = $task['score'] ?: ''; + $ajax = $this->request->isAjax(); $params = array( - 'values' => $task, - 'errors' => array(), - 'task' => $task, - 'users_list' => $this->projectPermission->getUsersList($task['project_id']), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($task['project_id']), - 'ajax' => $this->request->isAjax(), - 'menu' => 'tasks', - 'title' => t('Edit a task') - ); - if ($this->request->isAjax()) { + 'values' => $task, + 'errors' => array(), + 'task' => $task, + 'users_list' => $this->projectPermission->getUsersList($task['project_id']), + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($task['project_id']), + 'ajax' => $ajax, + 'menu' => 'tasks', + 'title' => t('Edit a task') + ); + + if ($ajax) { $this->response->html($this->template->load('task_edit', $params)); } else { - $this->response->html($this->template->layout('task_edit', $params)); + $this->response->html($this->taskLayout('task_edit', $params)); } } @@ -209,7 +211,7 @@ class Task extends Base } } - $this->response->html($this->template->layout('task_edit', array( + $this->response->html($this->taskLayout('task_edit', array( 'values' => $values, 'errors' => $errors, 'task' => $task, @@ -218,7 +220,8 @@ class Task extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($values['project_id']), 'menu' => 'tasks', - 'title' => t('Edit a task') + 'title' => t('Edit a task'), + 'ajax' => $this->request->isAjax(), ))); } diff --git a/app/Core/Listener.php b/app/Core/Listener.php index 0df641ba..9c96cd57 100644 --- a/app/Core/Listener.php +++ b/app/Core/Listener.php @@ -8,8 +8,8 @@ namespace Core; * @package core * @author Frederic Guillot */ -interface Listener { - +interface Listener +{ /** * Execute the listener * diff --git a/app/Model/TaskValidator.php b/app/Model/TaskValidator.php index 461c03d4..1c7b0b14 100644 --- a/app/Model/TaskValidator.php +++ b/app/Model/TaskValidator.php @@ -79,7 +79,7 @@ class TaskValidator extends Base } /** - * Validate task modification + * Validate task modification (form) * * @access public * @param array $values Form values @@ -89,6 +89,28 @@ class TaskValidator extends Base { $rules = array( new Validators\Required('id', t('The id is required')), + new Validators\Required('title', t('The title is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Validate task modification (Api) + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateApiModification(array $values) + { + $rules = array( + new Validators\Required('id', t('The id is required')), ); $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); diff --git a/app/Templates/task_edit.php b/app/Templates/task_edit.php index 83a4ca17..4038717e 100644 --- a/app/Templates/task_edit.php +++ b/app/Templates/task_edit.php @@ -1,58 +1,51 @@ -<section id="main"> - <div class="page-header"> - <h2><?= t('Edit a task') ?></h2> - <?php if (! $ajax): ?> - <ul> - <li><a href="?controller=board&action=show&project_id=<?= $task['project_id'] ?>"><?= t('Back to the board') ?></a></li> - </ul> - <?php endif ?> - </div> - <section id="task-section"> - <form method="post" action="?controller=task&action=update&task_id=<?= $task['id'] ?>&ajax=<?= $ajax ?>" autocomplete="off"> +<div class="page-header"> + <h2><?= t('Edit a task') ?></h2> +</div> +<section id="task-section"> +<form method="post" action="?controller=task&action=update&task_id=<?= $task['id'] ?>&ajax=<?= $ajax ?>" autocomplete="off"> - <?= Helper\form_csrf() ?> + <?= Helper\form_csrf() ?> - <div class="form-column"> + <div class="form-column"> - <?= Helper\form_label(t('Title'), 'title') ?> - <?= Helper\form_text('title', $values, $errors, array('required')) ?><br/> + <?= Helper\form_label(t('Title'), 'title') ?> + <?= Helper\form_text('title', $values, $errors, array('required')) ?><br/> - <?= Helper\form_label(t('Description'), 'description') ?> - <?= Helper\form_textarea('description', $values, $errors) ?><br/> - <div class="form-help"><a href="http://kanboard.net/documentation/syntax-guide" target="_blank" rel="noreferrer"><?= t('Write your text in Markdown') ?></a></div> + <?= Helper\form_label(t('Description'), 'description') ?> + <?= Helper\form_textarea('description', $values, $errors) ?><br/> + <div class="form-help"><a href="http://kanboard.net/documentation/syntax-guide" target="_blank" rel="noreferrer"><?= t('Write your text in Markdown') ?></a></div> - </div> + </div> - <div class="form-column"> - <?= Helper\form_hidden('id', $values) ?> - <?= Helper\form_hidden('project_id', $values) ?> + <div class="form-column"> + <?= Helper\form_hidden('id', $values) ?> + <?= Helper\form_hidden('project_id', $values) ?> - <?= Helper\form_label(t('Assignee'), 'owner_id') ?> - <?= Helper\form_select('owner_id', $users_list, $values, $errors) ?><br/> + <?= Helper\form_label(t('Assignee'), 'owner_id') ?> + <?= Helper\form_select('owner_id', $users_list, $values, $errors) ?><br/> - <?= Helper\form_label(t('Category'), 'category_id') ?> - <?= Helper\form_select('category_id', $categories_list, $values, $errors) ?><br/> + <?= Helper\form_label(t('Category'), 'category_id') ?> + <?= Helper\form_select('category_id', $categories_list, $values, $errors) ?><br/> - <?= Helper\form_label(t('Color'), 'color_id') ?> - <?= Helper\form_select('color_id', $colors_list, $values, $errors) ?><br/> + <?= Helper\form_label(t('Color'), 'color_id') ?> + <?= Helper\form_select('color_id', $colors_list, $values, $errors) ?><br/> - <?= Helper\form_label(t('Complexity'), 'score') ?> - <?= Helper\form_number('score', $values, $errors) ?><br/> + <?= Helper\form_label(t('Complexity'), 'score') ?> + <?= Helper\form_number('score', $values, $errors) ?><br/> - <?= Helper\form_label(t('Due Date'), 'date_due') ?> - <?= Helper\form_text('date_due', $values, $errors, array('placeholder="'.t('month/day/year').'"'), 'form-date') ?><br/> - <div class="form-help"><?= t('Others formats accepted: %s and %s', date('Y-m-d'), date('Y_m_d')) ?></div> - </div> + <?= Helper\form_label(t('Due Date'), 'date_due') ?> + <?= Helper\form_text('date_due', $values, $errors, array('placeholder="'.t('month/day/year').'"'), 'form-date') ?><br/> + <div class="form-help"><?= t('Others formats accepted: %s and %s', date('Y-m-d'), date('Y_m_d')) ?></div> + </div> - <div class="form-actions"> - <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/> - <?= t('or') ?> - <?php if ($ajax): ?> - <a href="?controller=board&action=show&project_id=<?= $task['project_id'] ?>"><?= t('cancel') ?></a> - <?php else: ?> - <a href="?controller=task&action=show&task_id=<?= $task['id'] ?>"><?= t('cancel') ?></a> - <?php endif ?> - </div> - </form> - </section> + <div class="form-actions"> + <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/> + <?= t('or') ?> + <?php if ($ajax): ?> + <a href="?controller=board&action=show&project_id=<?= $task['project_id'] ?>"><?= t('cancel') ?></a> + <?php else: ?> + <a href="?controller=task&action=show&task_id=<?= $task['id'] ?>"><?= t('cancel') ?></a> + <?php endif ?> + </div> +</form> </section> diff --git a/assets/css/app.css b/assets/css/app.css index 3f6e131f..ff859115 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -222,6 +222,10 @@ textarea.form-error { list-style-type: none; } +ul.form-errors li { + margin-left: 0; +} + .form-help { font-size: 0.8em; color: brown; diff --git a/jsonrpc.php b/jsonrpc.php index 2fbfb5a6..2dbab461 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -211,7 +211,7 @@ $server->register('updateTask', function($id, $title = null, $project_id = null, } } - list($valid) = $taskValidator->validateModification($values); + list($valid) = $taskValidator->validateApiModification($values); return $valid && $task->update($values); }); |