Add function to cancel file upload.

This commit is contained in:
Patrick Jentsch 2019-09-17 14:20:15 +02:00
parent 07c4e31510
commit 683b59bb47
3 changed files with 14 additions and 6 deletions

View File

@ -1,4 +1,4 @@
function sendNewJobFormData(newJobFormElement, progressModalElement) {
function sendNewJobFormData(newJobFormElement, progressModalElement, request) {
var formData;
var progress;
var progressModal;
@ -6,7 +6,6 @@ function sendNewJobFormData(newJobFormElement, progressModalElement) {
formData = new FormData(newJobFormElement);
progressModal = M.Modal.getInstance(progressModalElement);
request = new XMLHttpRequest();
progressModal.options.dismissible = false;
progressModalElement.querySelector(".title").innerHTML = newJobFormElement.title.value;
@ -15,7 +14,7 @@ function sendNewJobFormData(newJobFormElement, progressModalElement) {
progressModalElement.querySelector(".total").innerHTML = event.total.toString();
progressModalElement.querySelector(".determinate").style.width = ((event.loaded / event.total) * 100).toString() + "%";
});
request.addEventListener("loadend", function(event) {
request.addEventListener("load", function(event) {
newJobFormElement.reset();
location.reload();
});
@ -24,9 +23,18 @@ function sendNewJobFormData(newJobFormElement, progressModalElement) {
request.open("POST", window.location.href);
request.send(formData);
}
function initNewJobForm(newJobFormElement, progressModalElement) {
var request;
request = new XMLHttpRequest();
newJobFormElement.addEventListener("submit", function(event) {
event.preventDefault();
sendNewJobFormData(newJobFormElement, progressModalElement);
sendNewJobFormData(newJobFormElement, progressModalElement, request);
});
progressModalElement.querySelector(".cancel").addEventListener("click", function(event) {
request.abort();
});
}

View File

@ -131,7 +131,7 @@
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat disabled">Cancel</a>
<a href="#!" class="modal-close waves-effect waves-green btn red cancel">Cancel</a>
</div>
</div>

View File

@ -148,7 +148,7 @@
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat disabled">Cancel</a>
<a href="#!" class="modal-close waves-effect waves-green btn red cancel">Cancel</a>
</div>
</div>