urlo upload as js function
This commit is contained in:
@@ -8,15 +8,15 @@ function clear_text(id,defaultValue) {
|
||||
|
||||
|
||||
function index_form_enter(event) {
|
||||
if (event.which || event.keyCode) {
|
||||
if ((event.which == 13) || (event.keyCode == 13)) {
|
||||
index_form_submit();
|
||||
}
|
||||
};
|
||||
if (event.which || event.keyCode) {
|
||||
if ((event.which == 13) || (event.keyCode == 13)) {
|
||||
index_form_submit();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function index_form_submit() {
|
||||
window.location = window.location + "/list/" +
|
||||
window.location = window.location + "/list/" +
|
||||
document.getElementById("index_form_name").value;
|
||||
}
|
||||
|
||||
@@ -39,25 +39,28 @@ function UploadFile(file,file_no,files_total) {
|
||||
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.className = "";
|
||||
o.innerHTML = "Uploading: " + file_counter + pc + "%";
|
||||
if (pc == 100) {
|
||||
o.innerHTML = "Finishing up " + file_counter + "wait ...";
|
||||
}
|
||||
// upload works, hide button
|
||||
document.getElementById("list_upload_button").hidden = true;
|
||||
}, false);
|
||||
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.className = "";
|
||||
o.innerHTML = "Uploading: " + file_counter + pc + "%";
|
||||
if (pc == 100) {
|
||||
o.innerHTML = "Finishing up " + file_counter + "wait ...";
|
||||
}
|
||||
// upload works, hide button
|
||||
document.getElementById("list_upload_button").hidden = true;
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
// file received/failed
|
||||
xhr.onreadystatechange = function(e) {
|
||||
if (xhr.readyState == 4) {
|
||||
o.className = (xhr.status == 200 ? "success" : "failure");
|
||||
xhr.onreadystatechange = function(e) {
|
||||
if (xhr.readyState == 4) {
|
||||
o.className = (xhr.status == 200 ? "success" : "failure");
|
||||
if (xhr.status == 200) {
|
||||
if (file_no + 1 == files_total) {
|
||||
location = location;
|
||||
@@ -66,32 +69,74 @@ function UploadFile(file,file_no,files_total) {
|
||||
o.innerHTML = xhr.response;
|
||||
}
|
||||
uploadTurn += 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// start upload
|
||||
xhr.open("POST", document.getElementById("upload_form").action, true);
|
||||
xhr.setRequestHeader("X-FILENAME", file.name);
|
||||
xhr.open("POST", document.getElementById("upload_form").action, true);
|
||||
xhr.setRequestHeader("X-FILENAME", file.name);
|
||||
var formData = new FormData();
|
||||
formData.append('name', document.getElementById("list_upload_name").value);
|
||||
formData.append('from_gui', 'true');
|
||||
formData.append('file', file);
|
||||
xhr.send(formData);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// file selection
|
||||
function FileSelectHandler(e) {
|
||||
|
||||
// fetch FileList object
|
||||
var files = e.target.files || e.dataTransfer.files;
|
||||
// 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++) {
|
||||
// process all File objects
|
||||
for (var i = 0, f; f = files[i]; i++) {
|
||||
UploadFile(f,i,files.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Variable to stop parallel uploads
|
||||
var uploadTurn = -1;
|
||||
|
||||
function UploadURL() {
|
||||
var URL = document.getElementById("list_url_upload_text").value;
|
||||
var xhr = new XMLHttpRequest();
|
||||
if (xhr.upload) {
|
||||
var o = document.getElementById("progress");
|
||||
xhr.upload.addEventListener(
|
||||
"progress",
|
||||
function(e) {
|
||||
o.className = "";
|
||||
o.innerHTML = "Uploading...";
|
||||
console.log(e);
|
||||
// upload works, hide button
|
||||
document.getElementById("list_url_upload_button").setAttribute("disabled", "disabled");
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
// file received/failed
|
||||
xhr.onreadystatechange = function(e) {
|
||||
if (xhr.readyState == 4) {
|
||||
o.className = (xhr.status == 200 ? "success" : "failure");
|
||||
if (xhr.status == 200) {
|
||||
// refresh page at upload finish
|
||||
location = location;
|
||||
} else {
|
||||
o.innerHTML = xhr.response;
|
||||
document.getElementById("list_url_upload_button").removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// start upload
|
||||
xhr.open("POST", document.getElementById("url_upload_form").action, true);
|
||||
var formData = new FormData();
|
||||
formData.append('name', document.getElementById("list_upload_name").value);
|
||||
formData.append('from_gui', 'true');
|
||||
formData.append('url', URL);
|
||||
xhr.send(formData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user