Merge branch 'hotfix-0.14.5' into develop
[pithos-web-client] / src / gr / grnet / pithos / web / client / VersionsList.java
index 1e546a7..76fa4ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
  */
 package gr.grnet.pithos.web.client;
 
-import gr.grnet.pithos.web.client.FilePropertiesDialog.Images;
-import gr.grnet.pithos.web.client.foldertree.File;
-import gr.grnet.pithos.web.client.foldertree.Resource;
-import gr.grnet.pithos.web.client.foldertree.Version;
-import gr.grnet.pithos.web.client.rest.PostRequest;
-import gr.grnet.pithos.web.client.rest.RestException;
-
-import java.util.List;
-
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
@@ -50,12 +41,14 @@ import com.google.gwt.http.client.Response;
 import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.AbstractImagePrototype;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.FlexTable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.*;
+import gr.grnet.pithos.web.client.FileVersionsDialog.Images;
+import gr.grnet.pithos.web.client.foldertree.File;
+import gr.grnet.pithos.web.client.foldertree.Version;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.RestException;
+
+import java.util.List;
 
 public class VersionsList extends Composite {
 
@@ -67,13 +60,13 @@ public class VersionsList extends Composite {
     
     private Images images;
     
-    private VerticalPanel permPanel = new VerticalPanel();
+    private CustomScrollPanel permPanel = new CustomScrollPanel();
     
     private FlexTable permTable = new FlexTable();
 
-       FilePropertiesDialog container;
+    FileVersionsDialog container;
 
-       public VersionsList(Pithos _app, FilePropertiesDialog aContainer, final Images theImages, File _file, List<Version> theVersions) {
+       public VersionsList(Pithos _app, FileVersionsDialog aContainer, final Images theImages, File _file, List<Version> theVersions) {
         app = _app;
                images = theImages;
                container = aContainer;
@@ -89,7 +82,8 @@ public class VersionsList extends Composite {
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
                permPanel.add(permTable);
-               permPanel.addStyleName("pithos-TabPanelBottom");
+               permPanel.addStyleName("pithos-versionList");
+               permPanel.setSize("260px", "150px");
                permTable.addStyleName("pithos-permList");
                initWidget(permPanel);
                showVersionsTable();
@@ -102,7 +96,7 @@ public class VersionsList extends Composite {
                        HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>" + AbstractImagePrototype.create(images.restore()).getHTML() + "</span><div>Restore this Version</div></a>");
                        restoreVersion.addClickHandler(new ClickHandler() {
                                @Override
-                               public void onClick(@SuppressWarnings("unused") ClickEvent event) {
+                               public void onClick(ClickEvent event) {
                                        restoreVersion(v.getVersion());
                                }
                        });
@@ -115,8 +109,8 @@ public class VersionsList extends Composite {
                        HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>" + AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>");
                        downloadHtml.addClickHandler(new ClickHandler() {
                                @Override
-                               public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-                                       String fileUrl = app.getApiPath() + file.getOwner() + file.getUri() + "?X-Auth-Token=" + app.getToken() + "&version=" + v.getVersion();
+                               public void onClick(ClickEvent event) {
+                    final String fileUrl = Pithos.getVersionedFileViewURL(file, v.getVersion());
                                        Window.open(fileUrl, "_BLANK", "");
                                }
                        });
@@ -132,15 +126,16 @@ public class VersionsList extends Composite {
 
        void restoreVersion(int version) {
                String path = file.getUri() + "?update=";
-               PostRequest restoreVersion = new PostRequest(app.getApiPath(), file.getOwner(), path) {
+               PostRequest restoreVersion = new PostRequest(Pithos.getStorageAPIURL(), file.getOwnerID(), path) {
                        
                        @Override
-                       public void onSuccess(@SuppressWarnings("unused") Resource result) {
+                       public void onSuccess(Resource result) {
                                container.hide();
                        }
                        
                        @Override
                        public void onError(Throwable t) {
+                               app.setError(t);
                 if (t instanceof RestException) {
                        if (((RestException) t).getHttpStatusCode() == Response.SC_NO_CONTENT)
                                onSuccess(null);
@@ -156,7 +151,7 @@ public class VersionsList extends Composite {
                                app.sessionExpired();
                        }
                };
-               restoreVersion.setHeader("X-Auth-Token", app.getToken());
+               restoreVersion.setHeader("X-Auth-Token", app.getUserToken());
                restoreVersion.setHeader("X-Source-Object", URL.encodePathSegment(file.getUri()));
                restoreVersion.setHeader("X-Source-Version", String.valueOf(version));
                restoreVersion.setHeader("Content-Range", "bytes 0-/*");