X-Git-Url: https://git.p6c8.net/jirafeau.git/blobdiff_plain/045f02b53953998c9cb0cff34f7f62664bdd66cd..aaf7f366cebffa2963241d09d3f899e041ba51d7:/lib/functions.js diff --git a/lib/functions.js b/lib/functions.js index ccd13d3..f25ee6f 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -125,25 +125,52 @@ function upload_progress (e) show_upload_progression (p.toString() + '%'); } -function upload_failed (e) +function control_selected_file_size(max_size, error_str) { - /* Todo: Considere showing a error div. */ - alert ('Sorry, upload failed'); + f_size = document.getElementById('file_select').files[0].size; + if (max_size > 0 && f_size > max_size * 1024 * 1024) + { + pop_failure(error_str); + document.getElementById('send').style.display = 'none'; + } + else + { + document.getElementById('options').style.display = ''; + document.getElementById('send').style.display = ''; + document.getElementById('error_pop').style.display = 'none'; + } +} + +function pop_failure (e) +{ + var text = "An error occured"; + if (typeof e !== 'undefined') + text = e; + text = "
" + text + "
"; + document.getElementById('error_pop').innerHTML = e; + + document.getElementById('uploading').style.display = 'none'; + document.getElementById('error_pop').style.display = ''; + document.getElementById('upload').style.display = ''; + document.getElementById('send').style.display = ''; } function classic_upload (url, file, time, password, one_time, upload_password) { var req = new XMLHttpRequest (); req.upload.addEventListener ("progress", upload_progress, false); - req.addEventListener ("error", upload_failed, false); - req.addEventListener ("abort", upload_failed, false); + req.addEventListener ("error", pop_failure, false); + req.addEventListener ("abort", pop_failure, false); req.onreadystatechange = function () { if (req.readyState == 4 && req.status == 200) { var res = req.responseText; if (res == "Error") + { + pop_failure (); return; + } res = res.split ("\n"); if (time != 'none') { @@ -158,6 +185,8 @@ function classic_upload (url, file, time, password, one_time, upload_password) d.setSeconds (d.getSeconds() + 604800); else if (time == 'month') d.setSeconds (d.getSeconds() + 2419200); + else if (time == 'year') + d.setSeconds (d.getSeconds() + 29030400); else return; show_link (url, res[0], res[1], res[2], d.toString()); @@ -206,15 +235,18 @@ function async_upload_start (url, max_size, file, time, password, one_time, uplo async_global_time = time; var req = new XMLHttpRequest (); - req.addEventListener ("error", upload_failed, false); - req.addEventListener ("abort", upload_failed, false); + req.addEventListener ("error", pop_failure, false); + req.addEventListener ("abort", pop_failure, false); req.onreadystatechange = function () { if (req.readyState == 4 && req.status == 200) { var res = req.responseText; if (res == "Error") + { + pop_failure (); return; + } res = res.split ("\n"); async_global_ref = res[0]; var code = res[1]; @@ -258,15 +290,18 @@ function async_upload_push (code) } var req = new XMLHttpRequest (); req.upload.addEventListener ("progress", async_upload_progress, false); - req.addEventListener ("error", upload_failed, false); - req.addEventListener ("abort", upload_failed, false); + req.addEventListener ("error", pop_failure, false); + req.addEventListener ("abort", pop_failure, false); req.onreadystatechange = function () { if (req.readyState == 4 && req.status == 200) { var res = req.responseText; if (res == "Error") + { + pop_failure (); return; + } res = res.split ("\n"); var code = res[0] async_global_transfered = async_global_transfering; @@ -293,15 +328,18 @@ function async_upload_push (code) function async_upload_end (code) { var req = new XMLHttpRequest (); - req.addEventListener ("error", upload_failed, false); - req.addEventListener ("abort", upload_failed, false); + req.addEventListener ("error", pop_failure, false); + req.addEventListener ("abort", pop_failure, false); req.onreadystatechange = function () { if (req.readyState == 4 && req.status == 200) { var res = req.responseText; if (res == "Error") + { + pop_failure (); return; + } res = res.split ("\n"); if (async_global_time != 'none') { @@ -316,6 +354,8 @@ function async_upload_end (code) d.setSeconds (d.getSeconds() + 604800); else if (async_global_time == 'month') d.setSeconds (d.getSeconds() + 2419200); + else if (async_global_time == 'year') + d.setSeconds (d.getSeconds() + 29030400); else return; show_link (async_global_url, res[0], res[1], res[2], d.toString());