Add ticket status setter and prevent draft text loss
- Set ticket state (Offen / In Bearbeitung / Warten auf Schließen / Geschlossen) from the ticket detail page via a live PUT to Zammad; pending-close gets a default pending time and the change is synced back so it isn't flagged as an external change - Replace the disruptive meta-refresh with a JS auto-refresh that pauses while a text field has unsent content or focus - Persist reply/new-ticket drafts to localStorage and restore them after a reload or accidental navigation Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Allgemeines Verhalten: Entwurf-Speicherung + ungefährlicher Auto-Refresh.
|
||||
(function () {
|
||||
// --- 1) Entwürfe sichern (überlebt Reload / versehentliches Wegnavigieren) ---
|
||||
function draftKey(el) {
|
||||
return "episupport-draft:" + location.pathname + ":" + (el.name || el.id || "x");
|
||||
}
|
||||
var drafts = document.querySelectorAll("[data-draft]");
|
||||
drafts.forEach(function (el) {
|
||||
try {
|
||||
var saved = localStorage.getItem(draftKey(el));
|
||||
if (saved && !el.value) el.value = saved;
|
||||
} catch (e) {}
|
||||
el.addEventListener("input", function () {
|
||||
try {
|
||||
if (el.value) localStorage.setItem(draftKey(el), el.value);
|
||||
else localStorage.removeItem(draftKey(el));
|
||||
} catch (e) {}
|
||||
});
|
||||
});
|
||||
// Beim Absenden die zugehörigen Entwürfe löschen
|
||||
document.querySelectorAll("form").forEach(function (form) {
|
||||
form.addEventListener("submit", function () {
|
||||
form.querySelectorAll("[data-draft]").forEach(function (el) {
|
||||
try { localStorage.removeItem(draftKey(el)); } catch (e) {}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// --- 2) Auto-Refresh, aber NIE während des Tippens/ungesendeten Texts ---
|
||||
var INTERVAL = 120000; // 2 Minuten
|
||||
function hasUnsavedInput() {
|
||||
var a = document.activeElement;
|
||||
if (a && /^(TEXTAREA|INPUT|SELECT)$/.test(a.tagName)) return true;
|
||||
var fields = document.querySelectorAll("textarea, input[type=text], input:not([type])");
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
if ((fields[i].value || "").trim() !== "") return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
setInterval(function () {
|
||||
if (!hasUnsavedInput()) location.reload();
|
||||
}, INTERVAL);
|
||||
})();
|
||||
Reference in New Issue
Block a user