From 749136361e6eedbc868778db17bdc67aa0f3b677 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Wed, 3 Sep 2014 14:25:17 -0700 Subject: Change a category directly from the board --- app/Controller/Board.php | 94 +++++++++++++++++++++++++++----------- app/Locales/de_DE/translations.php | 2 + app/Locales/es_ES/translations.php | 2 + app/Locales/fi_FI/translations.php | 2 + app/Locales/fr_FR/translations.php | 2 + app/Locales/it_IT/translations.php | 2 + app/Locales/pl_PL/translations.php | 2 + app/Locales/pt_BR/translations.php | 2 + app/Locales/sv_SE/translations.php | 2 + app/Locales/zh_CN/translations.php | 2 + app/Model/Acl.php | 2 +- app/Model/Task.php | 24 ++++++++++ app/Templates/board_assign.php | 26 ----------- app/Templates/board_assignee.php | 24 ++++++++++ app/Templates/board_category.php | 24 ++++++++++ app/Templates/board_task.php | 16 ++++--- 16 files changed, 169 insertions(+), 59 deletions(-) delete mode 100644 app/Templates/board_assign.php create mode 100644 app/Templates/board_assignee.php create mode 100644 app/Templates/board_category.php (limited to 'app') diff --git a/app/Controller/Board.php b/app/Controller/Board.php index f43527ea..e2c10f58 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -51,39 +51,27 @@ class Board extends Base * * @access public */ - public function assign() + public function changeAssignee() { - $task = $this->task->getById($this->request->getIntegerParam('task_id')); + $task = $this->getTask(); $project = $this->project->getById($task['project_id']); - $projects = $this->project->getListByStatus(ProjectModel::ACTIVE); - - if ($this->acl->isRegularUser()) { - $projects = $this->project->filterListByAccess($projects, $this->acl->getUserId()); - } - - if (! $project) $this->notfound(); - $this->checkProjectPermissions($project['id']); + $projects = $this->project->getAvailableList($this->acl->getUserId()); + $params = array( + 'errors' => array(), + 'values' => $task, + 'users_list' => $this->project->getUsersList($project['id']), + 'projects' => $projects, + 'current_project_id' => $project['id'], + 'current_project_name' => $project['name'], + ); if ($this->request->isAjax()) { - $this->response->html($this->template->load('board_assign', array( - 'errors' => array(), - 'values' => $task, - 'users_list' => $this->project->getUsersList($project['id']), - 'projects' => $projects, - 'current_project_id' => $project['id'], - 'current_project_name' => $project['name'], - ))); + $this->response->html($this->template->load('board_assignee', $params)); } else { - $this->response->html($this->template->layout('board_assign', array( - 'errors' => array(), - 'values' => $task, - 'users_list' => $this->project->getUsersList($project['id']), - 'projects' => $projects, - 'current_project_id' => $project['id'], - 'current_project_name' => $project['name'], + $this->response->html($this->template->layout('board_assignee', $params + array( 'menu' => 'boards', 'title' => t('Change assignee').' - '.$task['title'], ))); @@ -95,7 +83,7 @@ class Board extends Base * * @access public */ - public function assignTask() + public function updateAssignee() { $values = $this->request->getValues(); $this->checkProjectPermissions($values['project_id']); @@ -112,6 +100,60 @@ class Board extends Base $this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']); } + /** + * Change a task category directly from the board + * + * @access public + */ + public function changeCategory() + { + $task = $this->getTask(); + $project = $this->project->getById($task['project_id']); + $projects = $this->project->getAvailableList($this->acl->getUserId()); + $params = array( + 'errors' => array(), + 'values' => $task, + 'categories_list' => $this->category->getList($project['id']), + 'projects' => $projects, + 'current_project_id' => $project['id'], + 'current_project_name' => $project['name'], + ); + + if ($this->request->isAjax()) { + + $this->response->html($this->template->load('board_category', $params)); + } + else { + + $this->response->html($this->template->layout('board_category', $params + array( + 'menu' => 'boards', + 'title' => t('Change category').' - '.$task['title'], + ))); + } + } + + /** + * Validate a category modification + * + * @access public + */ + public function updateCategory() + { + $values = $this->request->getValues(); + $this->checkProjectPermissions($values['project_id']); + + list($valid,) = $this->task->validateCategoryModification($values); + + if ($valid && $this->task->update($values)) { + $this->session->flash(t('Task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } + + $this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']); + } + /** * Display the public version of a board * Access checked by a simple token, no user login, read only, auto-refresh diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php index 006efe84..ad3b2ff8 100644 --- a/app/Locales/de_DE/translations.php +++ b/app/Locales/de_DE/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php index 295d6464..a853718c 100644 --- a/app/Locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/fi_FI/translations.php b/app/Locales/fi_FI/translations.php index d7e929ce..809be56d 100644 --- a/app/Locales/fi_FI/translations.php +++ b/app/Locales/fi_FI/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index 230e51db..96fb3a51 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -466,4 +466,6 @@ return array( 'No external authentication enabled.' => 'Aucune authentication externe activée.', 'Password modified successfully.' => 'Mot de passe changé avec succès.', 'Unable to change the password.' => 'Impossible de changer le mot de passe.', + 'Change category for the task "%s"' => 'Changer la catégorie pour la tâche « %s »', + 'Change category' => 'Changer de catégorie', ); diff --git a/app/Locales/it_IT/translations.php b/app/Locales/it_IT/translations.php index 3c5e3ae8..33ad358f 100644 --- a/app/Locales/it_IT/translations.php +++ b/app/Locales/it_IT/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php index f12ec080..34d4a704 100644 --- a/app/Locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php index ec67c90a..cd337939 100644 --- a/app/Locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/sv_SE/translations.php b/app/Locales/sv_SE/translations.php index 55878da5..a2ce9016 100644 --- a/app/Locales/sv_SE/translations.php +++ b/app/Locales/sv_SE/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Locales/zh_CN/translations.php b/app/Locales/zh_CN/translations.php index 91d5ff49..8a4b8836 100644 --- a/app/Locales/zh_CN/translations.php +++ b/app/Locales/zh_CN/translations.php @@ -466,4 +466,6 @@ return array( // 'No external authentication enabled.' => '', // 'Password modified successfully.' => '', // 'Unable to change the password.' => '', + // 'Change category for the task "%s"' => '', + // 'Change category' => '', ); diff --git a/app/Model/Acl.php b/app/Model/Acl.php index a7620731..21c76329 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -30,7 +30,7 @@ class Acl extends Base */ private $user_actions = array( 'app' => array('index'), - 'board' => array('index', 'show', 'assign', 'assigntask', 'save', 'check'), + 'board' => array('index', 'show', 'save', 'check', 'changeassignee', 'updateassignee', 'changecategory', 'updatecategory'), 'project' => array('tasks', 'index', 'forbidden', 'search', 'export', 'show'), 'user' => array('index', 'edit', 'forbidden', 'logout', 'index', 'show', 'external', 'unlinkgoogle', 'unlinkgithub', 'sessions', 'removesession', 'last', 'notifications', 'password'), 'comment' => array('create', 'save', 'confirm', 'remove', 'update', 'edit', 'forbidden'), diff --git a/app/Model/Task.php b/app/Model/Task.php index 6a20f4d0..df6e4426 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -704,6 +704,30 @@ class Task extends Base ); } + /** + * Validate category change + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateCategoryModification(array $values) + { + $v = new Validator($values, array( + new Validators\Required('id', t('The id is required')), + new Validators\Integer('id', t('This value must be an integer')), + new Validators\Required('project_id', t('The project is required')), + new Validators\Integer('project_id', t('This value must be an integer')), + new Validators\Required('category_id', t('This value is required')), + new Validators\Integer('category_id', t('This value must be an integer')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } + /** * Validate project modification * diff --git a/app/Templates/board_assign.php b/app/Templates/board_assign.php deleted file mode 100644 index 45cb4b4f..00000000 --- a/app/Templates/board_assign.php +++ /dev/null @@ -1,26 +0,0 @@ -
- - - -
-

-
- - - - - -
- -
- - -
-
-
- -
\ No newline at end of file diff --git a/app/Templates/board_assignee.php b/app/Templates/board_assignee.php new file mode 100644 index 00000000..41ede32b --- /dev/null +++ b/app/Templates/board_assignee.php @@ -0,0 +1,24 @@ +
+ + + +
+

+
+ + + + + +
+ +
+ + +
+
+
+ +
\ No newline at end of file diff --git a/app/Templates/board_category.php b/app/Templates/board_category.php new file mode 100644 index 00000000..36126a1d --- /dev/null +++ b/app/Templates/board_category.php @@ -0,0 +1,24 @@ +
+ + + +
+

+
+ + + + + +
+ +
+ + +
+
+
+ +
\ No newline at end of file diff --git a/app/Templates/board_task.php b/app/Templates/board_task.php index 4370558b..40590a65 100644 --- a/app/Templates/board_task.php +++ b/app/Templates/board_task.php @@ -23,11 +23,13 @@ # - - - - - - + + + + + + + @@ -44,7 +46,9 @@
- + + +
-- cgit v1.2.3