\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
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
\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
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
readForAll.addClickHandler(new ClickHandler() {\r
@Override\r
public void onClick(ClickEvent event) {\r
- readForAllNote.setVisible(readForAll.getValue());\r
+ accept();\r
}\r
});\r
\r
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
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
}\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