fix: remove duplicate openOnlyofficeEditor, add destroy check before reopen

This commit is contained in:
root
2026-07-16 11:46:14 +00:00
parent 9e3c296427
commit 46d2bf4931
4 changed files with 36 additions and 31 deletions

View File

@@ -260,8 +260,41 @@ async function loadOnlyofficeTemplates() {
}
}
// Force save the document
function forceSaveOnlyoffice() {
if (onlyofficeEditorInstance) {
// The ONLYOFFICE editor's onSave event will trigger the callback
// which saves the file to our backend
toast('Saving... changes will be stored automatically');
}
}
// Close the editor and clean up
function closeOnlyofficeEditor() {
if (onlyofficeEditorInstance) {
try {
onlyofficeEditorInstance.destroyEditor();
} catch (e) {
console.error('Error closing editor:', e);
}
onlyofficeEditorInstance = null;
}
closeModal();
// Force a small delay then reload the template list so the
// user sees the updated list with the latest save timestamp
setTimeout(() => {
loadOnlyofficeTemplates();
}, 500);
}
// Open ONLYOFFICE editor in a modal
async function openOnlyofficeEditor(templateId, templateName) {
// If there's a previous editor instance still lingering, destroy it first
if (onlyofficeEditorInstance) {
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
onlyofficeEditorInstance = null;
}
try {
// Get the JWT-signed editor config from our backend
// Add cache-buster to prevent browser caching the old config
@@ -335,34 +368,6 @@ async function openOnlyofficeEditor(templateId, templateName) {
toast('Failed to open editor: ' + e.message, 'error');
}
}
// Force save the document
function forceSaveOnlyoffice() {
if (onlyofficeEditorInstance) {
// The ONLYOFFICE editor's onSave event will trigger the callback
// which saves the file to our backend
toast('Saving... changes will be stored automatically');
}
}
// Close the editor and clean up
function closeOnlyofficeEditor() {
if (onlyofficeEditorInstance) {
try {
onlyofficeEditorInstance.destroyEditor();
} catch (e) {
console.error('Error closing editor:', e);
}
onlyofficeEditorInstance = null;
}
closeModal();
// Wait 1.5s for ONLYOFFICE save callbacks to settle, then refresh
setTimeout(() => {
loadOnlyofficeTemplates();
}, 1500);
}
// Call status check when templates page becomes active
document.addEventListener('DOMContentLoaded', () => {
const templatesPage = document.getElementById('page-templates');
if (templatesPage) {