From a5337cfe5c688c8b7bc91135af47cbafe7c0527d Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 23 Sep 2014 20:16:07 +0200 Subject: Move task edit form to the task layout --- app/Controller/Task.php | 31 +++++++++-------- app/Core/Listener.php | 4 +-- app/Model/TaskValidator.php | 24 ++++++++++++- app/Templates/task_edit.php | 83 +++++++++++++++++++++------------------------ assets/css/app.css | 4 +++ 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,13 +79,35 @@ class TaskValidator extends Base } /** - * Validate task modification + * Validate task modification (form) * * @access public * @param array $values Form values * @return array $valid, $errors [0] = Success or not, [1] = List of errors */ public function validateModification(array $values) + { + $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')), 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 @@ -
- -
-
+ +
+ - + -
+
- -
+ +
- -
-
+ +
+
-
+
-
- - +
+ + - -
+ +
- -
+ +
- -
+ +
- -
+ +
- -
-
-
+ +
+
+
-
- - - - - - - -
- -
+
+ + + + + + + +
+
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); }); -- cgit v1.2.3