diff options
| author | oweissbarth | 2014-07-19 16:17:49 +0200 |
|---|---|---|
| committer | oweissbarth | 2014-07-19 16:17:49 +0200 |
| commit | 0097ccaf345cbc423df415322357e1f574e19140 (patch) | |
| tree | e0d171cf1d01f457741b48bc291f05f76a07961b /www/static/js | |
| parent | 7f757321be39166ff259225c03a6793101cd921e (diff) | |
| download | files.iamfabulous.de-0097ccaf345cbc423df415322357e1f574e19140.tar.gz | |
added d&d multifile upload
Diffstat (limited to 'www/static/js')
| -rw-r--r-- | www/static/js/browser.js | 15 | ||||
| -rw-r--r-- | www/static/js/dropzone.js | 91 |
2 files changed, 105 insertions, 1 deletions
diff --git a/www/static/js/browser.js b/www/static/js/browser.js index a0e9824..b32154b 100644 --- a/www/static/js/browser.js +++ b/www/static/js/browser.js @@ -1,20 +1,33 @@ function showNewFolder(){ document.getElementById("new-folder-bg").style.visibility = "visible"; - + document.getElementById("new-folder-area").style.visibility = "visible"; return; } function hideNewFolder(){ document.getElementById("new-folder-bg").style.visibility = "hidden"; + document.getElementById("new-folder-area").style.visibility = "hidden"; return; } function showUpload(){ document.getElementById("upload-bg").style.visibility = "visible"; + document.getElementById("upload-area").style.visibility = "visible"; return; } function hideUpload(){ document.getElementById("upload-bg").style.visibility = "hidden"; + document.getElementById("upload-area").style.visibility = "hidden"; + + //clean up + vfs_upload_queue = []; + var list = document.getElementById("filelist"); + while(list.firstChild){ + list.removeChild(list.firstChild); + } + + location.reload(false); + return; } diff --git a/www/static/js/dropzone.js b/www/static/js/dropzone.js new file mode 100644 index 0000000..bfc5c1a --- /dev/null +++ b/www/static/js/dropzone.js @@ -0,0 +1,91 @@ +var vfs_upload_queue = []; + function dragover(e){ + e.preventDefault(); + var dropzone = document.getElementById("dropzone"); + dropzone.style.backgroundColor = "#E6E6FF"; + } + + function dragout(e){ + var dropzone = document.getElementById("dropzone"); + dropzone.style.backgroundColor = "white"; + } + + function drop(e){ + e.preventDefault(); + var dropzone = document.getElementById("dropzone"); + dropzone.style.backgroundColor = "white"; + for(file of e.dataTransfer.files){ + try { + reader = new FileReader(); + reader.readAsBinaryString(file); + } catch (NS_ERROR_FILE_ACCESS_DENIED) { + //file is a directory. Dropping of directories is only implemented in chrome > v21. + alert("file is a directory. Dropping of directories is only implemented in chrome > v21."); + break; + + } + var filelist = document.getElementById("filelist"); + var entry = document.createElement("tr"); + + var filename = document.createElement("td"); + filename.appendChild(document.createTextNode(file.name)); + + var filesize = document.createElement("td"); + filesize.appendChild(document.createTextNode(Math.floor(file.size/1024*100)/100+"KB")); + filesize.className = "filesize"; + + var progressBar = document.createElement("progress"); + progressBar.id="progressBar-"+file.name; + progressBar.className="progressBar"; + var progressCol = document.createElement("td"); + progressCol.className="progressCol"; + progressCol.appendChild(progressBar); + + var publicCol = document.createElement("td"); + var public_at = document.createElement("input"); + public_at.type = "checkbox"; + public_at.id = "public-"+file.name; + publicCol.appendChild(public_at); + + entry.appendChild(filename); + entry.appendChild(filesize); + entry.appendChild(publicCol); + entry.appendChild(progressCol); + + filelist.appendChild(entry); + vfs_upload_queue.push(file); + } + } + + function upload(){ + for(i = 0; i<vfs_upload_queue.length; i++){ + document.getElementById("progressBar-"+vfs_upload_queue[i].name).value = 0; + document.getElementById("progressBar-"+vfs_upload_queue[i].name).max = 100; + var xhr = new XMLHttpRequest(); + + xhr.upload.filename = vfs_upload_queue[i].name; + + xhr.open('post', document.URL, true); + var data = new FormData(); + + data.append("userfile", vfs_upload_queue[i]); + data.append("task", "upload"); + if(document.getElementById("public-"+ vfs_upload_queue[i].name).checked){ + data.append("share", "PUBLIC"); + } + + data.append("path", folder); + + xhr.onreadystatechange=function(){ + if (xhr.readyState==4 && xhr.status==200){ + document.getElementById("upload-message").innerHTML = xhr.responseText; + } + }; + + xhr.upload.addEventListener("progress", function(e){ + + document.getElementById("progressBar-"+this.filename).value = Math.ceil(e.loaded/e.total)*100; + }); + xhr.send(data); + } + } |
