Refactoring/rewrite of modal boxes handling
This commit is contained in:
@@ -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')
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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'])));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user