Prompt user when moving or duplicate a task to another project
This commit is contained in:
@@ -366,34 +366,6 @@ class Task extends Base
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate a task
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function duplicate()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if ($this->request->getStringParam('confirmation') === 'yes') {
|
||||
|
||||
$this->checkCSRFParam();
|
||||
$task_id = $this->taskDuplication->duplicate($task['id']);
|
||||
|
||||
if ($task_id) {
|
||||
$this->session->flash(t('Task created successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
} else {
|
||||
$this->session->flashError(t('Unable to create this task.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout('task/duplicate', array(
|
||||
'task' => $task,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit description form
|
||||
*
|
||||
@@ -492,84 +464,6 @@ class Task extends Base
|
||||
$this->response->html($this->taskLayout('task/edit_recurrence', $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a task to another project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function move()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$values = $task;
|
||||
$errors = array();
|
||||
$projects_list = $this->projectPermission->getActiveMemberProjects($this->userSession->getId());
|
||||
|
||||
unset($projects_list[$task['project_id']]);
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
|
||||
|
||||
if ($valid) {
|
||||
|
||||
if ($this->taskDuplication->moveToProject($task['id'], $values['project_id'])) {
|
||||
$this->session->flash(t('Task updated successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
else {
|
||||
$this->session->flashError(t('Unable to update your task.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout('task/move_project', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'task' => $task,
|
||||
'projects_list' => $projects_list,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate a task to another project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$values = $task;
|
||||
$errors = array();
|
||||
$projects_list = $this->projectPermission->getActiveMemberProjects($this->userSession->getId());
|
||||
|
||||
unset($projects_list[$task['project_id']]);
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
|
||||
|
||||
if ($valid) {
|
||||
$task_id = $this->taskDuplication->duplicateToProject($task['id'], $values['project_id']);
|
||||
if ($task_id) {
|
||||
$this->session->flash(t('Task created successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
else {
|
||||
$this->session->flashError(t('Unable to create your task.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout('task/duplicate_project', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'task' => $task,
|
||||
'projects_list' => $projects_list,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the time tracking details
|
||||
*
|
||||
|
||||
143
app/Controller/Taskduplication.php
Normal file
143
app/Controller/Taskduplication.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace Controller;
|
||||
|
||||
/**
|
||||
* Task Duplication controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Taskduplication extends Base
|
||||
{
|
||||
/**
|
||||
* Duplicate a task
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function duplicate()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if ($this->request->getStringParam('confirmation') === 'yes') {
|
||||
|
||||
$this->checkCSRFParam();
|
||||
$task_id = $this->taskDuplication->duplicate($task['id']);
|
||||
|
||||
if ($task_id > 0) {
|
||||
$this->session->flash(t('Task created successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
} else {
|
||||
$this->session->flashError(t('Unable to create this task.'));
|
||||
$this->response->redirect($this->helper->url->to('taskduplication', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout('task_duplication/duplicate', array(
|
||||
'task' => $task,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a task to another project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function move()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
|
||||
|
||||
if ($valid && $this->taskDuplication->moveToProject($task['id'],
|
||||
$values['project_id'],
|
||||
$values['swimlane_id'],
|
||||
$values['column_id'],
|
||||
$values['category_id'],
|
||||
$values['owner_id'])) {
|
||||
|
||||
$this->session->flash(t('Task updated successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $values['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
|
||||
$this->session->flashError(t('Unable to update your task.'));
|
||||
}
|
||||
|
||||
$this->chooseDestination($task, 'task_duplication/move');
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate a task to another project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
|
||||
|
||||
if ($valid && $this->taskDuplication->duplicateToProject($task['id'],
|
||||
$values['project_id'],
|
||||
$values['swimlane_id'],
|
||||
$values['column_id'],
|
||||
$values['category_id'],
|
||||
$values['owner_id'])) {
|
||||
|
||||
$this->session->flash(t('Task created successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
|
||||
}
|
||||
|
||||
$this->session->flashError(t('Unable to create your task.'));
|
||||
}
|
||||
|
||||
$this->chooseDestination($task, 'task_duplication/copy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose destination when move/copy task to another project
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function chooseDestination(array $task, $template)
|
||||
{
|
||||
$values = array();
|
||||
$projects_list = $this->projectPermission->getActiveMemberProjects($this->userSession->getId());
|
||||
|
||||
unset($projects_list[$task['project_id']]);
|
||||
|
||||
if (! empty($projects_list)) {
|
||||
$dst_project_id = $this->request->getIntegerParam('dst_project_id', key($projects_list));
|
||||
|
||||
$swimlanes_list = $this->swimlane->getList($dst_project_id, false, true);
|
||||
$columns_list = $this->board->getColumnsList($dst_project_id);
|
||||
$categories_list = $this->category->getList($dst_project_id);
|
||||
$users_list = $this->projectPermission->getMemberList($dst_project_id);
|
||||
|
||||
$values = $this->taskDuplication->checkDestinationProjectValues($task);
|
||||
$values['project_id'] = $dst_project_id;
|
||||
}
|
||||
else {
|
||||
$swimlanes_list = array();
|
||||
$columns_list = array();
|
||||
$categories_list = array();
|
||||
$users_list = array();
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout($template, array(
|
||||
'values' => $values,
|
||||
'task' => $task,
|
||||
'projects_list' => $projects_list,
|
||||
'swimlanes_list' => $swimlanes_list,
|
||||
'columns_list' => $columns_list,
|
||||
'categories_list' => $categories_list,
|
||||
'users_list' => $users_list,
|
||||
)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user