Revision 2f807846 src/gr/grnet/pithos/web/client/FileUploadDialog.java

b/src/gr/grnet/pithos/web/client/FileUploadDialog.java
39 39

  
40 40
import com.google.gwt.core.client.GWT;
41 41
import com.google.gwt.core.client.Scheduler;
42
import com.google.gwt.dom.client.DivElement;
42 43
import com.google.gwt.dom.client.NativeEvent;
43 44
import com.google.gwt.event.dom.client.ClickEvent;
44 45
import com.google.gwt.event.dom.client.ClickHandler;
45 46
import com.google.gwt.event.dom.client.KeyCodes;
46 47
import com.google.gwt.user.client.Command;
47 48
import com.google.gwt.user.client.Cookies;
49
import com.google.gwt.user.client.DOM;
48 50
import com.google.gwt.user.client.Event.NativePreviewEvent;
49 51
import com.google.gwt.user.client.Window;
50 52
import com.google.gwt.user.client.ui.Button;
......
57 59
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
58 60
import com.google.gwt.user.client.ui.Anchor;
59 61
import com.google.gwt.user.client.ui.Grid;
62
import com.google.gwt.user.client.ui.HTML;
60 63
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
61 64
import com.google.gwt.user.client.ui.Hidden;
62 65
import com.google.gwt.user.client.ui.HorizontalPanel;
......
107 110
		setStyleName("pithos-DialogBox");
108 111
		// Since we're going to add a FileUpload widget, we'll need to set the
109 112
		// form to use the POST method, and multipart MIME encoding.
113
		form.getElement().setId("fileupload");
110 114
		form.setEncoding(FormPanel.ENCODING_MULTIPART);
111 115
		form.setMethod(FormPanel.METHOD_POST);
112

  
113 116
		// Create a panel to hold all of the form widgets.
114 117
		VerticalPanel panel = new VerticalPanel();
115 118
		panel.add(close);
......
141 144
		generalTable.setCellSpacing(4);
142 145

  
143 146
		inner.add(generalTable);
147
		
148
		HTML html = new HTML("<div class='row'><div class='span16'><table class='zebra-striped'><tbody class='files'></tbody></table></div></div>");
149
		inner.add(html);
144 150

  
145 151
		// Create the 'upload' button, along with a listener that submits the
146 152
		// form.
......
167 173

  
168 174
			@Override
169 175
			public void onSubmit(@SuppressWarnings("unused") SubmitEvent event) {
170
                auth.setValue(app.getToken()); //This is done here because the app object is not available in the constructor
171
                Cookies.setCookie("X-Auth-Token", app.getToken(), null, "", "/", false);
176
//                auth.setValue(app.getToken()); //This is done here because the app object is not available in the constructor
177
//                Cookies.setCookie("X-Auth-Token", app.getToken(), null, "", "/", false);
172 178
			}
173 179
		});
174 180
		form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
......
209 215
	
