Phase 16Q Fix - Word Companion Unlink Button Does Nothing
This commit is contained in:
parent
7356a1c6b1
commit
5ff2713afb
@ -498,6 +498,21 @@
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<dialog class="word-companion-dialog" data-unlink-word-document-dialog>
|
||||
<form method="dialog">
|
||||
<div class="word-companion-section-header">
|
||||
<span>Unlink Word Document?</span>
|
||||
</div>
|
||||
<p class="word-companion-dialog-copy">This will remove PlotDirector binding metadata from this Word document.</p>
|
||||
<p class="word-companion-dialog-copy">If PlotDirector is reachable, it will also unlink this Book in PlotDirector.</p>
|
||||
<p class="word-companion-dialog-copy">Your manuscript text will not be changed.</p>
|
||||
<div class="word-companion-dialog-actions">
|
||||
<button type="button" data-unlink-word-document-confirm>Continue</button>
|
||||
<button type="button" data-unlink-word-document-cancel>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
}
|
||||
</main>
|
||||
<script src="~/js/word-companion-host.js" asp-append-version="true"></script>
|
||||
|
||||
@ -38,6 +38,9 @@
|
||||
const firstRunReplaceDialog = document.querySelector("[data-first-run-replace-dialog]");
|
||||
const firstRunReplaceConfirm = document.querySelector("[data-first-run-replace-confirm]");
|
||||
const firstRunReplaceCancel = document.querySelector("[data-first-run-replace-cancel]");
|
||||
const unlinkWordDocumentDialog = document.querySelector("[data-unlink-word-document-dialog]");
|
||||
const unlinkWordDocumentConfirm = document.querySelector("[data-unlink-word-document-confirm]");
|
||||
const unlinkWordDocumentCancel = document.querySelector("[data-unlink-word-document-cancel]");
|
||||
const officeStatus = document.querySelector("[data-office-status]");
|
||||
const connectionStatus = document.querySelector("[data-connection-status]");
|
||||
const summaryConnection = document.querySelector("[data-summary-connection]");
|
||||
@ -1343,6 +1346,27 @@
|
||||
};
|
||||
};
|
||||
|
||||
const currentDocumentBinding = () => {
|
||||
const binding = firstRunDocumentBinding || readDocumentBinding();
|
||||
if (binding) {
|
||||
return binding;
|
||||
}
|
||||
|
||||
const documentGuid = runtimeBookContext?.manuscriptDocument?.documentGuid || "";
|
||||
const bookId = Number.parseInt(runtimeBookContext?.bookId || "", 10);
|
||||
const projectId = Number.parseInt(runtimeBookContext?.projectId || "", 10);
|
||||
if (documentGuid && Number.isInteger(bookId) && bookId > 0 && Number.isInteger(projectId) && projectId > 0) {
|
||||
return {
|
||||
documentGuid,
|
||||
bookId,
|
||||
projectId,
|
||||
bindingVersion: Number.parseInt(runtimeBookContext?.manuscriptDocument?.bindingVersion || "", 10) || 1
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const writeDocumentBinding = (binding) => new Promise((resolve, reject) => {
|
||||
const settings = window.Office?.context?.document?.settings;
|
||||
if (!settings) {
|
||||
@ -2905,6 +2929,32 @@
|
||||
firstRunReplaceDialog.showModal();
|
||||
});
|
||||
|
||||
const requestUnlinkWordDocumentConfirmation = () => new Promise((resolve) => {
|
||||
if (!unlinkWordDocumentDialog || typeof unlinkWordDocumentDialog.showModal !== "function") {
|
||||
resolve(window.confirm("This will remove PlotDirector binding metadata from this Word document.\n\nIf PlotDirector is reachable, it will also unlink this Book in PlotDirector.\n\nYour manuscript text will not be changed.\n\nContinue?"));
|
||||
return;
|
||||
}
|
||||
|
||||
const cleanup = (confirmed) => {
|
||||
unlinkWordDocumentConfirm?.removeEventListener("click", confirmHandler);
|
||||
unlinkWordDocumentCancel?.removeEventListener("click", cancelHandler);
|
||||
unlinkWordDocumentDialog?.removeEventListener("cancel", cancelEventHandler);
|
||||
unlinkWordDocumentDialog?.close();
|
||||
resolve(confirmed);
|
||||
};
|
||||
const confirmHandler = () => cleanup(true);
|
||||
const cancelHandler = () => cleanup(false);
|
||||
const cancelEventHandler = (event) => {
|
||||
event.preventDefault();
|
||||
cleanup(false);
|
||||
};
|
||||
|
||||
unlinkWordDocumentConfirm?.addEventListener("click", confirmHandler);
|
||||
unlinkWordDocumentCancel?.addEventListener("click", cancelHandler);
|
||||
unlinkWordDocumentDialog?.addEventListener("cancel", cancelEventHandler);
|
||||
unlinkWordDocumentDialog.showModal();
|
||||
});
|
||||
|
||||
const importFirstRunManuscript = async () => {
|
||||
const project = selectedFirstRunProject();
|
||||
const book = selectedFirstRunBook();
|
||||
@ -3175,33 +3225,50 @@
|
||||
|
||||
const returnToUnboundOnboarding = async (message) => {
|
||||
firstRunDocumentBinding = null;
|
||||
cancelPendingRuntimeUpdate();
|
||||
clearPendingSceneWordCountSync();
|
||||
clearRuntimeCaches();
|
||||
resetPlotDirectorScene("Not detected");
|
||||
setSceneTrackingState("Manual");
|
||||
setConnectionStatus("Connected");
|
||||
syncFirstRunProjectOptions();
|
||||
if (selectedFirstRunProject()) {
|
||||
await loadBooks(selectedFirstRunProject().projectId, null);
|
||||
} else {
|
||||
resetSelect(firstRunBookSelect, "Select a project first");
|
||||
writeStoredId(storageKeys.projectId, null);
|
||||
writeStoredId(storageKeys.bookId, null);
|
||||
if (projectSelect) {
|
||||
projectSelect.value = "";
|
||||
}
|
||||
resetSelect(bookSelect, "Select a project first");
|
||||
syncFirstRunProjectOptions();
|
||||
if (firstRunProjectSelect) {
|
||||
firstRunProjectSelect.value = "";
|
||||
}
|
||||
resetSelect(firstRunBookSelect, "Select a project first");
|
||||
resetFirstRunPreview(message || "Select a Project and Book to begin.");
|
||||
setDocumentMessage(message || "Manuscript unlinked.");
|
||||
setSyncStatus("No resolved PlotDirector scene.");
|
||||
setFirstRunMode(true);
|
||||
updateUnlinkWordDocumentButton();
|
||||
};
|
||||
|
||||
const unlinkThisWordDocument = async () => {
|
||||
const binding = firstRunDocumentBinding || readDocumentBinding();
|
||||
console.debug("Word Companion unlink clicked");
|
||||
setDocumentMessage("Preparing to unlink manuscript...");
|
||||
const binding = currentDocumentBinding();
|
||||
if (!binding) {
|
||||
setDocumentMessage("This Word document is not linked.");
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed = window.confirm("This will remove PlotDirector binding metadata from this Word document.\n\nIf PlotDirector is reachable, it will also unlink this Book in PlotDirector.\n\nYour manuscript text will not be changed.\n\nContinue?");
|
||||
if (!confirmed) {
|
||||
if (!binding.documentGuid || !Number.isInteger(binding.bookId) || binding.bookId <= 0) {
|
||||
setDocumentMessage("Unable to unlink: bound document metadata is incomplete.");
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed = await requestUnlinkWordDocumentConfirmation();
|
||||
if (!confirmed) {
|
||||
setDocumentMessage("Unlink cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
setDocumentMessage("Unlinking manuscript...");
|
||||
if (unlinkWordDocumentButton) {
|
||||
unlinkWordDocumentButton.disabled = true;
|
||||
unlinkWordDocumentButton.textContent = "Unlinking...";
|
||||
@ -3213,10 +3280,11 @@
|
||||
bookId: binding.bookId
|
||||
});
|
||||
await removeDocumentBinding();
|
||||
await returnToUnboundOnboarding("Word document unlinked. Select a Project and Book to begin.");
|
||||
await returnToUnboundOnboarding("Manuscript unlinked.");
|
||||
} catch (error) {
|
||||
console.error("Unable to unlink manuscript binding.", error);
|
||||
const removeLocalOnly = window.confirm("PlotDirector could not be updated, but you can still remove the binding from this Word document.\n\nYou may need to unlink the Book manually in PlotDirector later.\n\nRemove Word metadata only?");
|
||||
setDocumentMessage("Unable to unlink from PlotDirector.");
|
||||
const removeLocalOnly = window.confirm("PlotDirector could not be updated, but you can still remove the binding from this Word document.\n\nYou may need to unlink the Book manually in PlotDirector later.\n\nRemove binding from this Word document only?");
|
||||
if (removeLocalOnly) {
|
||||
try {
|
||||
await removeDocumentBinding();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user