Revision 0c26bcb8
b/src/gr/grnet/pithos/web/client/FileUploadDialog.java | ||
---|---|---|
164 | 164 |
}); |
165 | 165 |
else |
166 | 166 |
app.updateOtherSharedFolder(folder, true); |
167 |
hide(); |
|
167 | 168 |
} |
168 | 169 |
|
169 | 170 |
native void setupUpload(FileUploadDialog dlg, String path, String token) /*-{ |
... | ... | |
181 | 182 |
preinit: { |
182 | 183 |
Init: function(up, info) { |
183 | 184 |
up.settings.file_data_name = "X-Object-Data"; |
184 |
}, |
|
185 |
|
|
186 |
UploadFile: function(up, file) { |
|
187 |
$wnd.console.log('About to upload ' + file.name); |
|
188 |
up.settings.url = path + "/" + file.name + "?X-Auth-Token=" + token; |
|
189 | 185 |
} |
190 | 186 |
}, |
191 | 187 |
|
192 | 188 |
init: { |
189 |
BeforeUpload: function(up, file) { |
|
190 |
$wnd.console.log('About to upload ' + file.name); |
|
191 |
up.settings.url = path + "/" + file.name + "?X-Auth-Token=" + token; |
|
192 |
}, |
|
193 |
|
|
193 | 194 |
FileUploaded: function(up, file, response) { |
194 | 195 |
$wnd.console.log('File ' + file.name + ' uploaded'); |
195 | 196 |
$wnd.console.log('Response: ' + response); |
... | ... | |
203 | 204 |
}); |
204 | 205 |
|
205 | 206 |
// Client side form validation |
206 |
$wnd.$('form').submit(function(e) { |
|
207 |
var uploader = $wnd.$('#uploader').pluploadQueue(); |
|
208 |
|
|
209 |
// Files in queue upload them first |
|
210 |
if (uploader.files.length > 0) { |
|
211 |
// When all files are uploaded submit form |
|
212 |
uploader.bind('StateChanged', function() { |
|
213 |
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) { |
|
214 |
$wnd.$('form')[0].submit(); |
|
215 |
} |
|
216 |
}); |
|
217 |
|
|
218 |
uploader.start(); |
|
219 |
} else { |
|
220 |
alert('You must queue at least one file.'); |
|
221 |
} |
|
222 |
|
|
223 |
return false; |
|
224 |
}); |
|
207 |
// $wnd.$('form').submit(function(e) {
|
|
208 |
// var uploader = $wnd.$('#uploader').pluploadQueue();
|
|
209 |
// |
|
210 |
// // Files in queue upload them first
|
|
211 |
// if (uploader.files.length > 0) {
|
|
212 |
// // When all files are uploaded submit form
|
|
213 |
// uploader.bind('StateChanged', function() {
|
|
214 |
// if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
|
|
215 |
// $wnd.$('form')[0].submit();
|
|
216 |
// }
|
|
217 |
// });
|
|
218 |
// |
|
219 |
// uploader.start();
|
|
220 |
// } else {
|
|
221 |
// alert('You must queue at least one file.');
|
|
222 |
// }
|
|
223 |
// |
|
224 |
// return false;
|
|
225 |
// });
|
|
225 | 226 |
|
226 | 227 |
dlg.@gr.grnet.pithos.web.client.FileUploadDialog::center()(); |
227 | 228 |
}-*/; |
228 |
|
|
229 |
/** |
|
230 |
* Make any last minute checks and start the upload. |
|
231 |
*/ |
|
232 |
protected void prepareAndSubmit() { |
|
233 |
if (upload.getFilename().length() == 0) { |
|
234 |
app.displayError("You must select a file!"); |
|
235 |
return; |
|
236 |
} |
|
237 |
final String fname = getFilename(upload.getFilename()); |
|
238 |
String apath = app.getApiPath() + folder.getOwner() + folder.getUri() + "/" + fname + "?X-Auth-Token=" + app.getToken(); |
|
239 |
form.setAction(apath); |
|
240 |
submit.setEnabled(false); |
|
241 |
upload.setVisible(false); |
|
242 |
filenameLabel.setText(fname); |
|
243 |
filenameLabel.setVisible(true); |
|
244 |
|
|
245 |
if (getFileForName(fname) == null) { |
|
246 |
form.submit(); |
|
247 |
} |
|
248 |
else { |
|
249 |
// We are going to update an existing file, so show a confirmation dialog. |
|
250 |
ConfirmationDialog confirm = new ConfirmationDialog("Are you sure " + |
|
251 |
"you want to update " + fname + "?", "Update") { |
|
252 |
|
|
253 |
@Override |
|
254 |
public void cancel() { |
|
255 |
FileUploadDialog.this.hide(); |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public void confirm() { |
|
260 |
form.submit(); |
|
261 |
} |
|
262 |
|
|
263 |
}; |
|
264 |
confirm.center(); |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* Returns the file name from a potential full path argument. Apparently IE |
|
270 |
* insists on sending the full path name of a file when uploading, forcing |
|
271 |
* us to trim the extra path info. Since this is only observed on Windows we |
|
272 |
* get to check for a single path separator value. |
|
273 |
* |
|
274 |
* @param name the potentially full path name of a file |
|
275 |
* @return the file name without extra path information |
|
276 |
*/ |
|
277 |
protected String getFilename(String name) { |
|
278 |
int pathSepIndex = name.lastIndexOf("\\"); |
|
279 |
if (pathSepIndex == -1) { |
|
280 |
pathSepIndex = name.lastIndexOf("/"); |
|
281 |
if (pathSepIndex == -1) |
|
282 |
return name; |
|
283 |
} |
|
284 |
return name.substring(pathSepIndex + 1); |
|
285 |
} |
|
286 |
|
|
287 |
protected File getFileForName(String name){ |
|
288 |
for (File f : folder.getFiles()) |
|
289 |
if (f.getName().equals(name)) |
|
290 |
return f; |
|
291 |
return null; |
|
292 |
} |
|
293 | 229 |
} |
Also available in: Unified diff