nopaque/app/static/js/opaque.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-17 12:20:15 +00:00
function sendNewJobFormData(newJobFormElement, progressModalElement, request) {
var formData;
var progress;
var progressModal;
var request;
formData = new FormData(newJobFormElement);
progressModal = M.Modal.getInstance(progressModalElement);
progressModal.options.dismissible = false;
progressModalElement.querySelector(".title").innerHTML = newJobFormElement.title.value;
request.upload.addEventListener("progress", function(event) {
2019-09-17 14:15:37 +00:00
progressInPercent = Math.floor(100 * event.loaded / event.total).toString() + "%";
progressModalElement.querySelector(".progress-in-percent").innerHTML = progressInPercent;
progressModalElement.querySelector(".determinate").style.width = progressInPercent;
2019-09-16 10:12:42 +00:00
});
2019-09-17 12:20:15 +00:00
request.addEventListener("load", function(event) {
newJobFormElement.reset();
2019-09-16 10:12:42 +00:00
location.reload();
});
2019-09-17 14:15:37 +00:00
request.addEventListener("abort", function(event) {
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
progressModalElement.querySelector(".determinate").style.width = "0%";
});
progressModal.open();
request.open("POST", window.location.href);
request.send(formData);
2019-09-16 10:12:42 +00:00
}
2019-09-17 12:20:15 +00:00
function initNewJobForm(newJobFormElement, progressModalElement) {
2019-09-17 12:20:15 +00:00
var request;
request = new XMLHttpRequest();
2019-09-16 10:12:42 +00:00
newJobFormElement.addEventListener("submit", function(event) {
event.preventDefault();
2019-09-17 12:20:15 +00:00
sendNewJobFormData(newJobFormElement, progressModalElement, request);
});
progressModalElement.querySelector(".cancel").addEventListener("click", function(event) {
request.abort();
2019-09-16 10:12:42 +00:00
});
}