/*\r
- * Copyright 2011 GRNET S.A. All rights reserved.\r
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or\r
* without modification, are permitted provided that the following\r
*/\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.Resource;\r
-import gr.grnet.pithos.web.client.rest.PostCommand;\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
+\r
+import java.util.Arrays;\r
+import java.util.HashMap;\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.http.client.URL;\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.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.DisclosurePanel;\r
import com.google.gwt.user.client.ui.FlexTable;\r
-import com.google.gwt.user.client.ui.FlowPanel;\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
-\r
- private CheckBox readForAll;\r
-\r
- /**\r
- * An image bundle for this widgets images.\r
- */\r
- public interface Images extends ClientBundle,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
- ImageResource permGroup();\r
-\r
- @Source("gr/grnet/pithos/resources/editdelete.png")\r
- ImageResource delete();\r
-\r
- @Source("gr/grnet/pithos/resources/db_update.png")\r
- ImageResource restore();\r
-\r
- @Source("gr/grnet/pithos/resources/folder_inbox.png")\r
- ImageResource download();\r
- }\r
-\r
/**\r
* The widget that holds the name of the file.\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
+ FlexTable metaTable;\r
/**\r
* The widget's constructor.\r
*/\r
super(_app);\r
file = _file;\r
\r
+ Anchor close = new Anchor("close");\r
+ close.addStyleName("close");\r
+ close.addClickHandler(new ClickHandler() {\r
+ \r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
+ hide();\r
+ }\r
+ });\r
// Set the dialog's caption.\r
setText("File properties");\r
+ setGlassEnabled(true);\r
+ setStyleName("pithos-DialogBox");\r
\r
// Outer contains inner and buttons.\r
final VerticalPanel outer = new VerticalPanel();\r
- final FocusPanel focusPanel = new FocusPanel(outer);\r
+ outer.add(close);\r
// Inner contains generalPanel and permPanel.\r
- inner = new DecoratedTabPanel();\r
- inner.setAnimationEnabled(true);\r
-\r
+ inner = new VerticalPanel();\r
+ inner.addStyleName("inner");\r
\r
- inner.add(createGeneralPanel(), "General");\r
-\r
- inner.add(createSharingPanel(), "Sharing");\r
-\r
- inner.add(createVersionPanel(), "Versions");\r
-\r
- inner.selectTab(0);\r
+ inner.add(createGeneralPanel());\r
\r
outer.add(inner);\r
\r
- final HorizontalPanel buttons = new HorizontalPanel();\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
@Override\r
public void onClick(ClickEvent event) {\r
- accept();\r
- closeDialog();\r
+ if (accept())\r
+ closeDialog();\r
}\r
});\r
+ ok.addStyleName("button");\r
\r
- buttons.add(ok);\r
- buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
- // Create the 'Cancel' button, along with a listener that hides the\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
- closeDialog();\r
- }\r
- });\r
- buttons.add(cancel);\r
- buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
- buttons.setSpacing(8);\r
- buttons.addStyleName("pithos-TabPanelBottom");\r
+ outer.add(ok);\r
+ outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
\r
- outer.add(buttons);\r
- outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
- outer.addStyleName("pithos-TabPanelBottom");\r
-\r
- focusPanel.setFocus(true);\r
setWidget(outer);\r
}\r
\r
- private VerticalPanel createGeneralPanel() {\r
+ private VerticalPanel createGeneralPanel() {\r
final VerticalPanel generalPanel = new VerticalPanel();\r
final FlexTable generalTable = new FlexTable();\r
generalTable.setText(0, 0, "Name");\r
generalTable.setText(1, 0, "Folder");\r
generalTable.setText(2, 0, "Owner");\r
generalTable.setText(3, 0, "Last modified");\r
- generalTable.setText(4, 0, "Tags");\r
\r
name.setWidth("100%");\r
name.setText(file.getName());\r
generalTable.setWidget(0, 1, name);\r
- if(file.getParent() != null)\r
+ if(file.getParent() != null) {\r
generalTable.setText(1, 1, file.getParent().getName());\r
- else\r
+ }\r
+ else {\r
generalTable.setText(1, 1, "-");\r
- generalTable.setText(2, 1, file.getOwner());\r
+ }\r
+\r
+ final String ownerID = file.getOwnerID();\r
+ final String displayName = app.getDisplayNameForUserID(ownerID);\r
+ final String ownerDisplayName;\r
+ if(displayName == null) {\r
+ // FIXME: Get the actual display name and do not use the id\r
+ ownerDisplayName = ownerID;\r
+ }\r
+ else {\r
+ ownerDisplayName = displayName;\r
+ }\r
+ generalTable.setText(2, 1, ownerDisplayName);\r
\r
final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
- generalTable.setText(3, 1, formatter.format(file.getLastModified()));\r
-\r
- StringBuffer tagsBuffer = new StringBuffer();\r
- for (String t : file.getTags())\r
- tagsBuffer.append(t).append(", ");\r
- if (tagsBuffer.length() > 1)\r
- tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);\r
- initialTagText = tagsBuffer.toString();\r
- tags.setWidth("100%");\r
- tags.setText(initialTagText);\r
- generalTable.setWidget(4, 1, tags);\r
+ generalTable.setText(3, 1, file.getLastModified() != null ? formatter.format(file.getLastModified()) : "");\r
\r
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
- generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");\r
generalTable.setCellSpacing(4);\r
\r
generalPanel.add(generalTable);\r
\r
- DisclosurePanel allTags = new DisclosurePanel("All tags");\r
- allTagsContent = new FlowPanel();\r
- allTagsContent.setWidth("100%");\r
- for (Tag t : app.getAllTags()) {\r
- final Anchor tagAnchor = new Anchor(t.getName(), false);\r
- tagAnchor.addStyleName("pithos-tag");\r
- allTagsContent.add(tagAnchor);\r
- Label separator = new Label(", ");\r
- separator.addStyleName("pithos-tag");\r
- allTagsContent.add(separator);\r
- tagAnchor.addClickHandler(new ClickHandler() {\r
+ HorizontalPanel metaTitlePanel = new HorizontalPanel();\r
+ metaTitlePanel.setSpacing(5);\r
+ Label meta = new Label("Meta data");\r
+ meta.addStyleName("pithos-metaTitle");\r
+ metaTitlePanel.add(meta);\r
+ \r
+ Anchor plus = new Anchor("add");\r
+ plus.addStyleName(Pithos.resources.pithosCss().commandAnchor());\r
+ metaTitlePanel.add(plus);\r
+ \r
+ generalPanel.add(metaTitlePanel);\r
+ \r
+ metaTable = new FlexTable();\r
+ metaTable.setCellSpacing(0);\r
+ metaTable.setHTML(0, 0, "Name");\r
+ metaTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+ metaTable.setText(0, 1, "Value");\r
+ metaTable.getFlexCellFormatter().setStyleName(0, 1, "props-labels");\r
+ int rows = 1;\r
+ for (String metaKey : file.getMeta().keySet()) {\r
+ addFormLine(metaTable, rows++, metaKey, file.getMeta().get(metaKey));\r
+ }\r
+ if (rows == 1) //If no meta add an empty line\r
+ addFormLine(metaTable, rows++, "", "");\r
+ \r
+ plus.addClickHandler(new ClickHandler() {\r
+ \r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
+ addFormLine(metaTable, metaTable.getRowCount(), "", "");\r
+ }\r
+ });\r
\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- String existing = tags.getText().trim();\r
- if (MULTIPLE_VALUES_TEXT.equals(existing))\r
- existing = "";\r
- String newTag = tagAnchor.getText().trim();\r
- // insert the new tag only if it is not in the list\r
- // already\r
- if (existing.indexOf(newTag) == -1)\r
- tags.setText(existing + (existing.length() > 0 ? ", " : "") + newTag);\r
- }\r
- });\r
- }\r
- allTags.setContent(allTagsContent);\r
- generalPanel.add(allTags);\r
+ generalPanel.add(metaTable);\r
generalPanel.setSpacing(4);\r
return generalPanel;\r
}\r
\r
- private VerticalPanel createSharingPanel() {\r
- VerticalPanel permPanel = new VerticalPanel();\r
-\r
- permList = new PermissionsList(app, images, file.getPermissions(), file.getOwner());\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
-\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
-\r
- permButtons.setSpacing(8);\r
- permButtons.addStyleName("pithos-TabPanelBottom");\r
- permPanel.add(permButtons);\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.setValue(file.isPublished());\r
- readForAll.addClickHandler(new ClickHandler() {\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- readForAllNote.setVisible(readForAll.getValue());\r
- }\r
- });\r
-\r
- // Only show the read for all permission if the user is the owner.\r
- if (file.getOwner().equals(app.getUsername())) {\r
- final HorizontalPanel permForAll = new HorizontalPanel();\r
- permForAll.add(new Label("Public"));\r
- permForAll.add(readForAll);\r
- permForAll.setSpacing(8);\r
- permForAll.addStyleName("pithos-TabPanelBottom");\r
- permForAll.add(readForAllNote);\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
- return permPanel;\r
- }\r
-\r
- private VerticalPanel createVersionPanel() {\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
- return versionPanel;\r
- }\r
+ void addFormLine(final FlexTable table, int row, String _name, String _value) {\r
+ TextBox nameBox = new TextBox();\r
+ nameBox.setText(_name);\r
+ nameBox.addStyleName("pithos-metaName");\r
+ table.setWidget(row, 0, nameBox);\r
+ table.getFlexCellFormatter().setStyleName(1, 0, "props-values");\r
+\r
+ TextBox valueBox = new TextBox();\r
+ valueBox.setText(_value);\r
+ valueBox.addStyleName("pithos-metaValue");\r
+ table.setWidget(row, 1, valueBox);\r
+ table.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
+ \r
+ Anchor delete = new Anchor("remove");\r
+ delete.addStyleName(Pithos.resources.pithosCss().commandAnchor());\r
+ delete.addClickHandler(new ClickHandler() {\r
+ \r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
+ int rowIndex = table.getCellForEvent(event).getRowIndex();\r
+ table.removeRow(rowIndex);\r
+ }\r
+ });\r
+ table.setWidget(row, 2, delete);\r
+ }\r
\r
/**\r
* Accepts any change and updates the file\r
*\r
*/\r
@Override\r
- protected void accept() {\r
+ protected boolean accept() {\r
String newFilename = null;\r
-// permList.updatePermissionsAccordingToInput();\r
-// Set<PermissionHolder> perms = permList.getPermissions();\r
-// JSONObject json = new JSONObject();\r
+\r
if (!name.getText().trim().equals(file.getName())) {\r
newFilename = name.getText().trim();\r
-// json.put("name", new JSONString(newFilename));\r
+ if (newFilename.length() == 0)\r
+ newFilename = null;\r
}\r
-// if (versioned.getValue() != file.isVersioned())\r
-// json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));\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
- 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
- final String[] newTags = tagset;\r
+ \r
+\r
+ final Map<String, String> newMeta = new HashMap<String, String>();\r
+ for (int row = 1; row < metaTable.getRowCount(); row++) {\r
+ String key = ((TextBox) metaTable.getWidget(row, 0)).getText().trim();\r
+ String value = ((TextBox) metaTable.getWidget(row, 1)).getText().trim();\r
+ if (key.length() > 0 && value.length() > 0)\r
+ newMeta.put(key, value);\r
+ else if ((key.length() > 0 && value.length() == 0) || (key.length() == 0 && value.length() > 0)) {\r
+ app.displayError("You have empty keys or values");\r
+ return false;\r
+ }\r
+ }\r
\r
if (newFilename != null) {\r
final String path = file.getParent().getUri() + "/" + newFilename;\r
- PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
+ PutRequest updateFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), 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
+ updateMetaData(Pithos.getStorageAPIURL(), file.getOwnerID(), path, newMeta);\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
- updateFile.setHeader("X-Auth-Token", app.getToken());\r
- updateFile.setHeader("X-Move-From", file.getUri());\r
+ updateFile.setHeader("X-Auth-Token", app.getUserToken());\r
+ updateFile.setHeader("X-Move-From", URL.encodePathSegment(file.getUri()));\r
updateFile.setHeader("Content-Type", file.getContentType());\r
+ for (String key : file.getMeta().keySet())\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+ if (file.isPublished())\r
+ updateFile.setHeader("X-Object-Public", "true");\r
+ String readPermHeader = "read=";\r
+ String writePermHeader = "write=";\r
+ for (String u : file.getPermissions().keySet()) {\r
+ Boolean[] p = file.getPermissions().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
+ else\r
+ permHeader = URL.encodePathSegment(permHeader);\r
+ updateFile.setHeader("X-Object-Sharing", permHeader);\r
+\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(Pithos.getStorageAPIURL(), app.getUserID(), file.getUri(), newMeta);\r
+ return true;\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(final String api, final String owner, final String path, Map<String, String> newMeta) {\r
+ if (newMeta != null) {\r
+ PostRequest updateFile = new PostRequest(api, owner, path + "?update=") {\r
+ @Override\r
+ public void onSuccess(Resource result) {\r
+ if (!app.isMySharedSelected())\r
+ app.updateFolder(file.getParent(), true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ app.getFileList().selectByUrl(Arrays.asList(api + owner + path));\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ else {\r
+ app.updateSharedFolder(file.getParent(), true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ app.getFileList().selectByUrl(Arrays.asList(api + owner + path));\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
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- app.displayError("System error modifying file:" + t.getMessage());\r
+ @Override\r
+ protected void onUnauthorized(Response response) {\r
+ app.sessionExpired();\r
+ }\r
+ };\r
+ updateFile.setHeader("X-Auth-Token", app.getUserToken());\r
+ \r
+ for (String t : file.getMeta().keySet()) {\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~");\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
+ \r
+ for (String key : newMeta.keySet())\r
+ updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+ \r
+ Scheduler.get().scheduleDeferred(updateFile);\r
+ }\r
+ else if (!app.isMySharedSelected())\r
+ app.updateFolder(file.getParent(), true, new Command() {\r
+ \r
+ @Override\r
+ public void execute() {\r
+ app.getFileList().selectByUrl(Arrays.asList(api + owner + path));\r
+ if (file.isSharedOrPublished())\r
+ app.updateMySharedRoot();\r
+ }\r
+ }, true);\r
+ else {\r
+ app.getFileList().selectByUrl(Arrays.asList(api + owner + path));\r
+ app.updateSharedFolder(file.getParent(), true);\r
+ }\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