From abcfd02067b348e1c86f61e7545b93f87ea89569 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 24 Jan 2016 18:15:21 -0500 Subject: Split project edition into multiple pages --- app/Controller/Project.php | 52 ------------------- app/Controller/ProjectEdit.php | 115 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 52 deletions(-) create mode 100644 app/Controller/ProjectEdit.php (limited to 'app/Controller') diff --git a/app/Controller/Project.php b/app/Controller/Project.php index 836bfb45..ffd62b09 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -132,58 +132,6 @@ class Project extends Base ))); } - /** - * Display a form to edit a project - * - * @access public - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - $this->response->html($this->projectLayout('project/edit', array( - 'values' => empty($values) ? $project : $values, - 'errors' => $errors, - 'project' => $project, - 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true), - 'title' => t('Edit project') - ))); - } - - /** - * Validate and update a project - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - if (isset($values['is_private'])) { - if (! $this->helper->user->hasProjectAccess('project', 'create', $project['id'])) { - unset($values['is_private']); - } - } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { - if ($this->helper->user->hasProjectAccess('project', 'create', $project['id'])) { - $values += array('is_private' => 0); - } - } - - list($valid, $errors) = $this->projectValidator->validateModification($values); - - if ($valid) { - if ($this->project->update($values)) { - $this->flash->success(t('Project updated successfully.')); - $this->response->redirect($this->helper->url->to('project', 'edit', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to update this project.')); - } - } - - $this->edit($values, $errors); - } - /** * Remove a project * diff --git a/app/Controller/ProjectEdit.php b/app/Controller/ProjectEdit.php new file mode 100644 index 00000000..3b0a3da3 --- /dev/null +++ b/app/Controller/ProjectEdit.php @@ -0,0 +1,115 @@ +renderView('project_edit/general', $values, $errors); + } + + /** + * Change start and end dates + * + * @access public + */ + public function dates(array $values = array(), array $errors = array()) + { + $this->renderView('project_edit/dates', $values, $errors); + } + + /** + * Change project description + * + * @access public + */ + public function description(array $values = array(), array $errors = array()) + { + $this->renderView('project_edit/description', $values, $errors); + } + + /** + * Validate and update a project + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + $redirect = $this->request->getStringParam('redirect', 'edit'); + + $values = $this->prepareValues($redirect, $project, $values); + list($valid, $errors) = $this->projectValidator->validateModification($values); + + if ($valid) { + if ($this->project->update($values)) { + $this->flash->success(t('Project updated successfully.')); + $this->response->redirect($this->helper->url->to('ProjectEdit', $redirect, array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to update this project.')); + } + } + + $this->$redirect($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) + { + if ($redirect === 'edit') { + if (isset($values['is_private'])) { + if (! $this->helper->user->hasProjectAccess('project', 'create', $project['id'])) { + unset($values['is_private']); + } + } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { + if ($this->helper->user->hasProjectAccess('project', 'create', $project['id'])) { + $values += array('is_private' => 0); + } + } + } + + return $values; + } + + /** + * Common metthod 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->projectLayout($template, array( + 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true), + 'values' => empty($values) ? $project : $values, + 'errors' => $errors, + 'project' => $project, + 'title' => t('Edit project') + ))); + } +} -- cgit v1.2.3