feat: disable Edit Online buttons for 2s during cleanup, re-enable dynamically
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,6 @@
|
|||||||
"originalName": "master_cv_template.docx",
|
"originalName": "master_cv_template.docx",
|
||||||
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
||||||
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
||||||
"updatedAt": "2026-07-17T09:01:35.526Z"
|
"updatedAt": "2026-07-17T09:04:41.170Z"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -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
|
// Close the editor — full teardown so the next open is completely fresh
|
||||||
function closeOnlyofficeEditor() {
|
function closeOnlyofficeEditor() {
|
||||||
if (onlyofficeEditorInstance) {
|
if (onlyofficeEditorInstance) {
|
||||||
@@ -281,19 +284,44 @@ function closeOnlyofficeEditor() {
|
|||||||
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
|
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
|
||||||
if (oldScript) oldScript.remove();
|
if (oldScript) oldScript.remove();
|
||||||
|
|
||||||
|
// 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();
|
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
|
// Open ONLYOFFICE editor in a modal
|
||||||
async function openOnlyofficeEditor(templateId, templateName) {
|
async function openOnlyofficeEditor(templateId, templateName) {
|
||||||
// Block reopening if a previous editor is still tearing down.
|
// Don't open if cleanup is in progress
|
||||||
// destroyEditor() is async — the ONLYOFFICE websocket/session needs
|
if (editorCleaningUp) return;
|
||||||
// time to close before a new editor can be created cleanly.
|
|
||||||
if (onlyofficeEditorInstance) {
|
if (onlyofficeEditorInstance) {
|
||||||
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
|
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
|
||||||
onlyofficeEditorInstance = null;
|
onlyofficeEditorInstance = null;
|
||||||
// Give ONLYOFFICE's internal session 2 seconds to fully close
|
|
||||||
await new Promise(r => setTimeout(r, 2000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
<!-- Modals -->
|
<!-- Modals -->
|
||||||
<div class="modal-overlay" id="modal-overlay"></div>
|
<div class="modal-overlay" id="modal-overlay"></div>
|
||||||
|
|
||||||
<script src="/static/app.js?v=13"></script>
|
<script src="/static/app.js?v=14"></script>
|
||||||
<script src="/static/carbone.js?v=13"></script>
|
<script src="/static/carbone.js?v=14"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user