From 01c6bb3d09f2e3140edb5e0cf27f5771f011b021 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Thu, 2 Oct 2025 10:09:25 -0500 Subject: [PATCH] Edit logic implemented. --- inventory/templates/update_list.html | 38 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/inventory/templates/update_list.html b/inventory/templates/update_list.html index 096543b..6062dbd 100644 --- a/inventory/templates/update_list.html +++ b/inventory/templates/update_list.html @@ -4,7 +4,7 @@ {% for n in items %}
  • -
    +
    @@ -61,14 +61,46 @@ container.dataset.prev = container.innerHTML; container.innerHTML = ` - +
    - + + +
    +
    `; } else { // Switch to viewer mode renderView(id, contents[id]); } } + + function saveEdit(id) { + const textarea = document.getElementById(`editor${id}`); + const value = textarea.value; + contents[id] = value; + renderView(id, value); + + document.getElementById(`editSwitch${id}`).checked = false; + } + + function cancelEdit(id) { + document.getElementById(`editSwitch${id}`).checked = false; + renderView(id, contents[id]); + } + + function togglePreview(id) { + const textarea = document.getElementById(`editor${id}`); + const preview = document.getElementById(`preview${id}`); + preview.classList.toggle('d-none'); + if (!preview.classList.contains('d-none')) { + const html = marked.parse(textarea.value ?? ""); + preview.innerHTML = DOMPurify.sanitize(html); + } + } + + function escapeForTextarea(s) { + // Keep control of what goes inside the textarea + return (s ?? "").replace(/&/g,'&').replace(//g,'>'); + }