When public is checked the action is done immediately without clicking the ok button...
authorChristos Stathis <chstath@ebs.gr>
Wed, 7 Mar 2012 13:25:26 +0000 (15:25 +0200)
committerChristos Stathis <chstath@ebs.gr>
Wed, 7 Mar 2012 13:25:26 +0000 (15:25 +0200)
src/gr/grnet/pithos/web/client/FilePermissionsDialog.java
src/gr/grnet/pithos/web/client/foldertree/File.java

index 95dcd48..662a44f 100644 (file)
@@ -36,19 +36,23 @@ package gr.grnet.pithos.web.client;
 \r
 import gr.grnet.pithos.web.client.foldertree.File;\r
 import gr.grnet.pithos.web.client.foldertree.Resource;\r
+import gr.grnet.pithos.web.client.rest.HeadRequest;\r
 import gr.grnet.pithos.web.client.rest.PostRequest;\r
 \r
 import java.util.Map;\r
 \r
 import com.google.gwt.core.client.GWT;\r
 import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.dom.client.NativeEvent;\r
 import com.google.gwt.event.dom.client.ClickEvent;\r
 import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.event.dom.client.KeyCodes;\r
 import com.google.gwt.http.client.Response;\r
 import com.google.gwt.http.client.URL;\r
 import com.google.gwt.resources.client.ImageResource;\r
 import com.google.gwt.user.client.Command;\r
 import com.google.gwt.user.client.Window;\r
+import com.google.gwt.user.client.Event.NativePreviewEvent;\r
 import com.google.gwt.user.client.ui.Anchor;\r
 import com.google.gwt.user.client.ui.Button;\r
 import com.google.gwt.user.client.ui.CheckBox;\r
@@ -68,7 +72,11 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
        protected PermissionsList permList;\r
 \r
        protected CheckBox readForAll;\r
-\r
+       \r
+       private HorizontalPanel pathPanel;\r
+       \r
+       private TextBox path;\r
+       \r
        /**\r
         * An image bundle for this widgets images.\r
         */\r
@@ -122,12 +130,9 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
 \r
         outer.add(inner);\r
 \r
-               // Create the 'OK' button, along with a listener that hides the dialog\r
-               // when the button is clicked.\r
-               final Button ok = new Button("OK", new ClickHandler() {\r
+               final Button ok = new Button("Close", new ClickHandler() {\r
                        @Override\r
                        public void onClick(ClickEvent event) {\r
-                               accept();\r
                                closeDialog();\r
                        }\r
                });\r
@@ -178,7 +183,6 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
         final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +\r
                     " by everyone. By checking this option, you are certifying that you have the right to " +\r
                     "distribute this file and that it does not violate the Terms of Use.", true);\r
-        readForAllNote.setVisible(false);\r
         readForAllNote.setStylePrimaryName("pithos-readForAllNote");\r
 \r
         readForAll = new CheckBox();\r
@@ -186,7 +190,7 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
         readForAll.addClickHandler(new ClickHandler() {\r
             @Override\r
             public void onClick(ClickEvent event) {\r
-                readForAllNote.setVisible(readForAll.getValue());\r
+               accept();\r
             }\r
         });\r
 \r
@@ -201,35 +205,50 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
             permPanel.add(permForAll);\r
         }\r
 \r
-        if (file.isPublished()) {\r
-            final HorizontalPanel pathPanel = new HorizontalPanel();\r
-            pathPanel.setWidth("100%");\r
-            pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
-            pathPanel.add(new Label("Link"));\r
-            pathPanel.setSpacing(8);\r
-            pathPanel.addStyleName("pithos-TabPanelBottom");\r
-\r
-            TextBox path = new TextBox();\r
-            path.setWidth("100%");\r
-            path.addClickHandler(new ClickHandler() {\r
-                @Override\r
-                public void onClick(ClickEvent event) {\r
-                    Pithos.enableIESelection();\r
-                    ((TextBox) event.getSource()).selectAll();\r
-                    Pithos.preventIESelection();\r
-                }\r
-            });\r
-            path.setText(Window.Location.getHost() + file.getPublicUri());\r
-            path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
-            path.setWidth("100%");\r
-            path.setReadOnly(true);\r
-            pathPanel.add(path);\r
-            permPanel.add(pathPanel);\r
-        }\r
-\r
+        pathPanel = new HorizontalPanel();\r
+        pathPanel.setVisible(false);\r
+        pathPanel.setWidth("100%");\r
+        pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
+        pathPanel.add(new Label("Link"));\r
+        pathPanel.setSpacing(8);\r
+        pathPanel.addStyleName("pithos-TabPanelBottom");\r
+\r
+        path = new TextBox();\r
+        path.setWidth("100%");\r
+        path.addClickHandler(new ClickHandler() {\r
+            @Override\r
+            public void onClick(ClickEvent event) {\r
+                Pithos.enableIESelection();\r
+                ((TextBox) event.getSource()).selectAll();\r
+                Pithos.preventIESelection();\r
+            }\r
+        });\r
+        path.setText(Window.Location.getHost() + file.getPublicUri());\r
+        path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
+        path.setWidth("100%");\r
+        path.setReadOnly(true);\r
+        pathPanel.add(path);\r
+        permPanel.add(pathPanel);\r
+\r
+        Scheduler.get().scheduleDeferred(new Command() {\r
+                       \r
+                       @Override\r
+                       public void execute() {\r
+                               showLinkIfPublished();\r
+                       }\r
+               });\r
         return permPanel;\r
     }\r
 \r
