blob: 4b01f3bba2c61019eb7c6a0fecad404f8fa77ec1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
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";
addToUploadQueue(e.dataTransfer.files);
}
function addToUploadQueue(files){
for(i= 0; i<files.length; i++){
file = files[i];
try {
reader = new FileReader();
reader.readAsBinaryString(files[i]);
} 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");
if(filelist.children.length==0){
var entry = document.createElement("tr");
var filenameCol = document.createElement("th");
filenameCol.id="filename-head";
filenameCol.appendChild(document.createTextNode("Name"));
var filesizeCol = document.createElement("th");
filesizeCol.id = "filesize-head";
filesizeCol.appendChild(document.createTextNode("Size"));
var publicCol = document.createElement("th");
publicCol.id="public-head";
var globeIcon = document.createElement("i");
globeIcon.className="fa fa-globe";
globeIcon.title="public";
publicCol.appendChild(globeIcon);
var progressCol = document.createElement("th");
progressCol.id="progress-head";
progressCol.appendChild(document.createTextNode("Progress"));
entry.appendChild(filenameCol);
entry.appendChild(filesizeCol);
entry.appendChild(publicCol);
entry.appendChild(progressCol);
filelist.appendChild(entry);
}
var entry = document.createElement("tr");
var filename = document.createElement("td");
filename.className="filenameCol";
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 = "filesizeCol";
var progressBar = document.createElement("progress");
progressBar.id="progressBar-"+file.name;
progressBar.className="progressBar";
progressBar.style.display="none";
var progressPending = document.createElement("p");
progressPending.id="progressPending-"+file.name;
progressPending.appendChild(document.createTextNode("pending"));
var progressCol = document.createElement("td");
progressCol.className="progressCol";
progressCol.appendChild(progressBar);
progressCol.appendChild(progressPending);
var publicCol = document.createElement("td");
publicCol.className="publicCol";
var public_at = document.createElement("input");
public_at.type = "checkbox";
public_at.id = "public-"+file.name;
public_at.title="public";
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("progressPending-"+vfs_upload_queue[i].name).style.display = "none";
document.getElementById("progressBar-"+vfs_upload_queue[i].name).style.display = "inline";
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;
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.onload=function(){
if (xhr.status==200){
}else if (xhr.status != 0){
alert("upload failed due to "+xhr.status);
}
};
xhr.upload.onprogress= function(e){
if(e.lengthComputable){
document.getElementById("progressBar-"+this.filename).value = Math.floor(e.loaded/e.total*100);
console.log(Math.floor(e.loaded/e.total*100)+"%");
}else{
alert("cant compute progress");
}
};
xhr.open('post', document.URL, true);
xhr.send(data);
}
}
|