diff --git a/Asset/js/save-close.js b/Asset/js/save-close.js new file mode 100644 index 0000000..12fa30a --- /dev/null +++ b/Asset/js/save-close.js @@ -0,0 +1,39 @@ +/* + * OrganonTweaks -- the "Save & Close" button on the task edit form. It is a plain type=button (so it + * never becomes the Enter default -- Enter still triggers the core Save), and on click it repoints + * the form to the plugin's TaskSaveCloseController and lets Kanboard's own modal submit it. Kanboard + * keeps ownership of the POST, CSRF, error re-render, and the X-Ajax-Redirect navigation; we only + * change the destination, so the controller redirects to the board instead of the card view. + */ +(function () { + "use strict"; + + document.addEventListener("click", function (e) { + if (!e.target || !e.target.closest) { + return; + } + + var btn = e.target.closest("[data-organon-save-close]"); + if (!btn) { + return; + } + + e.preventDefault(); + + var form = btn.closest("form"); + var url = btn.getAttribute("data-url"); + if (!form || !url) { + return; + } + + form.setAttribute("action", url); + + if (window.KB && KB.modal && KB.modal.isOpen && KB.modal.isOpen() && KB.modal.submitForm) { + KB.modal.submitForm(); + } else if (form.requestSubmit) { + form.requestSubmit(); + } else { + form.submit(); + } + }, false); +})(); diff --git a/Controller/TaskSaveCloseController.php b/Controller/TaskSaveCloseController.php new file mode 100644 index 0000000..a402079 --- /dev/null +++ b/Controller/TaskSaveCloseController.php @@ -0,0 +1,33 @@ +getTask(); + $values = $this->request->getValues(); + $values['id'] = $task['id']; + $values['project_id'] = $task['project_id']; + + list($valid, $errors) = $this->taskValidator->validateModification($values); + + if ($valid && $this->updateTask($task, $values, $errors)) { + $this->flash->success(t('Task updated successfully.')); + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $task['project_id'])), true); + } else { + $this->flash->failure(t('Unable to update your task.')); + $this->edit($values, $errors); + } + } +} diff --git a/Template/task_form/save_close_button.php b/Template/task_form/save_close_button.php new file mode 100644 index 0000000..b5a9ed3 --- /dev/null +++ b/Template/task_form/save_close_button.php @@ -0,0 +1,8 @@ + + 0): ?> + +