diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-01-02 17:01:27 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-01-02 17:01:27 -0500 |
commit | 3833c12ccce59bcc49c4cfa892401973558f604d (patch) | |
tree | b67b0e10cdc3d42e5626f728206138a444a40ed0 /app/Controller | |
parent | d49ce63e51f596ad3bf0d02b689aea673cf544f8 (diff) |
Refactoring/rewrite of modal boxes handling
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/ProjectEditController.php | 95 | ||||
-rw-r--r-- | app/Controller/TaskGanttCreationController.php | 64 | ||||
-rw-r--r-- | app/Controller/TaskMovePositionController.php | 4 |
3 files changed, 23 insertions, 140 deletions
diff --git a/app/Controller/ProjectEditController.php b/app/Controller/ProjectEditController.php index 228d681c..ae39fdf3 100644 --- a/app/Controller/ProjectEditController.php +++ b/app/Controller/ProjectEditController.php @@ -11,51 +11,23 @@ namespace Kanboard\Controller; class ProjectEditController extends BaseController { /** - * General edition (most common operations) + * Edit project * * @access public * @param array $values * @param array $errors */ - public function edit(array $values = array(), array $errors = array()) + public function show(array $values = array(), array $errors = array()) { - $this->renderView('project_edit/general', $values, $errors); - } - - /** - * Change start and end dates - * - * @access public - * @param array $values - * @param array $errors - */ - public function dates(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/dates', $values, $errors); - } - - /** - * Change project description - * - * @access public - * @param array $values - * @param array $errors - */ - public function description(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/description', $values, $errors); - } + $project = $this->getProject(); - /** - * Change task priority - * - * @access public - * @param array $values - * @param array $errors - */ - public function priority(array $values = array(), array $errors = array()) - { - $this->renderView('project_edit/task_priority', $values, $errors); + $this->response->html($this->helper->layout->project('project_edit/show', array( + 'owners' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true), + 'values' => empty($values) ? $project : $values, + 'errors' => $errors, + 'project' => $project, + 'title' => t('Edit project') + ))); } /** @@ -67,67 +39,42 @@ class ProjectEditController extends BaseController { $project = $this->getProject(); $values = $this->request->getValues(); - $redirect = $this->request->getStringParam('redirect', 'edit'); - $values = $this->prepareValues($redirect, $project, $values); + $values = $this->prepareValues($project, $values); list($valid, $errors) = $this->projectValidator->validateModification($values); if ($valid) { if ($this->projectModel->update($values)) { $this->flash->success(t('Project updated successfully.')); - return $this->response->redirect($this->helper->url->to('ProjectEditController', $redirect, array('project_id' => $project['id'])), true); + return $this->response->redirect($this->helper->url->to('ProjectEditController', 'show', array('project_id' => $project['id'])), true); } else { $this->flash->failure(t('Unable to update this project.')); } } - return $this->$redirect($values, $errors); + return $this->show($values, $errors); } /** * Prepare form values * * @access private - * @param string $redirect * @param array $project * @param array $values * @return array */ - private function prepareValues($redirect, array $project, array $values) + private function prepareValues(array $project, array $values) { - if ($redirect === 'edit') { - if (isset($values['is_private'])) { - if (! $this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { - unset($values['is_private']); - } - } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { - if ($this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { - $values += array('is_private' => 0); - } + if (isset($values['is_private'])) { + if (! $this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { + unset($values['is_private']); + } + } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { + if ($this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { + $values += array('is_private' => 0); } } return $values; } - - /** - * Common method to render different views - * - * @access private - * @param string $template - * @param array $values - * @param array $errors - */ - private function renderView($template, array $values, array $errors) - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project($template, array( - 'owners' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true), - 'values' => empty($values) ? $project : $values, - 'errors' => $errors, - 'project' => $project, - 'title' => t('Edit project') - ))); - } } diff --git a/app/Controller/TaskGanttCreationController.php b/app/Controller/TaskGanttCreationController.php deleted file mode 100644 index c5046f60..00000000 --- a/app/Controller/TaskGanttCreationController.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -namespace Kanboard\Controller; - -/** - * Class TaskGanttCreationController - * - * @package Kanboard\Controller - * @author Frederic Guillot - */ -class TaskGanttCreationController extends BaseController -{ - /** - * Simplified form to create a new task - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function show(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - $values = $values + array( - 'project_id' => $project['id'], - 'column_id' => $this->columnModel->getFirstColumnId($project['id']), - 'position' => 1 - ); - - $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); - $values = $this->hook->merge('controller:gantt:task:form:default', $values, array('default_values' => $values)); - - $this->response->html($this->template->render('task_gantt_creation/show', array( - 'project' => $project, - 'errors' => $errors, - 'values' => $values, - 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, true), - 'categories_list' => $this->categoryModel->getList($project['id']), - 'swimlanes_list' => $this->swimlaneModel->getList($project['id'], false, true), - ))); - } - - /** - * Validate and save a new task - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->taskValidator->validateCreation($values); - - if ($valid && $this->taskCreationModel->create($values)) { - $this->flash->success(t('Task created successfully.')); - $this->response->redirect($this->helper->url->to('TaskGanttController', 'show', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to create your task.')); - $this->show($values, $errors); - } - } -} diff --git a/app/Controller/TaskMovePositionController.php b/app/Controller/TaskMovePositionController.php index caa074c9..39687b79 100644 --- a/app/Controller/TaskMovePositionController.php +++ b/app/Controller/TaskMovePositionController.php @@ -38,7 +38,7 @@ class TaskMovePositionController extends BaseController throw new AccessForbiddenException(e('You are not allowed to move this task.')); } - $result = $this->taskPositionModel->movePosition( + $this->taskPositionModel->movePosition( $task['project_id'], $task['id'], $values['column_id'], @@ -46,6 +46,6 @@ class TaskMovePositionController extends BaseController $values['swimlane_id'] ); - $this->response->json(array('result' => $result)); + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } } |