*/
package gr.grnet.pithos.web.client;
-import gr.grnet.pithos.web.client.foldertree.File;
import gr.grnet.pithos.web.client.foldertree.Folder;
-import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
/**
* The widget's constructor.
*/
- public FileUploadDialog(Pithos _app, Folder _folder) {
+ public FileUploadDialog(Pithos _app) {
app = _app;
- folder = _folder;
- foldernameLabel.setText(folder.getName());
- Anchor close = new Anchor();
+ Anchor close = new Anchor("close");
close.addStyleName("close");
close.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- hide();
+ close();
}
});
// Set the dialog's caption.
setAnimationEnabled(true);
setGlassEnabled(true);
setStyleName("pithos-DialogBox");
+ setVisible(false);
+
// Since we're going to add a FileUpload widget, we'll need to set the
// form to use the POST method, and multipart MIME encoding.
form.setEncoding(FormPanel.ENCODING_MULTIPART);
// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
+ panel.setWidth("470px");
panel.add(close);
form.setWidget(panel);
panel.add(inner);
panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
-
- Scheduler.get().scheduleDeferred(new Command() {
-
- @Override
- public void execute() {
- String path = app.getApiPath() + folder.getOwner() + folder.getUri();
- setupUpload(FileUploadDialog.this, path, app.getToken());
- }
- });
setWidget(form);
}
public void execute() {
app.updateStatistics();
}
- });
+ }, true);
else
app.updateOtherSharedFolder(folder, true);
- hide();
}
native void setupUpload(FileUploadDialog dlg, String path, String token) /*-{
- $wnd.$("#uploader").pluploadQueue({
- // General settings
- runtimes : 'html5, flash, gears, silverlight, browserplus, html4',
- unique_names : true,
-
- // Flash settings
- flash_swf_url : 'plupload/js/plupload.flash.swf',
-
- // Silverlight settings
- silverlight_xap_url : 'plupload/js/plupload.silverlight.xap',
-
- preinit: {
- Init: function(up, info) {
- up.settings.file_data_name = "X-Object-Data";
- }
- },
-
- init: {
- BeforeUpload: function(up, file) {
- $wnd.console.log('About to upload ' + file.name);
- up.settings.url = path + "/" + file.name + "?X-Auth-Token=" + token;
- },
+ var uploader = $wnd.$('#uploader').pluploadQueue();
+ var createUploader = function() {
+ $wnd.$("#uploader").pluploadQueue({
+ // General settings
+ runtimes : 'html5, flash, gears, silverlight, browserplus, html4',
+ unique_names : true,
+
+ // Flash settings
+ flash_swf_url : 'plupload/js/plupload.flash.swf',
+
+ // Silverlight settings
+ silverlight_xap_url : 'plupload/js/plupload.silverlight.xap',
+
+ multiple_queues: true,
- FileUploaded: function(up, file, response) {
- $wnd.console.log('File ' + file.name + ' uploaded');
- $wnd.console.log('Response: ' + response);
+ preinit: {
+ Init: function(up, info) {
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log("Init fired");
+ up.settings.file_data_name = "X-Object-Data";
+ }
+
},
- UploadComplete: function(up, files) {
- $wnd.console.log('All files finished');
- dlg.@gr.grnet.pithos.web.client.FileUploadDialog::refreshFolder()();
+ init: {
+ FilesAdded: function(up, files) {
+ for (var j=0; j<files.length; j++)
+ files[j].url = up.path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
+ },
+
+ BeforeUpload: function(up, file) {
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log('About to upload ' + file.url);
+ up.settings.url = file.url;
+ },
+
+ FileUploaded: function(up, file, response) {
+ if ($wnd.console && $wnd.console.log) {
+ $wnd.console.log('File ' + file.name + ' uploaded');
+ $wnd.console.log('Response: ' + response);
+ }
+ },
+
+ UploadComplete: function(up, files) {
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log('All files finished');
+ dlg.@gr.grnet.pithos.web.client.FileUploadDialog::hideUploadIndicator()();
+ dlg.@gr.grnet.pithos.web.client.FileUploadDialog::refreshFolder()();
+ },
+
+ Error: function(up, error) {
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log("Error occured:" + error);
+ }
+ }
+ });
+ return $wnd.$('#uploader').pluploadQueue();
+ };
+
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log(uploader);
+ if (!uploader) {
+ uploader = createUploader();
+ }
+ else {
+ var removeAll = true;
+ var files = uploader.files;
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log('About to check ' + files.length + ' files');
+ for (var i=0; i<files.length; i++) {
+ var f = files[i];
+ if (f.status != $wnd.plupload.DONE && f.status != $wnd.plupload.FAILED) {
+ removeAll = false;
+ break;
}
}
- });
+ if (removeAll) {
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log('About to remove ' + files.length + ' files');
+ uploader.destroy();
+ uploader = createUploader();
+ if ($wnd.console && $wnd.console.log)
+ $wnd.console.log(uploader);
+ }
+ }
+ uploader.path = path;
+ }-*/;
- // Client side form validation
-// $wnd.$('form').submit(function(e) {
-// var uploader = $wnd.$('#uploader').pluploadQueue();
-//
-// // Files in queue upload them first
-// if (uploader.files.length > 0) {
-// // When all files are uploaded submit form
-// uploader.bind('StateChanged', function() {
-// if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
-// $wnd.$('form')[0].submit();
-// }
-// });
-//
-// uploader.start();
-// } else {
-// alert('You must queue at least one file.');
-// }
-//
-// return false;
-// });
-
- dlg.@gr.grnet.pithos.web.client.FileUploadDialog::center()();
+ native boolean isUploading()/*-{
+ var uploader = $wnd.$("#uploader").pluploadQueue();
+ var files = uploader.files;
+ for (var i=0; i<files.length; i++) {
+ var f = files[i];
+ if (f.status == $wnd.plupload.UPLOADING) {
+ return true;
+ }
+ }
+ return false;
}-*/;
+
+ @Override
+ protected void onPreviewNativeEvent(NativePreviewEvent event) {
+ super.onPreviewNativeEvent(event);
+
+ NativeEvent evt = event.getNativeEvent();
+ if (evt.getType().equals("keydown"))
+ // Use the popup's key preview hooks to close the dialog when
+ // escape is pressed.
+ switch (evt.getKeyCode()) {
+ case KeyCodes.KEY_ESCAPE:
+ close();
+ break;
+ }
+ }
+
+ public void setFolder(Folder folder) {
+ this.folder = folder;
+ foldernameLabel.setText(folder.getName());
+ }
+
+ @Override
+ public void center() {
+ app.hideUploadIndicator();
+ setVisible(true);
+ setModal(true);
+ super.center();
+ String path = app.getApiPath() + folder.getOwner() + folder.getUri();
+ setupUpload(this, path, app.getToken());
+ super.center();
+ }
+
+ private void hideUploadIndicator() {
+ app.hideUploadIndicator();
+ }
+
+ void close() {
+ setVisible(false);
+ setModal(false);
+ if (isUploading())
+ app.showUploadIndicator();
+ }
}