diff --git a/code/static/js/scripts.js b/code/static/js/scripts.js index 13f9862..cb977c4 100644 --- a/code/static/js/scripts.js +++ b/code/static/js/scripts.js @@ -8,20 +8,32 @@ function index_form_enter(event) { } function index_form_submit() { - window.location = window.location + "/list/" + document.getElementById("index_form_name").value; + window.location = window.location + "/list/" + + document.getElementById("index_form_name").value; } -function UploadFile(file) { - +function UploadFile(file,file_no,files_total) { + if (uploadTurn != file_no) { + // Wait for our turn to upload. check every 0.5s + setTimeout( + function() { + UploadFile(file,file_no,files_total); + }, + 500 + ); + return + } + var file_counter = "(" + (file_no + 1) + "/" + files_total + ") "; var xhr = new XMLHttpRequest(); if (xhr.upload) { var o = document.getElementById("progress"); xhr.upload.addEventListener("progress", function(e) { var pc = parseInt((e.loaded / e.total * 100)); - o.innerHTML = "Uploading: " + pc + "%"; + o.className = ""; + o.innerHTML = "Uploading: " + file_counter + pc + "%"; if (pc == 100) { - o.innerHTML = "Finishing up... wait..."; + o.innerHTML = "Finishing up " + file_counter + "wait ..."; } // upload works, hide button document.getElementById("list_upload_button").hidden = true; @@ -30,12 +42,15 @@ function UploadFile(file) { // file received/failed xhr.onreadystatechange = function(e) { if (xhr.readyState == 4) { - progress.className = (xhr.status == 200 ? "success" : "failure"); + o.className = (xhr.status == 200 ? "success" : "failure"); if (xhr.status == 200) { - location = location; + if (file_no + 1 == files_total) { + location = location; + } } else { o.innerHTML = xhr.response; } + uploadTurn += 1; } }; @@ -55,13 +70,12 @@ function FileSelectHandler(e) { // fetch FileList object var files = e.target.files || e.dataTransfer.files; - + uploadTurn = 0; // process all File objects for (var i = 0, f; f = files[i]; i++) { - UploadFile(f); + UploadFile(f,i,files.length); } - } - - +// Variable to stop parallel uploads +var uploadTurn = -1; diff --git a/code/templates/list.html b/code/templates/list.html index 920ee09..d5e1ef2 100644 --- a/code/templates/list.html +++ b/code/templates/list.html @@ -6,7 +6,8 @@