Postload JSZip

Close #18
This commit is contained in:
Joshua Ramon Enslin 2022-11-07 01:09:41 +01:00
parent fe791c2000
commit 453a726a9a
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 37 additions and 19 deletions

View File

@ -450,28 +450,48 @@ class CsvxmlPage {
zipUploadToXml(validator) {
let zip = new JSZip();
// Wrap zipping in function to postload it
function runZipping() {
let zip = new JSZip();
let xmlFiles = validator.generateXml();
const serializer = new XMLSerializer();
let lineCounter = 0;
for (let xml of xmlFiles) {
zip.file(lineCounter + ".xml", serializer.serializeToString(xml));
lineCounter++;
}
zip.generateAsync({type:"blob"})
.then(function(content) {
const triggerLink = document.createElement('a');
triggerLink.href = window.URL.createObjectURL(content);
triggerLink.setAttribute('download', "csvxml.zip");
triggerLink.style.display = 'none';
document.body.appendChild(triggerLink);
triggerLink.click();
document.body.removeChild(triggerLink);
});
let xmlFiles = validator.generateXml();
const serializer = new XMLSerializer();
let lineCounter = 0;
for (let xml of xmlFiles) {
zip.file(lineCounter + ".xml", serializer.serializeToString(xml));
lineCounter++;
}
zip.generateAsync({type:"blob"})
.then(function(content) {
const triggerLink = document.createElement('a');
triggerLink.href = window.URL.createObjectURL(content);
triggerLink.setAttribute('download', "csvxml.zip");
if (typeof JSZip === "undefined") {
triggerLink.style.display = 'none';
const loadScript = document.createElement("script");
loadScript.setAttribute("src", "assets/js/jszip/dist/jszip.min.js");
loadScript.addEventListener('load', function() {
// console.log("Post-loaded OpenLayers");
runZipping();
}, {passive: true, once: true});
document.body.appendChild(triggerLink);
triggerLink.click();
document.body.removeChild(triggerLink);
});
document.body.appendChild(loadScript);
}
else {
runZipping();
}
}

View File

@ -40,8 +40,6 @@ echo '
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Validate import CSV files for museum-digital" />
<script src="assets/js/jszip/dist/jszip.min.js" type="text/javascript" async defer></script>
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.css" />
<meta name="theme-color" content="#aa4400" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />