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 +++++++++++++++++++++------------------------ 4 files changed, 80 insertions(+), 62 deletions(-) (limited to 'app') 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 @@ -
- -
-
+ +
+ - + -
+
- -
+ +
- -
-
+ +
+
-
+
-
- - +
+ + - -
+ +
- -
+ +
- -
+ +
- -
+ +
- -
-
-
+ +
+
+
-
- - - - - - - -
- -
+
+ + + + + + + +
+
-- cgit v1.2.3