Drafts system implemented
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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/');
|
||||
|
||||
Reference in New Issue
Block a user