mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Improvements for the upload box
This commit is contained in:
@@ -50,9 +50,6 @@
|
||||
// xml request element
|
||||
var xhr = null;
|
||||
|
||||
// file reader
|
||||
var reader = null;
|
||||
|
||||
// attach to element
|
||||
$.fn.uploadbox = function(options)
|
||||
{
|
||||
@@ -163,7 +160,7 @@
|
||||
function process()
|
||||
{
|
||||
// log
|
||||
console.log("Processing queue..." + queue_length + " (" + queue_running + " / " + queue_pause + ")");
|
||||
//console.log("Processing queue..." + queue_length + " (" + queue_running + " / " + queue_pause + ")");
|
||||
|
||||
// validate
|
||||
if (queue_length == 0 || queue_pause)
|
||||
@@ -176,7 +173,7 @@
|
||||
queue_running = true;
|
||||
|
||||
// log
|
||||
console.log("Looking for file...");
|
||||
//console.log("Looking for file...");
|
||||
|
||||
// get an identifier from the queue
|
||||
var index = -1;
|
||||
@@ -193,60 +190,21 @@
|
||||
remove(index)
|
||||
|
||||
// log
|
||||
console.log("Initializing ('" + file.name + "').");
|
||||
//console.log("Initializing ('" + file.name + "').");
|
||||
|
||||
// start
|
||||
var data = opts.initialize(index, file);
|
||||
// identify maximum file size
|
||||
var filesize = file.size;
|
||||
var maxfilesize = 1048576 * opts.maxfilesize;
|
||||
|
||||
// add file to queue
|
||||
try
|
||||
// check file size
|
||||
if (filesize < maxfilesize)
|
||||
{
|
||||
// load file read
|
||||
reader = new FileReader();
|
||||
|
||||
// identify maximum file size
|
||||
var filesize = file.size;
|
||||
var maxfilesize = 1048576 * opts.maxfilesize;
|
||||
|
||||
// set index
|
||||
reader.index = index;
|
||||
if (filesize < maxfilesize)
|
||||
{
|
||||
// link load
|
||||
reader.onload = function(e)
|
||||
{
|
||||
// file read succesfully
|
||||
console.log("Preparing submission ('" + file.name + "').");
|
||||
|
||||
// sending file
|
||||
send(index, file, data)
|
||||
};
|
||||
|
||||
// link error
|
||||
reader.onerror = function(e)
|
||||
{
|
||||
error(index, file, opts.error_default);
|
||||
};
|
||||
|
||||
// link abort
|
||||
reader.onabort = function(e)
|
||||
{
|
||||
error(index, file, opts.error_default);
|
||||
};
|
||||
|
||||
// reading file
|
||||
console.log("Reading ('" + file.name + "').");
|
||||
|
||||
// read data
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
// skip file
|
||||
error(index, file, opts.error_filesize);
|
||||
}
|
||||
} catch (err)
|
||||
{
|
||||
// parse error
|
||||
error(index, file, err);
|
||||
// send data
|
||||
var data = opts.initialize(index, file);
|
||||
send(index, file, data)
|
||||
} else {
|
||||
// skip file
|
||||
error(index, file, opts.error_filesize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +228,7 @@
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
// status change
|
||||
console.log("Status changed: " + xhr.readyState + ".");
|
||||
//console.log("Status changed: " + xhr.readyState + ".");
|
||||
|
||||
// check for request completed, server connection closed
|
||||
if (xhr.readyState != xhr.DONE)
|
||||
@@ -291,20 +249,14 @@
|
||||
// pass any error to the error option
|
||||
if (xhr.status < 200 || xhr.status > 299)
|
||||
{
|
||||
// format error
|
||||
var text = xhr.statusText;
|
||||
|
||||
// format status
|
||||
var text = xhr.statusText;
|
||||
if (xhr.status == 403)
|
||||
text = opts.error_login;
|
||||
|
||||
// text
|
||||
if (!text) {
|
||||
if (xhr.status == 0)
|
||||
text = opts.error_server;
|
||||
else
|
||||
text = opts.error_default;
|
||||
}
|
||||
else if (xhr.status == 0)
|
||||
text = opts.error_server;
|
||||
else if (!text)
|
||||
text = opts.error_default;
|
||||
|
||||
// request error
|
||||
error(index, file, text + " (" + xhr.status + ")");
|
||||
@@ -322,7 +274,7 @@
|
||||
xhr.send(formData);
|
||||
|
||||
// sending file
|
||||
console.log("Sending file ('" + file.name + "').");
|
||||
//console.log("Sending file ('" + file.name + "').");
|
||||
}
|
||||
|
||||
// success
|
||||
@@ -392,7 +344,7 @@
|
||||
// verify browser compatibility
|
||||
function compatible()
|
||||
{
|
||||
return window.File && window.FileReader && window.FormData && window.XMLHttpRequest && window.FileList;
|
||||
return window.File && window.FormData && window.XMLHttpRequest && window.FileList;
|
||||
}
|
||||
|
||||
// export functions
|
||||
|
||||
Reference in New Issue
Block a user