Revision 1238d28d

b/src/gr/grnet/pithos/web/client/Pithos.java
92 92
import com.google.gwt.user.client.ui.AbstractImagePrototype;
93 93
import com.google.gwt.user.client.ui.Button;
94 94
import com.google.gwt.user.client.ui.Composite;
95
import com.google.gwt.user.client.ui.FlowPanel;
95 96
import com.google.gwt.user.client.ui.HTML;
96 97
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
97 98
import com.google.gwt.user.client.ui.HasVerticalAlignment;
......
249 250

  
250 251
    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
251 252
    
252
    Button upload;
253
    public Button upload;
253 254
    
254 255
    private HTML numOfFiles;
255 256
    
......
359 360
        fileList = new FileList(this, images);
360 361
        inner.add(fileList);
361 362

  
363
        inner.add(createUploadArea());
364
        
362 365
        trees = new VerticalPanel();
363 366
        trees.setWidth("100%");
364 367
        
......
460 463

  
461 464
    public void applyPermissions(Folder f) {
462 465
    	if (f != null) {
463
    		if (f.isInTrash())
466
    		if (f.isInTrash()) {
464 467
    			upload.setEnabled(false);
468
    			hideUploadArea();
469
    		}
465 470
    		else {
466 471
		    	Boolean[] perms = f.getPermissions().get(username);
467 472
		    	if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
468 473
		    		upload.setEnabled(true);
474
		    		showUploadArea();
469 475
		    	}
470
		    	else
476
		    	else {
471 477
		    		upload.setEnabled(false);
478
		    		hideUploadArea();
479
		    	}
472 480
    		}
473 481
    	}
474
    	else
482
    	else {
475 483
    		upload.setEnabled(false);
484
    		hideUploadArea();
485
    	}
476 486
	}
477 487

  
478 488
	@SuppressWarnings({ "rawtypes", "unchecked" })
......
1087 1097
		        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
1088 1098
		            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
1089 1099
		            upload.setEnabled(false);
1100
		            hideUploadArea();
1090 1101
		            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
1091 1102
					showRelevantToolbarButtons();
1092 1103
		        }
......
1276 1287
	public boolean isMySharedSelected() {
1277 1288
		return getSelectedTree().equals(getMySharedTreeView());
1278 1289
	}
1290
	
1291
	private FlowPanel createUploadArea() {
1292
		FlowPanel area = new FlowPanel();
1293
		area.getElement().setId("container");
1294
		HTML list = new HTML();
1295
		list.getElement().setId("filelist");
1296
		area.add(list);
1297
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {
1298
			
1299
			@Override
1300
			public void execute() {
1301
				setupUploadArea(Pithos.this, getToken());
1302
			}
1303
		});
1304
		
1305
		return area;
1306
	}
1307
	
1308
	native void setupUploadArea(Pithos app, String token) /*-{
1309
		$wnd.$("#container").pluploadQueue({
1310
			// General settings
1311
			runtimes : 'html5',
1312
			unique_names : true,
1313
			multiple_queues: true,
1314
			drop_element: 'filelist',
1315
			
1316
			preinit: {
1317
				Init: function(up, info) {
1318
					if ($wnd.console && $wnd.console.log)
1319
						$wnd.console.log("Init fired");
1320
					up.settings.file_data_name = "X-Object-Data";				
1321
				}
1322
			},
1323
			
1324
			init: {
1325
				FilesAdded: function(up, files) {
1326
					$wnd.$('#container').css('border', '');
1327
					var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
1328
					var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
1329
					var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwner()();
1330
					var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
1331
					var path = api + owner + uri;
1332
					for (var j=0; j<files.length; j++) {
1333
						files[j].folder = folder;
1334
						files[j].url = path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
1335
					}
1336
					up.start();
1337
				},
1338
				
1339
				BeforeUpload: function(up, file) {
1340
					if ($wnd.console && $wnd.console.log)
1341
						$wnd.console.log('About to upload ' + file.url);
1342
					up.settings.url = file.url;
1343
				},
1344
				
1345
				FileUploaded: function(up, file, response) {
1346
					if ($wnd.console && $wnd.console.log) {
1347
						$wnd.console.log('File ' + file.name + ' uploaded');
1348
						$wnd.console.log('Response: ' + response);
1349
					}
1350
					up.removeFile(file);
1351
					var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
1352
					if (folder == file.folder)
1353
						app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder()();
1354
				},
1355
				
1356
				UploadComplete: function(up, files) {
1357
					if ($wnd.console && $wnd.console.log)
1358
						$wnd.console.log('All files finished');
1359
				},
1360
				
1361
				Error: function(up, error) {
1362
					if ($wnd.console && $wnd.console.log)
1363
						$wnd.console.log("Error occured:" + error);
1364
				}
1365
			}
1366
		});
1367
		var uploader = $wnd.$("#container").pluploadQueue();
1368
		if (uploader.runtime != 'html5')
1369
			$wnd.$("#container").hide();
1370
		else {
1371
			if ($wnd.console && $wnd.console.log) {
1372
				$wnd.console.log(uploader);
1373
				$wnd.console.log($wnd.plupload);
1374
			}
1375
			$wnd.$('.plupload_header').hide();
1376
			$wnd.$('.plupload_filelist_header').hide();
1377
			$wnd.$('#container_filelist').css('overflow-y', 'auto');
1378
			$wnd.$('.plupload_filelist_footer').hide();
1379
			$wnd.document.getElementById('container').addEventListener('dragenter', function(event) {
1380
				$wnd.$('#container').css('border', '3px inset');
1381
			}, false);
1382
			$wnd.document.getElementById('container').addEventListener('dragleave', function(event) {
1383
				$wnd.$('#container').css('border', '');
1384
			}, false);
1385
		}
1386
	}-*/;
1387
	
1388
	private Folder getUploadFolder() {
1389
		if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
1390
			return getSelection();
1391
		}
1392
		return null;
1393
	}
1394
	
1395
	private void updateUploadFolder() {
1396
		if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
1397
			Folder f = getSelection();
1398
			if (getSelectedTree().equals(getFolderTreeView()))
1399
				updateFolder(f, true, new Command() {
1400
				
1401
					@Override
1402
					public void execute() {
1403
						updateStatistics();
1404
					}
1405
				}, false);
1406
			else
1407
				updateOtherSharedFolder(f, true);
1408
		}
1409
	}
1410

  
1411
	public native void hideUploadArea() /*-{
1412
		$wnd.$("#container").hide();
1413
	}-*/;
1414

  
1415
	public native void showUploadArea() /*-{
1416
		$wnd.$("#container").show();
1417
	}-*/;
1279 1418
}
b/src/gr/grnet/pithos/web/client/grouptree/GroupTreeViewModel.java
122 122
				if (selected != null) {
123 123
					app.deselectOthers(app.getGroupTreeView(), groupSelectionModel);
124 124
					app.showFiles(new HashSet<File>());
125
					app.hideUploadArea();
126
					app.upload.setEnabled(false);
125 127
					app.showRelevantToolbarButtons();
126 128
					if (selected.equals(createGroup)) {
127 129
						new CreateGroupCommand(app, null).execute();

Also available in: Unified diff