2019-11-08 11:21:59 +00:00
|
|
|
function SubmitAddJobForm(newJobFormElement, progressModalElement, request) {
|
2019-09-17 08:56:56 +00:00
|
|
|
var formData;
|
|
|
|
var progress;
|
|
|
|
var progressModal;
|
|
|
|
|
|
|
|
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) {
|
2019-11-18 13:23:53 +00:00
|
|
|
if (request.status === 201) {
|
|
|
|
window.location.href = JSON.parse(this.responseText)['redirect_url'];
|
|
|
|
}
|
|
|
|
if (request.status === 400) {
|
|
|
|
console.log(JSON.parse(this.responseText));
|
2019-11-18 14:41:32 +00:00
|
|
|
// TODO print errors under input fields.
|
2019-11-18 13:23:53 +00:00
|
|
|
}
|
|
|
|
if (request.status === 500) {
|
|
|
|
location.reload();
|
|
|
|
}
|
2019-09-16 10:12:42 +00:00
|
|
|
});
|
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%";
|
|
|
|
});
|
2019-09-17 08:56:56 +00:00
|
|
|
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
|
|
|
|
2019-11-08 11:21:59 +00:00
|
|
|
function initAddJobForm(addJobFormElement, progressModalElement) {
|
2019-09-17 12:20:15 +00:00
|
|
|
var request;
|
|
|
|
|
|
|
|
request = new XMLHttpRequest();
|
|
|
|
|
2019-11-08 11:21:59 +00:00
|
|
|
addJobFormElement.addEventListener("submit", function(event) {
|
2019-09-16 10:12:42 +00:00
|
|
|
event.preventDefault();
|
2019-11-08 11:21:59 +00:00
|
|
|
SubmitAddJobForm(addJobFormElement, progressModalElement, request);
|
2019-09-17 12:20:15 +00:00
|
|
|
});
|
|
|
|
progressModalElement.querySelector(".cancel").addEventListener("click", function(event) {
|
|
|
|
request.abort();
|
2019-09-16 10:12:42 +00:00
|
|
|
});
|
|
|
|
}
|