Add the possibility to duplicate a task to another project

This commit is contained in:
Frédéric Guillot
2014-09-01 19:36:40 -08:00
parent e496554654
commit e6d0658a0e
13 changed files with 205 additions and 45 deletions

View File

@@ -432,6 +432,26 @@ class Task extends Base
* @access public
*/
public function move()
{
$this->toAnotherProject('move');
}
/**
* Duplicate a task to another project
*
* @access public
*/
public function copy()
{
$this->toAnotherProject('duplicate');
}
/**
* Common methods between the actions "move" and "copy"
*
* @access private
*/
private function toAnotherProject($action)
{
$task = $this->getTask();
$values = $task;
@@ -446,23 +466,24 @@ class Task extends Base
list($valid, $errors) = $this->task->validateProjectModification($values);
if ($valid) {
if ($this->task->moveToAnotherProject($values['project_id'], $task)) {
$this->session->flash(t('Task updated successfully.'));
$this->response->redirect('?controller=task&action=show&task_id='.$values['id']);
$task_id = $this->task->{$action.'ToAnotherProject'}($values['project_id'], $task);
if ($task_id) {
$this->session->flash(t('Task created successfully.'));
$this->response->redirect('?controller=task&action=show&task_id='.$task_id);
}
else {
$this->session->flashError(t('Unable to update your task.'));
$this->session->flashError(t('Unable to create your task.'));
}
}
}
$this->response->html($this->taskLayout('task_move_project', array(
$this->response->html($this->taskLayout('task_'.$action.'_project', array(
'values' => $values,
'errors' => $errors,
'task' => $task,
'projects_list' => $projects_list,
'menu' => 'tasks',
'title' => t('Move the task to another project')
'title' => t(ucfirst($action).' the task to another project')
)));
}
}