From 7bb09c3f9b3440cf297104f32e80050601d61533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 1 Sep 2014 21:10:27 -0800 Subject: [PATCH] Improve task controller and fix bug description popover --- app/Controller/Task.php | 161 ++++++++++-------------- app/Model/Acl.php | 18 +-- app/Templates/board_task.php | 2 +- app/Templates/task_close.php | 2 +- app/Templates/task_edit_description.php | 2 +- app/Templates/task_open.php | 2 +- app/Templates/task_remove.php | 2 +- app/Templates/task_sidebar.php | 8 +- assets/js/app.js | 37 ++++-- 9 files changed, 101 insertions(+), 133 deletions(-) diff --git a/app/Controller/Task.php b/app/Controller/Task.php index e905ef30f..444065f0f 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -233,27 +233,21 @@ class Task extends Base */ public function close() { - $this->checkCSRFParam(); $task = $this->getTask(); - if ($this->task->close($task['id'])) { - $this->session->flash(t('Task closed successfully.')); - } else { - $this->session->flashError(t('Unable to close this task.')); + if ($this->request->getStringParam('confirmation') === 'yes') { + + $this->checkCSRFParam(); + + if ($this->task->close($task['id'])) { + $this->session->flash(t('Task closed successfully.')); + } else { + $this->session->flashError(t('Unable to close this task.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); - } - - /** - * Confirmation dialog before to close a task - * - * @access public - */ - public function confirmClose() - { - $task = $this->getTask(); - $this->response->html($this->taskLayout('task_close', array( 'task' => $task, 'menu' => 'tasks', @@ -268,27 +262,21 @@ class Task extends Base */ public function open() { - $this->checkCSRFParam(); $task = $this->getTask(); - if ($this->task->open($task['id'])) { - $this->session->flash(t('Task opened successfully.')); - } else { - $this->session->flashError(t('Unable to open this task.')); + if ($this->request->getStringParam('confirmation') === 'yes') { + + $this->checkCSRFParam(); + + if ($this->task->open($task['id'])) { + $this->session->flash(t('Task opened successfully.')); + } else { + $this->session->flashError(t('Unable to open this task.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); - } - - /** - * Confirmation dialog before to open a task - * - * @access public - */ - public function confirmOpen() - { - $task = $this->getTask(); - $this->response->html($this->taskLayout('task_open', array( 'task' => $task, 'menu' => 'tasks', @@ -303,27 +291,21 @@ class Task extends Base */ public function remove() { - $this->checkCSRFParam(); $task = $this->getTask(); - if ($this->task->remove($task['id'])) { - $this->session->flash(t('Task removed successfully.')); - } else { - $this->session->flashError(t('Unable to remove this task.')); + if ($this->request->getStringParam('confirmation') === 'yes') { + + $this->checkCSRFParam(); + + if ($this->task->remove($task['id'])) { + $this->session->flash(t('Task removed successfully.')); + } else { + $this->session->flashError(t('Unable to remove this task.')); + } + + $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); } - $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); - } - - /** - * Confirmation dialog before removing a task - * - * @access public - */ - public function confirmRemove() - { - $task = $this->getTask(); - $this->response->html($this->taskLayout('task_remove', array( 'task' => $task, 'menu' => 'tasks', @@ -366,20 +348,49 @@ class Task extends Base * * @access public */ - public function editDescription() + public function description() { $task = $this->getTask(); + $ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax'); + + if ($this->request->isPost()) { + + $values = $this->request->getValues(); + + list($valid, $errors) = $this->task->validateDescriptionCreation($values); + + if ($valid) { + + if ($this->task->update($values)) { + $this->session->flash(t('Task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } + + if ($ajax) { + $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); + } + else { + $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); + } + } + } + else { + $values = $task; + $errors = array(); + } $params = array( - 'values' => $task, - 'errors' => array(), + 'values' => $values, + 'errors' => $errors, 'task' => $task, - 'ajax' => $this->request->isAjax(), + 'ajax' => $ajax, 'menu' => 'tasks', 'title' => t('Edit the description'), ); - if ($this->request->isAjax()) { + if ($ajax) { $this->response->html($this->template->load('task_edit_description', $params)); } else { @@ -387,44 +398,6 @@ class Task extends Base } } - /** - * Save and validation the description - * - * @access public - */ - public function saveDescription() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->task->validateDescriptionCreation($values); - - if ($valid) { - - if ($this->task->update($values)) { - $this->session->flash(t('Task updated successfully.')); - } - else { - $this->session->flashError(t('Unable to update your task.')); - } - - if ($this->request->getIntegerParam('ajax')) { - $this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']); - } - else { - $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); - } - } - - $this->response->html($this->taskLayout('task_edit_description', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'menu' => 'tasks', - 'title' => t('Edit the description') - ))); - } - /** * Move a task to another project * diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 23f6ff441..f2b287bef 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -37,23 +37,7 @@ class Acl extends Base 'comment' => array('create', 'save', 'confirm', 'remove', 'update', 'edit', 'forbidden'), 'file' => array('create', 'save', 'download', 'confirm', 'remove', 'open', 'image'), 'subtask' => array('create', 'save', 'edit', 'update', 'confirm', 'remove'), - 'task' => array( - 'show', - 'create', - 'save', - 'edit', - 'update', - 'close', - 'confirmclose', - 'open', - 'confirmopen', - 'duplicate', - 'remove', - 'confirmremove', - 'editdescription', - 'savedescription', - 'move', - ), + 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'open', 'duplicate', 'remove', 'description', 'move', 'copy'), ); /** diff --git a/app/Templates/board_task.php b/app/Templates/board_task.php index 0bc965799..4370558b6 100644 --- a/app/Templates/board_task.php +++ b/app/Templates/board_task.php @@ -69,7 +69,7 @@ - '> + diff --git a/app/Templates/task_close.php b/app/Templates/task_close.php index 5c75b72be..2abfd032d 100644 --- a/app/Templates/task_close.php +++ b/app/Templates/task_close.php @@ -8,7 +8,7 @@

- +
\ No newline at end of file diff --git a/app/Templates/task_edit_description.php b/app/Templates/task_edit_description.php index d403190f3..2d2a4d0bf 100644 --- a/app/Templates/task_edit_description.php +++ b/app/Templates/task_edit_description.php @@ -2,7 +2,7 @@

-
+ diff --git a/app/Templates/task_open.php b/app/Templates/task_open.php index 3526ec812..d28970e3a 100644 --- a/app/Templates/task_open.php +++ b/app/Templates/task_open.php @@ -8,7 +8,7 @@

- +
\ No newline at end of file diff --git a/app/Templates/task_remove.php b/app/Templates/task_remove.php index dd4841dbb..496ac2d83 100644 --- a/app/Templates/task_remove.php +++ b/app/Templates/task_remove.php @@ -8,7 +8,7 @@

- +
\ No newline at end of file diff --git a/app/Templates/task_sidebar.php b/app/Templates/task_sidebar.php index 5d93d7b16..4d363fecf 100644 --- a/app/Templates/task_sidebar.php +++ b/app/Templates/task_sidebar.php @@ -4,7 +4,7 @@ \ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index 20af61eb8..68da5fcb0 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -9,22 +9,30 @@ var Kanboard = (function() { e.preventDefault(); e.stopPropagation(); - $.get(e.target.getAttribute("href"), function(content) { + var link = e.target.getAttribute("href"); - $("body").append('
' + content + '
'); + if (! link) { + link = e.target.getAttribute("data-href"); + } - $("#popover-container").click(function() { - $(this).remove(); + if (link) { + $.get(link, function(content) { + + $("body").append('
' + content + '
'); + + $("#popover-container").click(function() { + $(this).remove(); + }); + + $("#popover-content").click(function(e) { + e.stopPropagation(); + }); + + if (callback) { + callback(); + } }); - - $("#popover-content").click(function(e) { - e.stopPropagation(); - }); - - if (callback) { - callback(); - } - }); + } }, // Return true if the page is visible @@ -89,6 +97,9 @@ Kanboard.Board = (function() { Kanboard.Popover(e, Kanboard.Task.Init); }); + // Description popover + $(".task-description-popover").click(Kanboard.Popover); + // Redirect to the task details page $("[data-task-id]").each(function() { $(this).click(function() {