Drafts system implemented

This commit is contained in:
2026-08-05 17:16:09 -05:00
parent 203ff88af1
commit 49c4ff681f
13 changed files with 419 additions and 75 deletions
+9 -2
View File
@@ -9,6 +9,13 @@
(document.getElementById('packs-draft-uploads') || { textContent: '[]' }).textContent
);
const draftUuidEl = document.getElementById('packs-draft-uuid');
let draftUuid = '';
if (draftUuidEl) {
try { draftUuid = JSON.parse(draftUuidEl.textContent || '""'); }
catch (e) { draftUuid = draftUuidEl.textContent; }
}
const autosaveStatus = document.getElementById('autosave-status');
const csrf = getCookie('csrftoken');
const csrfHeader = csrf ? { 'X-CSRFToken': csrf } : {};
@@ -50,7 +57,7 @@
xhr.onerror = function () {
setStatus('<i class="fas fa-exclamation-triangle"></i> Save failed', 'error');
};
xhr.send(JSON.stringify({ data }));
xhr.send(JSON.stringify({ draft: draftUuid, data }));
}
function initAutosave() {
@@ -67,7 +74,7 @@
setTimeout(() => setStatus('<i class="fas fa-check"></i> Saved just now', 'saved'), 2000);
}
PacksUploads.init({ pending: pending, onReady: initAutosave });
PacksUploads.init({ pending: pending, draftUuid: draftUuid, onReady: initAutosave });
function getCookie(name) {
let cookieValue = null;
+2
View File
@@ -21,6 +21,7 @@
function init(options) {
const opts = options || {};
const pending = opts.pending || [];
const draftUuid = opts.draftUuid || '';
const csrf = getCookie('csrftoken');
const csrfHeader = csrf ? { 'X-CSRFToken': csrf } : {};
@@ -112,6 +113,7 @@
const fd = new FormData();
fd.append('file', file);
fd.append('kind', z.kind);
if (draftUuid) fd.append('draft_uuid', draftUuid);
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/uploads/');