+    void showLinkIfPublished() {\r
+               if (file.isPublished()) {\r
+               path.setText(Window.Location.getHost() + file.getPublicUri());\r
+               pathPanel.setVisible(true);\r
+               }\r
+               else {\r
+                       pathPanel.setVisible(false);\r
+               }\r
+    }\r
        /**\r
         * Accepts any change and updates the file\r
         *\r
@@ -238,28 +257,46 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
        protected void accept() {\r
                final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);\r
 \r
-               //only update the read for all perm if the user is the owner\r
         Boolean published = null;\r
                if (readForAll.getValue() != file.isPublished())\r
                        if (file.getOwner().equals(app.getUsername()))\r
                 published = readForAll.getValue();\r
-        final Boolean finalPublished = published;\r
-\r
-        updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", finalPublished, perms);\r
+        updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", published, perms);\r
        }\r
 \r
-       protected void updateMetaData(String api, String owner, String path, final Boolean published, final Map<String, Boolean[]> newPermissions) {\r
+       protected void updateMetaData(String api, String owner, final String path, final Boolean published, final Map<String, Boolean[]> newPermissions) {\r
         if (published != null || newPermissions != null) {\r
             PostRequest updateFile = new PostRequest(api, owner, path) {\r
                 @Override\r
                 public void onSuccess(Resource result) {\r
-                    app.updateFolder(file.getParent(), true, new Command() {\r
-                                               \r
+                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwner(), path, file) {\r
+\r
                                                @Override\r
-                                               public void execute() {\r
-                                                       app.updateMySharedRoot();\r
+                                               public void onSuccess(File _result) {\r
+                                                       showLinkIfPublished();\r
+                                   app.updateFolder(file.getParent(), true, new Command() {\r
+                                                               \r
+                                                               @Override\r
+                                                               public void execute() {\r
+                                                                       app.updateMySharedRoot();\r
+                                                               }\r
+                                                       });\r
                                                }\r
-                                       });\r
+\r
+                                               @Override\r
+                                               public void onError(Throwable t) {\r
+                                   GWT.log("", t);\r
+                                                       app.setError(t);\r
+                                   app.displayError("System error modifying file:" + t.getMessage());\r
+                                               }\r
+\r
+                                               @Override\r
+                                               protected void onUnauthorized(Response response) {\r
+                                                       app.sessionExpired();\r
+                                               }\r
+                                       };\r
+                                       headFile.setHeader("X-Auth-Token", app.getToken());\r
+                                       Scheduler.get().scheduleDeferred(headFile);\r
                 }\r
 \r
                 @Override\r
@@ -315,4 +352,13 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
                                }\r
                        });\r
     }\r
+\r
+       @Override\r
+       protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
+           super.onPreviewNativeEvent(preview);\r
+\r
+           NativeEvent evt = preview.getNativeEvent();\r
+           if (evt.getType().equals("keydown") && evt.getKeyCode() == KeyCodes.KEY_ENTER)\r
+                               closeDialog();\r
+       }\r
 }\r
index f832e94..6cb4282 100644 (file)
@@ -42,7 +42,9 @@ import java.util.Map;
 import com.google.gwt.http.client.Header;
 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.i18n.client.NumberFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONValue;
 
@@ -224,6 +226,8 @@ public class File extends Resource {
 
     private void populate(String _owner, Response response) {
         this.owner = _owner;
+        published = false;
+        publicUri = null;
         for (Header h : response.getHeaders()) {
                if (h == null)
                        continue; //IE bug. h cannot be null in the general case
@@ -237,6 +241,19 @@ public class File extends Resource {
             else if (header.equals("X-Object-Shared-By")) {
                 inheritedPermissionsFrom = URL.decodePathSegment(h.getValue());
             }
+            else if (header.equals("Content-Length")) {
+                bytes = Long.parseLong(h.getValue());
+            }
+            else if (header.equals("Content-Type")) {
+               contentType = h.getValue();
+            }
+            else if (header.equals("Last-Modified")) {
+               lastModified = DateTimeFormat.getFormat(PredefinedFormat.RFC_2822).parse(h.getValue());
+            }
+            else if (header.equals("X-Object-Public")) {
+               published = true;
+               publicUri = h.getValue();
+            }
         }
     }