Document the role of PithosDisclosurePanel
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileShareDialog.java
index 5a57998..579f39e 100644 (file)
@@ -59,6 +59,57 @@ import java.util.Map;
  * UI for the "Share" command.
  */
 public class FileShareDialog extends AbstractPropertiesDialog {
+    private static final class PermissionsUncheckWarning extends AbstractPropertiesDialog {
+        private PermissionsUncheckWarning(Pithos app) {
+            super(app);
+            final Anchor close = new Anchor("close");
+            close.addStyleName("close");
+            close.addClickHandler(new ClickHandler() {
+                @Override
+                public void onClick(ClickEvent event) {
+                    hide();
+                }
+            });
+            final String dialogText = "Info";
+            setText(dialogText);
+            setStyleName("pithos-DialogBox");
+
+            final VerticalPanel panel = new VerticalPanel();
+            panel.add(close);
+
+            VerticalPanel inner = new VerticalPanel();
+            inner.addStyleName("inner");
+
+            inner.add(
+                new InlineHTML(
+                    "It seems you are already sharing this file with some users." +
+                    "<br>" +
+                    "Please remove all users from the sharing list, to be able to uncheck this option."
+                )
+            );
+
+            final Button ok = new Button("OK", new ClickHandler() {
+                @Override
+                public void onClick(ClickEvent event) {
+                    hide();
+                }
+            });
+
+            ok.addStyleName("button");
+            inner.add(ok);
+
+            panel.add(inner);
+            panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
+
+            setWidget(panel);
+        }
+
+        @Override
+        protected boolean accept() {
+            return true;
+        }
+    }
+
     // For public sharing
        private final HorizontalPanel publicPathPanel = new HorizontalPanel();
        private final TextBox publicPathText = new TextBox();
@@ -66,23 +117,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     // For private sharing
     private final HorizontalPanel privatePathPanel = new HorizontalPanel();
     private final TextBox privatePathText = new TextBox();
-    private final VerticalPanel privatePermSuperPanel = new VerticalPanel();
     private PermissionsList permList;
-       
-       /**
-        * An image bundle for this widgets images.
-        */
-       public interface PublicSharingImages extends MessagePanel.Images {
-
-               @Source("gr/grnet/pithos/resources/edit_user.png")
-               ImageResource permUser();
-
-               @Source("gr/grnet/pithos/resources/groups22.png")
-               ImageResource permGroup();
-
-               @Source("gr/grnet/pithos/resources/editdelete.png")
-               ImageResource delete();
-    }
 
     public interface PrivateSharingImages extends MessagePanel.Images {
 
@@ -98,7 +133,6 @@ public class FileShareDialog extends AbstractPropertiesDialog {
 
     private final File file;
 
-    private final PublicSharingImages publicSharingImages = GWT.create(PublicSharingImages.class);
     private final PrivateSharingImages privateSharingImages = GWT.create(PrivateSharingImages.class);
 
        /**
@@ -118,7 +152,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
                        }
                });
                // Set the dialog's caption.
-               setText("Share");
+               setText(Const.TXT_SHARE_FILE);
                setGlassEnabled(true);
                setStyleName("pithos-DialogBox");
 
@@ -187,7 +221,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
             publicPathPanel.setVisible(false);
             publicPathPanel.setWidth(Const.PERCENT_100);
             publicPathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
-            publicPathPanel.add(new Label("Link"));
+            publicPathPanel.add(new Label(Const.TXT_PUBLIC_LINK));
             publicPathPanel.setSpacing(8);
             publicPathPanel.addStyleName("pithos-TabPanelBottom");
 
@@ -200,7 +234,8 @@ public class FileShareDialog extends AbstractPropertiesDialog {
                     Pithos.preventIESelection();
                 }
             });
-            publicPathText.setText(Window.Location.getHost() + file.getPublicUri());
+
+            publicPathText.setText(""); // check: showLinkForPublicSharing();
             publicPathText.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
             publicPathText.setReadOnly(true);
             publicPathPanel.add(publicPathText);
@@ -235,16 +270,23 @@ public class FileShareDialog extends AbstractPropertiesDialog {
         privateCheckBox.addClickHandler(new ClickHandler() {
             @Override
             public void onClick(ClickEvent event) {
+                // This is the value *after* the click is applied :)
+                boolean userCheckedIt = privateCheckBox.getValue();
+                boolean userUncheckedIt = !userCheckedIt;
+
                 if(isFilePrivatelyShared()) {
                     // ignore the click, set it always to "checked"
                     privateCheckBox.setValue(true);
                     // show permissions
                     privatePermPanel.setVisible(true);
+
+                    // Refs #3593
+                    if(userUncheckedIt) {
+                        new PermissionsUncheckWarning(app).center();
+                    }
                 }
                 else {
-                    // This is the value *after* the click is applied :)
-                    boolean isChecked = privateCheckBox.getValue();
-                    privatePermPanel.setVisible(isChecked);
+                    privatePermPanel.setVisible(userCheckedIt);
                 }
             }
         });
@@ -274,22 +316,23 @@ public class FileShareDialog extends AbstractPropertiesDialog {
         permButtons.add(addUser);
 
         final boolean haveGroups = app.getAccount().getGroups().size() > 0;
-        Button addGroup = new Button("Add Group", new ClickHandler() {
-            @Override
-            public void onClick(ClickEvent event) {
-                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
-                dlg.center();
-                permList.updatePermissionTable();
-            }
-        });
-        addGroup.addStyleName("button");
-        addGroup.setEnabled(haveGroups);
-        if(!haveGroups) {
-            addGroup.setTitle("You do not have any groups");
+
+        if(haveGroups) {
+            Button addGroup = new Button("Add Group", new ClickHandler() {
+                @Override
+                public void onClick(ClickEvent event) {
+                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
+                    dlg.center();
+                    permList.updatePermissionTable();
+                }
+            });
+            addGroup.addStyleName("button");
+
+            permButtons.add(addGroup);
+            permButtons.setCellHorizontalAlignment(addGroup, HasHorizontalAlignment.ALIGN_CENTER);
         }
-        permButtons.add(addGroup);
 
-        Button addEverybody = new Button("Add everybody", new ClickHandler() {
+        final Button addEverybody = new Button("Add everybody", new ClickHandler() {
             @Override
             public void onClick(ClickEvent event) {
                 Pithos.LOG("Adding to Everybody");
@@ -301,7 +344,6 @@ public class FileShareDialog extends AbstractPropertiesDialog {
         addEverybody.addStyleName("button");
         permButtons.add(addEverybody);
 
-        permButtons.setCellHorizontalAlignment(addGroup, HasHorizontalAlignment.ALIGN_CENTER);
         privatePermPanel.add(permList);
         privatePermPanel.add(permButtons);
 
@@ -309,7 +351,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
         privatePathPanel.setVisible(false);
         privatePathPanel.setWidth(Const.PERCENT_100);
         privatePathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
-        privatePathPanel.add(new Label("Link"));
+        privatePathPanel.add(new Label(Const.TXT_PRIVATE_LINK));
         privatePathPanel.setSpacing(8);
         privatePathPanel.addStyleName("pithos-TabPanelBottom");
 
@@ -322,7 +364,8 @@ public class FileShareDialog extends AbstractPropertiesDialog {
                 Pithos.preventIESelection();
             }
         });
-        privatePathText.setText(Window.Location.getHost() + file.getPublicUri());
+
+        privatePathText.setText(""); // check: showLinkForPrivateSharing();
         privatePathText.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
         privatePathText.setWidth(Const.PERCENT_100);
         privatePathText.setReadOnly(true);
@@ -365,9 +408,20 @@ public class FileShareDialog extends AbstractPropertiesDialog {
 
     private void showLinkForPublicSharing() {
                if (isFilePubliclyShared()) {
-                       UrlBuilder b = Window.Location.createUrlBuilder();
-                       b.setPath(file.getPublicUri());
-                       publicPathText.setText(b.buildString());
+            // Transitional: When the server returns the full URL in X-Object-Public,
+            //               just use it.
+            final String filePublicURI = file.getPublicUri();
+            final String shownPublicURI;
+            if(filePublicURI.toLowerCase().startsWith("http")) {
+                shownPublicURI = filePublicURI;
+            }
+            else {
+                UrlBuilder b = Window.Location.createUrlBuilder();
+                b.setPath(filePublicURI);
+                shownPublicURI = b.buildString();
+            }
+
+                       publicPathText.setText(shownPublicURI);
                publicPathPanel.setVisible(true);
                }
                else {
@@ -377,11 +431,20 @@ public class FileShareDialog extends AbstractPropertiesDialog {
 
     private void showLinkForPrivateSharing() {
         if (isFilePrivatelyShared()) {
-            UrlBuilder b = Window.Location.createUrlBuilder();
-            b.setPath(app.getApiPath() + file.getOwnerID() + file.getUri());
+            final String fileViewURL = Pithos.getFileViewURL(file);
+            final String shownViewURL;
+            if(fileViewURL.toLowerCase().startsWith("http")) {
+                shownViewURL = fileViewURL;
+            }
+            else {
+                UrlBuilder b = Window.Location.createUrlBuilder();
+                b.setPath(fileViewURL);
+                shownViewURL = b.buildString();
+            }
+
             String href = Window.Location.getHref();
             boolean hasParameters = href.contains(Const.QUESTION_MARK);
-            privatePathText.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + b.buildString());
+            privatePathText.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + shownViewURL);
             privatePathPanel.setVisible(true);
         }
         else {
@@ -394,7 +457,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
             PostRequest updateFile = new PostRequest(api, owner, path) {
                 @Override
                 public void onSuccess(Resource result) {
-                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
+                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
 
                                                @Override
                                                public void onSuccess(File _result) {
@@ -457,7 +520,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     }
     protected void updateMetaDataForPublicSharing(Boolean published) {
         updateMetaDataForPublicSharing(
-            app.getApiPath(),
+            Pithos.getStorageAPIURL(),
             app.getUserID(),
             file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
             published
@@ -469,7 +532,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
             PostRequest updateFile = new PostRequest(api, owner, path) {
                 @Override
                 public void onSuccess(Resource result) {
-                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
+                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
 
                         @Override
                         public void onSuccess(File _result) {
@@ -563,12 +626,13 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     }
     protected void updateMetaDataForPrivateSharing() {
         updateMetaDataForPrivateSharing(
-            app.getApiPath(),
+            Pithos.getStorageAPIURL(),
             app.getUserID(),
             file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
             permList.getPermissions()
         );
     }
+
     @Override
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
            super.onPreviewNativeEvent(preview);