fix: remove duplicate openOnlyofficeEditor, add destroy check before reopen
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<!-- Modals -->
|
||||
<div class="modal-overlay" id="modal-overlay"></div>
|
||||
|
||||
<script src="/static/app.js?v=4"></script>
|
||||
<script src="/static/carbone.js?v=4"></script>
|
||||
<script src="/static/app.js?v=5"></script>
|
||||
<script src="/static/carbone.js?v=5"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user