add Save & Close button on the task edit form v1.8 t2

This commit is contained in:
2026-07-10 18:18:26 -03:00
parent ac8e3b9544
commit 269964d4cc
3 changed files with 80 additions and 0 deletions

39
Asset/js/save-close.js Normal file
View File

@@ -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);
})();

View File

@@ -0,0 +1,33 @@
<?php
namespace Kanboard\Plugin\OrganonTweaks\Controller;
use Kanboard\Controller\TaskModificationController;
/**
* "Save & Close": the exact core task update, but on success it redirects to the BOARD instead of
* reopening the card view. The plugin's "Save & Close" button repoints the edit form here (via JS),
* so everything else -- validation, permission checks, CSRF, and the modal error re-render -- is
* inherited unchanged from core TaskModificationController. This mirrors core update() line for line
* except the one redirect target (kept in sync on Kanboard upgrades).
*/
class TaskSaveCloseController extends TaskModificationController
{
public function update()
{
$task = $this->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);
}
}
}

View File

@@ -0,0 +1,8 @@
<?php $task_id = isset($values['id']) ? (int) $values['id'] : 0 ?>
<?php if ($task_id > 0): ?>
<button type="button" class="btn"
data-organon-save-close="1"
data-url="<?= $this->url->href('TaskSaveCloseController', 'update', array('plugin' => 'OrganonTweaks', 'task_id' => $task_id)) ?>">
<?= t('Save & Close') ?>
</button>
<?php endif ?>