*/\r
package gr.grnet.pithos.web.client;\r
\r
-import com.google.gwt.core.client.Scheduler;\r
-import com.google.gwt.json.client.JSONArray;\r
-import com.google.gwt.json.client.JSONString;\r
-import com.google.gwt.user.client.Window;\r
-import com.google.gwt.user.client.ui.Anchor;\r
-import com.google.gwt.user.client.ui.Label;\r
import gr.grnet.pithos.web.client.foldertree.File;\r
+import gr.grnet.pithos.web.client.foldertree.FileVersions;\r
import gr.grnet.pithos.web.client.foldertree.Resource;\r
-import gr.grnet.pithos.web.client.rest.PostCommand;\r
+import gr.grnet.pithos.web.client.foldertree.Version;\r
+import gr.grnet.pithos.web.client.rest.GetRequest;\r
import gr.grnet.pithos.web.client.rest.PostRequest;\r
import gr.grnet.pithos.web.client.rest.PutRequest;\r
import gr.grnet.pithos.web.client.rest.RestException;\r
+import gr.grnet.pithos.web.client.tagtree.Tag;\r
+\r
+import java.util.List;\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.event.dom.client.ClickEvent;\r
import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.http.client.Response;\r
import com.google.gwt.i18n.client.DateTimeFormat;\r
-import com.google.gwt.json.client.JSONBoolean;\r
-import com.google.gwt.json.client.JSONObject;\r
-import com.google.gwt.resources.client.ClientBundle;\r
import com.google.gwt.resources.client.ImageResource;\r
-import com.google.gwt.user.client.Command;\r
-import com.google.gwt.user.client.DeferredCommand;\r
+import com.google.gwt.user.client.Window;\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
import com.google.gwt.user.client.ui.DecoratedTabPanel;\r
import com.google.gwt.user.client.ui.FocusPanel;\r
import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
import com.google.gwt.user.client.ui.HorizontalPanel;\r
+import com.google.gwt.user.client.ui.Label;\r
import com.google.gwt.user.client.ui.TextBox;\r
import com.google.gwt.user.client.ui.VerticalPanel;\r
-import gr.grnet.pithos.web.client.tagtree.Tag;\r
-import java.util.Iterator;\r
\r
/**\r
* The 'File properties' dialog box implementation.\r
*/\r
public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
\r
- private PermissionsList permList;\r
+ protected PermissionsList permList;\r
\r
- private CheckBox readForAll;\r
+ protected CheckBox readForAll;\r
\r
/**\r
* An image bundle for this widgets images.\r
*/\r
- public interface Images extends ClientBundle,MessagePanel.Images {\r
+ public interface Images extends MessagePanel.Images {\r
\r
@Source("gr/grnet/pithos/resources/edit_user.png")\r
ImageResource permUser();\r
\r
- @Source("gr/grnet/pithos/resources/groupevent.png")\r
+ @Source("gr/grnet/pithos/resources/groups22.png")\r
ImageResource permGroup();\r
\r
@Source("gr/grnet/pithos/resources/editdelete.png")\r
*/\r
private TextBox name = new TextBox();\r
\r
- private final CheckBox versioned = new CheckBox();\r
-\r
final File file;\r
\r
- private String userFullName;\r
-\r
Images images = GWT.create(Images.class);\r
\r
/**\r
\r
inner.add(createSharingPanel(), "Sharing");\r
\r
- inner.add(createVersionPanel(), "Versions");\r
-\r
+ fetchVersions();\r
+ \r
inner.selectTab(0);\r
\r
outer.add(inner);\r
// when the button is clicked.\r
final Button ok = new Button("OK", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
accept();\r
closeDialog();\r
}\r
// dialog when the button is clicked.\r
final Button cancel = new Button("Cancel", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
closeDialog();\r
}\r
});\r
setWidget(outer);\r
}\r
\r
- private VerticalPanel createGeneralPanel() {\r
+ protected void fetchVersions() {\r
+ String path = file.getUri() + "?format=json&version=list";\r
+ GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {\r
+\r
+ @Override\r
+ public void onSuccess(FileVersions _result) {\r
+ inner.add(createVersionPanel(_result.getVersions()), "Versions");\r
+ }\r
+\r
+ @Override\r
+ public void onError(Throwable t) {\r
+ if (t instanceof RestException) {\r
+ app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());\r
+ }\r
+ else\r
+ app.displayError("System error unable to fetch versions: "+t.getMessage());\r
+ }\r
+\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
+ };\r
+ getVersions.setHeader("X-Auth-Token", app.getToken());\r
+ Scheduler.get().scheduleDeferred(getVersions);\r
+ }\r
+\r
+ private VerticalPanel createGeneralPanel() {\r
final VerticalPanel generalPanel = new VerticalPanel();\r
final FlexTable generalTable = new FlexTable();\r
generalTable.setText(0, 0, "Name");\r
tagAnchor.addClickHandler(new ClickHandler() {\r
\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
String existing = tags.getText().trim();\r
if (MULTIPLE_VALUES_TEXT.equals(existing))\r
existing = "";\r
private VerticalPanel createSharingPanel() {\r
VerticalPanel permPanel = new VerticalPanel();\r
\r
- permList = new PermissionsList(app, images, file.getPermissions(), file.getOwner());\r
+ permList = new PermissionsList(images, file.getPermissions(), file.getOwner(), file.getInheritedPermissionsFrom() != null);\r
permPanel.add(permList);\r
\r
- HorizontalPanel permButtons = new HorizontalPanel();\r
- Button add = new Button("Add Group", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);\r
- dlg.center();\r
- permList.updatePermissionTable();\r
- }\r
- });\r
- permButtons.add(add);\r
- permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
+ if (file.getInheritedPermissionsFrom() == null) {\r
+ HorizontalPanel permButtons = new HorizontalPanel();\r
+ Button add = new Button("Add Group", new ClickHandler() {\r
+ @Override\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+ PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);\r
+ dlg.center();\r
+ permList.updatePermissionTable();\r
+ }\r
+ });\r
+ permButtons.add(add);\r
+ permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
\r
- final Button addUser = new Button("Add User", new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);\r
- dlg.center();\r
- permList.updatePermissionTable();\r
- }\r
- });\r
- permButtons.add(addUser);\r
- permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
+ final Button addUser = new Button("Add User", new ClickHandler() {\r
+ @Override\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+ PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);\r
+ dlg.center();\r
+ permList.updatePermissionTable();\r
+ }\r
+ });\r
+ permButtons.add(addUser);\r
+ permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
\r
- permButtons.setSpacing(8);\r
- permButtons.addStyleName("pithos-TabPanelBottom");\r
- permPanel.add(permButtons);\r
+ permButtons.setSpacing(8);\r
+ permButtons.addStyleName("pithos-TabPanelBottom");\r
+ permPanel.add(permButtons);\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
readForAll.setValue(file.isPublished());\r
readForAll.addClickHandler(new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
readForAllNote.setVisible(readForAll.getValue());\r
}\r
});\r
return permPanel;\r
}\r
\r
- private VerticalPanel createVersionPanel() {\r
+ VerticalPanel createVersionPanel(List<Version> versions) {\r
VerticalPanel versionPanel = new VerticalPanel();\r
-\r
-// VersionsList verList = new VersionsList(this, images, bodies);\r
-// versionPanel.add(verList);\r
-//\r
-// HorizontalPanel vPanel = new HorizontalPanel();\r
-//\r
-// vPanel.setSpacing(8);\r
-// vPanel.addStyleName("pithos-TabPanelBottom");\r
-// vPanel.add(new Label("Versioned"));\r
-//\r
-// versioned.setValue(file.isVersioned());\r
-// vPanel.add(versioned);\r
-// versionPanel.add(vPanel);\r
-//\r
-// HorizontalPanel vPanel2 = new HorizontalPanel();\r
-// vPanel2.setSpacing(8);\r
-// vPanel2.addStyleName("pithos-TabPanelBottom");\r
-//\r
-// HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");\r
-// vPanel2.add(removeAllVersion);\r
-//\r
-// Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {\r
-// @Override\r
-// public void onClick(ClickEvent event) {\r
-// ConfirmationDialog confirm = new ConfirmationDialog("Really " +\r
-// "remove all previous versions?", "Remove") {\r
-//\r
-// @Override\r
-// public void cancel() {\r
-// }\r
-//\r
-// @Override\r
-// public void confirm() {\r
-// FilePropertiesDialog.this.closeDialog();\r
-// removeAllOldVersions();\r
-// }\r
-//\r
-// };\r
-// confirm.center();\r
-// }\r
-//\r
-// });\r
-// vPanel2.add(removeVersionsButton);\r
-// if(!file.isVersioned())\r
-// vPanel2.setVisible(false);\r
-//\r
-// versionPanel.add(vPanel2);\r
-\r
+ VersionsList verList = new VersionsList(app, this, images, file, versions);\r
+ versionPanel.add(verList);\r
return versionPanel;\r
}\r
\r
@Override\r
protected void accept() {\r
String newFilename = null;\r
-// permList.updatePermissionsAccordingToInput();\r
-// Set<PermissionHolder> perms = permList.getPermissions();\r
-// JSONObject json = new JSONObject();\r
+\r
+ final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);\r
+\r
if (!name.getText().trim().equals(file.getName())) {\r
newFilename = name.getText().trim();\r
-// json.put("name", new JSONString(newFilename));\r
}\r
-// if (versioned.getValue() != file.isVersioned())\r
-// json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));\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
-// json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
-// int i = 0;\r
-// if (permList.hasChanges()) {\r
-// GWT.log("Permissions change", null);\r
-// JSONArray perma = new JSONArray();\r
-//\r
-// for (PermissionHolder p : perms) {\r
-// JSONObject po = new JSONObject();\r
-// if (p.getUser() != null)\r
-// po.put("user", new JSONString(p.getUser()));\r
-// if (p.getGroup() != null)\r
-// po.put("group", new JSONString(p.getGroup()));\r
-// po.put("read", JSONBoolean.getInstance(p.isRead()));\r
-// po.put("write", JSONBoolean.getInstance(p.isWrite()));\r
-// po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));\r
-// perma.set(i, po);\r
-// i++;\r
-// }\r
-// json.put("permissions", perma);\r
-// }\r
+\r
String[] tagset = null;\r
if (!tags.getText().equals(initialTagText))\r
- tagset = tags.getText().split(",");\r
-// String jsonString = json.toString();\r
-// if(jsonString.equals("{}")){\r
-// GWT.log("NO CHANGES", null);\r
-// return;\r
-// }\r
+ tagset = tags.getText().trim().split(",");\r
final String[] newTags = tagset;\r
\r
if (newFilename != null) {\r
final String path = file.getParent().getUri() + "/" + newFilename;\r
PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
@Override\r
- public void onSuccess(Resource result) {\r
- if (newTags != null || finalPublished != null)\r
- updateMetaData(app.getApiPath(), app.getUsername(), path + "?update=", newTags, finalPublished);\r
- else\r
- app.updateFolder(file.getParent());\r
+ public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+ updateMetaData(app.getApiPath(), file.getOwner(), path + "?update=", newTags, finalPublished, perms);\r
}\r
\r
@Override\r
GWT.log("", 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
updateFile.setHeader("X-Auth-Token", app.getToken());\r
updateFile.setHeader("X-Move-From", file.getUri());\r
updateFile.setHeader("Content-Type", file.getContentType());\r
Scheduler.get().scheduleDeferred(updateFile);\r
}\r
- else if (newTags != null || finalPublished != null)\r
- updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished);\r
+ else\r
+ updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished, perms);\r
}\r
\r
- private void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published) {\r
- PostRequest updateFile = new PostRequest(api, owner, path) {\r
- @Override\r
- public void onSuccess(Resource result) {\r
- app.updateFolder(file.getParent());\r
- }\r
+ protected void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published, Map<String, Boolean[]> newPermissions) {\r
+ if (newTags != null || published != null || newPermissions != null) {\r
+ PostRequest updateFile = new PostRequest(api, owner, path) {\r
+ @Override\r
+ public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+ app.updateFolder(file.getParent(), true, null);\r
+ }\r
\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- app.displayError("System error modifying file:" + t.getMessage());\r
+ @Override\r
+ public void onError(Throwable t) {\r
+ GWT.log("", 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
+ updateFile.setHeader("X-Auth-Token", app.getToken());\r
+ if (newTags != null)\r
+ for (String t : newTags)\r
+ if (t.length() > 0)\r
+ updateFile.setHeader("X-Object-Meta-" + t.trim(), "true");\r
+ for (String t : file.getTags())\r
+ updateFile.setHeader("X-Object-Meta-" + t.trim(), "~");\r
+ if (published != null)\r
+ updateFile.setHeader("X-Object-Public", published.toString());\r
+ if (newPermissions != null) {\r
+ String readPermHeader = "read=";\r
+ String writePermHeader = "write=";\r
+ for (String u : newPermissions.keySet()) {\r
+ Boolean[] p = newPermissions.get(u);\r
+ if (p[0] != null && p[0])\r
+ readPermHeader += u + ",";\r
+ if (p[1] != null && p[1])\r
+ writePermHeader += u + ",";\r
+ }\r
+ if (readPermHeader.endsWith("="))\r
+ readPermHeader = "";\r
+ else if (readPermHeader.endsWith(","))\r
+ readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);\r
+ if (writePermHeader.endsWith("="))\r
+ writePermHeader = "";\r
+ else if (writePermHeader.endsWith(","))\r
+ writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);\r
+ String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader;\r
+ if (permHeader.length() == 0)\r
+ permHeader="~";\r
+ updateFile.setHeader("X-Object-Sharing", permHeader);\r
}\r
- };\r
- updateFile.setHeader("X-Auth-Token", app.getToken());\r
- if (newTags != null)\r
- for (String t : newTags)\r
- updateFile.setHeader("X-Object-Meta-" + t.trim(), "true");\r
- if (published != null)\r
- updateFile.setHeader("X-Object-Public", published.toString());\r
- Scheduler.get().scheduleDeferred(updateFile);\r
+ Scheduler.get().scheduleDeferred(updateFile);\r
+ }\r
+ else\r
+ app.updateFolder(file.getParent(), true, null);\r
}\r
-\r
- private void removeAllOldVersions() {\r
- JSONObject json = new JSONObject();\r
- json.put("versioned", JSONBoolean.getInstance(false));\r
- GWT.log(json.toString(), null);\r
- PostCommand cf = new PostCommand(app, file.getUri() + "?update=", json.toString(), 200) {\r
-\r
- @Override\r
- public void onComplete() {\r
- toggleVersioned(true);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if (t instanceof RestException) {\r
- int statusCode = ((RestException) t).getHttpStatusCode();\r
- if (statusCode == 405)\r
- app.displayError("You don't have the necessary permissions");\r
- else if (statusCode == 404)\r
- app.displayError("User in permissions does not exist");\r
- else if (statusCode == 409)\r
- app.displayError("A folder with the same name already exists");\r
- else if (statusCode == 413)\r
- app.displayError("Your quota has been exceeded");\r
- else\r
- app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
- } else\r
- app.displayError("System error moifying file:" + t.getMessage());\r
- }\r
- };\r
- DeferredCommand.addCommand(cf);\r
- }\r
-\r
- private void toggleVersioned(boolean versionedValue) {\r
- JSONObject json = new JSONObject();\r
- json.put("versioned", JSONBoolean.getInstance(versionedValue));\r
- GWT.log(json.toString(), null);\r
- PostCommand cf = new PostCommand(app, file.getUri() + "?update=", json.toString(), 200) {\r
-\r
- @Override\r
- public void onComplete() {\r
- app.getTreeView().refreshCurrentNode(false);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- if (t instanceof RestException) {\r
- int statusCode = ((RestException) t).getHttpStatusCode();\r
- if (statusCode == 405)\r
- app.displayError("You don't have the necessary permissions");\r
- else if (statusCode == 404)\r
- app.displayError("User in permissions does not exist");\r
- else if (statusCode == 409)\r
- app.displayError("A folder with the same name already exists");\r
- else if (statusCode == 413)\r
- app.displayError("Your quota has been exceeded");\r
- else\r
- app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
- } else\r
- app.displayError("System error moifying file:" + t.getMessage());\r
- }\r
- };\r
- DeferredCommand.addCommand(cf);\r
- }\r
-\r
}\r