Skip to content

Commit

Permalink
Annotations: also show revision panel before exporting document to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangmm committed Mar 15, 2024
1 parent 59289f6 commit 121e512
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
50 changes: 36 additions & 14 deletions resources/scripts/annotations/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ window.addEventListener("WebComponentsReady", () => {
hideForm();
view.popHistory();
});

// ---- START: save and export ----

// save document action
const saveDocBtn = document.getElementById("document-save");
saveDocBtn.addEventListener("click", () => {
Expand All @@ -643,38 +646,57 @@ window.addEventListener("WebComponentsReady", () => {
window.hotkeys(saveDocBtn.dataset.shortcut, () => preview(view.annotations, true));
}

function _saveOrExport(exportFile = false, details) {
if (exportFile) {
const doc = document.getElementById("document1");
getNewFileHandle(doc.getFileName())
.then((fh) => {
if (verifyPermission(fh, true)) {
preview(view.annotations, true, details)
.then((xml) => {
writeFile(fh, xml);
});
} else {
alert('Permission denied to store files locally');
}
});
} else {
preview(view.annotations, true, details);
}
}

document.getElementById('commit').addEventListener('pb-commit', (ev) => {
const exportFile = ev.detail.export === 'true';
if (ev.detail.message !== '') {
preview(view.annotations, true, {
_saveOrExport(exportFile, {
user: ev.detail.user,
message: ev.detail.message,
status: ev.detail.status
});
} else {
preview(view.annotations, true);
_saveOrExport(exportFile);
}
});

// save and download merged TEI to local file
const downloadBtn = document.getElementById('document-download');
if ('showSaveFilePicker' in window) {
downloadBtn.addEventListener('click', () => {
const doc = document.getElementById("document1");
getNewFileHandle(doc.getFileName())
.then((fh) => {
if (verifyPermission(fh, true)) {
preview(view.annotations, true)
.then((xml) => {
writeFile(fh, xml);
});
} else {
alert('Permission denied to store files locally');
}
});
if (trackHistory) {
document.dispatchEvent(new CustomEvent('pb-before-save', {
detail: {
user: currentUser,
export: true
}
}));
} else {
_saveOrExport(true);
}
});
} else {
downloadBtn.style.display = 'none';
}
// ---- END: save and export ----

// mark-all occurrences action
const markAllBtn = document.getElementById("mark-all");
Expand Down
7 changes: 4 additions & 3 deletions templates/pages/annotate.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</data>
</fx-instance>
<fx-instance id="i-commit">
<commit user="" status="feat">
<commit user="" status="feat" export="false">
<message></message>
</commit>
</fx-instance>
Expand All @@ -122,7 +122,7 @@
</fx-function>
</fx-model>

<fx-group ref="commit" id="commit" track-history="">
<fx-group ref="commit[.='true']" id="commit" track-history="">
<section>
<header>Revision Description</header>
<fx-control ref="instance('i-commit')/@user">
Expand All @@ -145,6 +145,7 @@
<fx-dispatch name="pb-commit" targetid="commit">
<fx-property name="message" expr="instance('i-commit')/message/string()"/>
<fx-property name="user" expr="instance('i-commit')/@user"/>
<fx-property name="export" expr="instance('i-commit')/@export"/>
<fx-property name="status" expr="instance('i-commit')/@status"/>
</fx-dispatch>
<fx-setvalue ref="commit">false</fx-setvalue>
Expand Down Expand Up @@ -290,6 +291,7 @@
<fx-action event="pb-before-save" target="#document">
<fx-setvalue ref="commit">true</fx-setvalue>
<fx-setvalue ref="instance('i-commit')/@user" value="event('user')"></fx-setvalue>
<fx-setvalue ref="instance('i-commit')/@export" value="event('export')"></fx-setvalue>
<fx-setvalue ref="instance('i-commit')/message" value="''"></fx-setvalue>
<fx-update></fx-update>
<fx-refresh></fx-refresh>
Expand Down Expand Up @@ -342,7 +344,6 @@
<!-- ### show the annotation form and the authority search -->
<fx-action id="show-annotation" event="show-annotation" target="#document">
<fx-call action="reset-panels"></fx-call>
<fx-message>Revision panel relevant: {commit}</fx-message>
<!-- ### show annotation details panel -->
<fx-setvalue ref="annotation">true</fx-setvalue>
</fx-action>
Expand Down

0 comments on commit 121e512

Please sign in to comment.