Refactoring/rewrite of modal boxes handling

This commit is contained in:
Frederic Guillot
2017-01-02 17:01:27 -05:00
parent d49ce63e51
commit 3833c12ccc
173 changed files with 1526 additions and 1654 deletions

View File

@@ -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);
}
$project = $this->getProject();
/**
* 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);
}
/**
* 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')
)));
}
}