210 216
	static native void setupUpload(String path, String token) /*-{
211 217
		//This is to prevent the default browser action for dropped files
212
		$wnd.$(document).bind('drop dragover', function (e) {
213
		    e.preventDefault();
214
		});
218
//		$wnd.$(document).bind('drop dragover', function (e) {
219
//		    e.preventDefault();
220
//		});
215 221
		
216
		$wnd.$('#fileupload').fileupload({
217
        	url: '', //The uri to POST to
218
        	type: 'POST', //DEFAULT
219
        	dataType: '', //Nothing is expected from the server
220
        	dropZone: $wnd.$(document), //DEFAULT
221
        	sequentialUploads: true, //false is the default
222
        	send: function (e, data) {
223
    			$wnd.console.log('send:' + data);
224
//    			$wnd.$('#fileupload').fileupload('option', 'url', path + '/' + input.val() + '?X-Auth-Token=' + token);
225
    			return true;
226
			},
227
        	done: function (e, data) {
228
        		$wnd.console.log(data.textStatus + ' ' + data.url);
229
            	$wnd.$.each(data.result, function (index, file) {
230
                	$wnd.$('<p/>').text(file.name).appendTo(document.body);
231
            	});
232
        	}
233
    	});
222
//		$wnd.$('#fileupload').fileupload({
223
//        	url: '', //The uri to POST to
224
//        	type: 'POST', //DEFAULT
225
//        	dataType: '', //Nothing is expected from the server
226
//        	dropZone: $wnd.$(document), //DEFAULT
227
//        	sequentialUploads: true, //false is the default
228
//        	send: function (e, data) {
229
//    			$wnd.console.log('send:' + data.files[0].fileName);
230
//    			return true;
231
//			},
232
//			submit: function (e, data) {
233
//    			$wnd.console.log('submit:' + data.files[0].fileName);
234
//    			$wnd.$('#fileupload').fileupload('option', 'url', path + '/' + data.files[0].fileName + '?X-Auth-Token=' + token);
235
//    			return true;
236
//			},
237
//        	done: function (e, data) {
238
//        		$wnd.console.log(data.textStatus + ' ' + data.url);
239
////            	$wnd.$.each(data.result, function (index, file) {
240
////                	$wnd.$('<p/>').text(file.name).appendTo(document.body);
241
////            	});
242
//        	}
243
//    	});
244

  
245
    'use strict';
246

  
247
    // Initialize the jQuery File Upload widget:
248
    $wnd.$('#fileupload').fileupload();
249

  
250
	$wnd.$('#fileupload').fileupload('option', 'url', '');
251
	$wnd.$('#fileupload').fileupload('option', 'dataType', '');
252
	$wnd.$('#fileupload').fileupload('option', 'submit', function (e, data) {
253
		$wnd.console.log('submit:' + data.files[0].fileName);
254
		$wnd.$('#fileupload').fileupload('option', 'url', path + '/' + data.files[0].fileName + '?X-Auth-Token=' + token);
255
		return true;
256
	});
257
	
258
    // Load existing files:
259
    $wnd.$.getJSON($wnd.$('#fileupload').prop('action'), function (files) {
260
        var fu = $wnd.$('#fileupload').data('fileupload'),
261
            template;
262
        fu._adjustMaxNumberOfFiles(-files.length);
263
        template = fu._renderDownload(files)
264
            .appendTo($wnd.$('#fileupload .files'));
265
        // Force reflow:
266
        fu._reflow = fu._transition && template.length &&
267
            template[0].offsetWidth;
268
        template.addClass('in');
269
    });
270

  
271
    // Enable iframe cross-domain access via redirect page:
272
    var redirectPage = window.location.href.replace(
273
        /\/[^\/]*$/,
274
        '/cors/result.html?%s'
275
    );
276
    $wnd.$('#fileupload').bind('fileuploadsend', function (e, data) {
277
        if (data.dataType.substr(0, 6) === 'iframe') {
278
            var target = $wnd.$('<a/>').prop('href', data.url)[0];
279
            if (window.location.host !== target.host) {
280
                data.formData.push({
281
                    name: 'redirect',
282
                    value: redirectPage
283
                });
284
            }
285
        }
286
    });
287

  
288
    // Open download dialogs via iframes,
289
    // to prevent aborting current uploads:
290
    $wnd.$('#fileupload .files').delegate(
291
        'a:not([rel^=gallery])',
292
        'click',
293
        function (e) {
294
            e.preventDefault();
295
            $wnd.$('<iframe style="display:none;"></iframe>')
296
                .prop('src', this.href)
297
                .appendTo(document.body);
298
        }
299
    );
300

  
301
    // Initialize the Bootstrap Image Gallery plugin:
302
    $wnd.$('#fileupload .files').imagegallery();
303

  
234 304
	}-*/;
235 305

  
236 306
	@Override

Also available in: Unified diff