Resolve #630: "Do not allow tab closure during upload"

This commit is contained in:
Ciarán Ainsworth 2019-03-18 10:09:28 +01:00 committed by Eliot Berriot
parent 1486d6301e
commit 77b41fc0b4
3 changed files with 28 additions and 1 deletions

View file

@ -169,14 +169,24 @@ export default {
id: "fileUpload",
handler: this.handleImportEvent
});
window.onbeforeunload = e => this.onBeforeUnload(e);
},
destroyed() {
this.$store.commit("ui/removeWebsocketEventHandler", {
eventName: "import.status_updated",
id: "fileUpload"
});
window.onbeforeunload = null;
},
methods: {
onBeforeUnload(e = {}) {
const returnValue = ('This page is asking you to confirm that you want to leave - data you have entered may not be saved.');
if (!this.hasActiveUploads) return null;
Object.assign(e, {
returnValue,
});
return returnValue;
},
inputFile(newFile, oldFile) {
this.$refs.upload.active = true;
},
@ -294,6 +304,9 @@ export default {
f.statusIndex = statusIndex
return f
}), ['statusIndex', 'name'])
},
hasActiveUploads () {
return this.sortedFiles.filter((f) => { return f.active }).length > 0
}
},
watch: {