nopaque/app/static/js/opaque.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-09-16 10:12:42 +00:00
function sendNewJobFormData(form, progress) {
var XHR = new XMLHttpRequest();
var FD = new FormData(form);
XHR.upload.addEventListener("progress", function(event) {
progress.querySelector(".determinate").style.width = ((event.loaded / event.total) * 100).toString() + "%";
});
XHR.addEventListener("loadend", function(event) {
form.reset();
location.reload();
});
XHR.open("POST", window.location.href);
XHR.send(FD);
}
function initNewJobForm(newJobFormElement) {
newJobFormElement.addEventListener("submit", function(event) {
event.preventDefault();
var toast = M.toast(
{html: `<div class="row">
<div class="col s12">${this.title.value}</div>
<div class="col s12">
<div class="progress">
<div class="determinate" style="width: 0%"></div>
</div>
</div>
</div>`,
displayLength: Infinity}
);
sendNewJobFormData(this, toast.el.querySelector(".progress"));
});
}