user feedback logic was updated to report if zero posts were found in a zip and form submissions disable the submit button until the form input for files changes again, preventing possible duplicate submissions on large zip uploads. updated to v0.2.1 wfimport to prevent early error returns when an invalid file is present in a zip.
55 lines
No EOL
1.5 KiB
JavaScript
55 lines
No EOL
1.5 KiB
JavaScript
const fileForm = document.querySelector('form.import-form');
|
|
const selectElem = document.querySelector('select[name="collection"]');
|
|
const submitElem = document.querySelector('input[type="submit"]');
|
|
const zipInfo = document.querySelector('span.zip > ul.info');
|
|
const zipWarning = document.querySelector('span.zip > p.error');
|
|
const fileInput = document.querySelector('input[type="file"]')
|
|
|
|
document.onreadystatechange = () => {
|
|
if ( document.readyState === "complete") {
|
|
selectElem.disabled = true;
|
|
submitElem.disabled = true;
|
|
zipInfo.hidden = true;
|
|
zipWarning.hidden = true;
|
|
}
|
|
}
|
|
|
|
fileInput.onchange = function() {
|
|
if ( this.files.length === 1 ) {
|
|
if ( this.files[0].type === 'application/zip' ) {
|
|
selectElem.disabled = true;
|
|
submitElem.disabled = false;
|
|
zipInfo.hidden = false;
|
|
zipWarning.hidden = true;
|
|
} else {
|
|
selectElem.disabled = false;
|
|
submitElem.disabled = false;
|
|
zipInfo.hidden = true;
|
|
zipWarning.hidden = true;
|
|
}
|
|
}
|
|
|
|
if ( this.files.length > 1 ) {
|
|
selectElem.disabled = false;
|
|
submitElem.disabled = false;
|
|
var zips = 0;
|
|
Array.from(this.files).forEach(file => {
|
|
if ( file.name.endsWith(".zip") ) {
|
|
zips++;
|
|
}
|
|
})
|
|
if ( zips > 0 ) {
|
|
zipInfo.hidden = true;
|
|
zipWarning.hidden = false;
|
|
} else {
|
|
zipInfo.hidden = true;
|
|
zipWarning.hidden = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
submitElem.addEventListener("click", (e) => {
|
|
e.preventDefault();
|
|
submitElem.disabled = true;
|
|
fileForm.submit();
|
|
}); |