Commit d4a861b7 authored by Jan Koester's avatar Jan Koester
Browse files

editor: ?document=<id> oeffnet das verlinkte Dokument

Links aus dem Blog (Verwaltung, Freigabe-Mail) zeigen auf
<editor>/?document=<id>; das Frontend hat den Parameter bisher ignoriert
und das zuletzt offene Dokument geladen. Die ID uebersteht auch den Umweg
ueber login.html (sessionStorage) und wird danach aus der URL entfernt.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 960caf9e
Loading
Loading
Loading
Loading
+37 −0
Changes for editor/html/js/editor.js: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -280,8 +280,45 @@
        });
    }

    // Deep link: index.html?document=<id> opens that document (e.g. links from the
    // blog's admin pages or approval mails). The id is parked in sessionStorage first
    // so it survives a detour through login.html (401 redirect drops the query).
    var OPEN_DOCUMENT_STORAGE_KEY = 'blogi-open-document';

    function loadDocument() {
        var docId = '';
        try { docId = new URLSearchParams(window.location.search).get('document') || ''; } catch(e) {}
        if (docId) {
            try { sessionStorage.setItem(OPEN_DOCUMENT_STORAGE_KEY, docId); } catch(e) {}
        } else {
            try { docId = sessionStorage.getItem(OPEN_DOCUMENT_STORAGE_KEY) || ''; } catch(e) {}
        }
        if (!docId || !/^[A-Za-z0-9_-]{1,128}$/.test(docId)) {
            refreshDocument();
            return;
        }
        EditorApi.loadDocument(docId).then(function(resp) {
            try { sessionStorage.removeItem(OPEN_DOCUMENT_STORAGE_KEY); } catch(e) {}
            currentDocGroup = (resp && resp.group) || '';
            dropDocumentParam();
            refreshDocument();
        }).catch(function(err) {
            try { sessionStorage.removeItem(OPEN_DOCUMENT_STORAGE_KEY); } catch(e) {}
            console.error('Failed to open document ' + docId + ':', err);
            alert(I18n.t('I18N_ACTION_FAILED', 'Aktion fehlgeschlagen') + ': ' + ((err && err.error) || docId));
            dropDocumentParam();
            refreshDocument();
        });
    }

    // Remove ?document= so a reload keeps the document the user is working on
    function dropDocumentParam() {
        try {
            var u = new URL(window.location.href);
            if (!u.searchParams.has('document')) return;
            u.searchParams.delete('document');
            history.replaceState(null, '', u.pathname + u.search + u.hash);
        } catch(e) {}
    }

    // --- Toolbar bindings ---