Simplify code to handle ajax popover and redirects
This commit is contained in:
@@ -17,9 +17,7 @@ class Taskstatus extends Base
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$this->changeStatus($task, 'close', t('Task closed successfully.'), t('Unable to close this task.'));
|
||||
$this->renderTemplate($task, 'task_status/close');
|
||||
$this->changeStatus('close', 'task_status/close', t('Task closed successfully.'), t('Unable to close this task.'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,13 +27,22 @@ class Taskstatus extends Base
|
||||
*/
|
||||
public function open()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$this->changeStatus($task, 'open', t('Task opened successfully.'), t('Unable to open this task.'));
|
||||
$this->renderTemplate($task, 'task_status/open');
|
||||
$this->changeStatus('open', 'task_status/open', t('Task opened successfully.'), t('Unable to open this task.'));
|
||||
}
|
||||
|
||||
private function changeStatus(array $task, $method, $success_message, $failure_message)
|
||||
/**
|
||||
* Common method to change status
|
||||
*
|
||||
* @access private
|
||||
* @param string $method
|
||||
* @param string $template
|
||||
* @param string $success_message
|
||||
* @param string $failure_message
|
||||
*/
|
||||
private function changeStatus($method, $template, $success_message, $failure_message)
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if ($this->request->getStringParam('confirmation') === 'yes') {
|
||||
$this->checkCSRFParam();
|
||||
|
||||
@@ -45,28 +52,11 @@ class Taskstatus extends Base
|
||||
$this->flash->failure($failure_message);
|
||||
}
|
||||
|
||||
if ($this->request->getStringParam('redirect') === 'board') {
|
||||
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id'])));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
|
||||
}
|
||||
}
|
||||
|
||||
private function renderTemplate(array $task, $template)
|
||||
{
|
||||
$redirect = $this->request->getStringParam('redirect');
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$this->response->html($this->template->render($template, array(
|
||||
'task' => $task,
|
||||
'redirect' => $redirect,
|
||||
)));
|
||||
return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true);
|
||||
}
|
||||
|
||||
$this->response->html($this->taskLayout($template, array(
|
||||
'task' => $task,
|
||||
'redirect' => $redirect,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user