feat: disable Edit Online buttons for 2s during cleanup, re-enable dynamically
This commit is contained in:
@@ -267,6 +267,9 @@ function forceSaveOnlyoffice() {
|
||||
}
|
||||
}
|
||||
|
||||
// Track whether the editor is cleaning up (disable Edit buttons during this)
|
||||
let editorCleaningUp = false;
|
||||
|
||||
// Close the editor — full teardown so the next open is completely fresh
|
||||
function closeOnlyofficeEditor() {
|
||||
if (onlyofficeEditorInstance) {
|
||||
@@ -281,19 +284,44 @@ function closeOnlyofficeEditor() {
|
||||
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
|
||||
if (oldScript) oldScript.remove();
|
||||
|
||||
loadOnlyofficeTemplates();
|
||||
// Disable all "Edit Online" buttons for 2 seconds while ONLYOFFICE
|
||||
// tears down its server-side session, then re-enable them.
|
||||
editorCleaningUp = true;
|
||||
disableEditButtons('Cleaning up...');
|
||||
setTimeout(() => {
|
||||
editorCleaningUp = false;
|
||||
enableEditButtons();
|
||||
loadOnlyofficeTemplates();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// Disable/enable all "Edit Online" buttons with a status label
|
||||
function disableEditButtons(label) {
|
||||
document.querySelectorAll('button[onclick^="openOnlyofficeEditor"]').forEach(btn => {
|
||||
btn.disabled = true;
|
||||
btn.style.opacity = '0.5';
|
||||
btn.style.cursor = 'not-allowed';
|
||||
btn.dataset.originalText = btn.textContent;
|
||||
btn.textContent = label || 'Please wait...';
|
||||
});
|
||||
}
|
||||
function enableEditButtons() {
|
||||
document.querySelectorAll('button[onclick^="openOnlyofficeEditor"]').forEach(btn => {
|
||||
btn.disabled = false;
|
||||
btn.style.opacity = '';
|
||||
btn.style.cursor = '';
|
||||
if (btn.dataset.originalText) btn.textContent = btn.dataset.originalText;
|
||||
});
|
||||
}
|
||||
|
||||
// Open ONLYOFFICE editor in a modal
|
||||
async function openOnlyofficeEditor(templateId, templateName) {
|
||||
// Block reopening if a previous editor is still tearing down.
|
||||
// destroyEditor() is async — the ONLYOFFICE websocket/session needs
|
||||
// time to close before a new editor can be created cleanly.
|
||||
// Don't open if cleanup is in progress
|
||||
if (editorCleaningUp) return;
|
||||
|
||||
if (onlyofficeEditorInstance) {
|
||||
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
|
||||
onlyofficeEditorInstance = null;
|
||||
// Give ONLYOFFICE's internal session 2 seconds to fully close
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<!-- Modals -->
|
||||
<div class="modal-overlay" id="modal-overlay"></div>
|
||||
|
||||
<script src="/static/app.js?v=13"></script>
|
||||
<script src="/static/carbone.js?v=13"></script>
|
||||
<script src="/static/app.js?v=14"></script>
|
||||
<script src="/static/carbone.js?v=14"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user