Revision 6b7d024f
b/src/gr/grnet/pithos/web/client/FolderContextMenu.java | ||
---|---|---|
134 | 134 |
MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images)); |
135 | 135 |
contextMenu.addItem(delete); |
136 | 136 |
|
137 |
MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, folder, 0));
|
|
138 |
contextMenu.addItem(properties);
|
|
137 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
|
|
138 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
|
|
139 | 139 |
} |
140 | 140 |
} |
141 | 141 |
} |
b/src/gr/grnet/pithos/web/client/FolderPermissionsDialog.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or |
|
5 |
* without modification, are permitted provided that the following |
|
6 |
* conditions are met: |
|
7 |
* |
|
8 |
* 1. Redistributions of source code must retain the above |
|
9 |
* copyright notice, this list of conditions and the following |
|
10 |
* disclaimer. |
|
11 |
* |
|
12 |
* 2. Redistributions in binary form must reproduce the above |
|
13 |
* copyright notice, this list of conditions and the following |
|
14 |
* disclaimer in the documentation and/or other materials |
|
15 |
* provided with the distribution. |
|
16 |
* |
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
28 |
* POSSIBILITY OF SUCH DAMAGE. |
|
29 |
* |
|
30 |
* The views and conclusions contained in the software and |
|
31 |
* documentation are those of the authors and should not be |
|
32 |
* interpreted as representing official policies, either expressed |
|
33 |
* or implied, of GRNET S.A. |
|
34 |
*/ |
|
35 |
package gr.grnet.pithos.web.client; |
|
36 |
|
|
37 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
38 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
39 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
40 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
|
41 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
|
42 |
import gr.grnet.pithos.web.client.rest.RestException; |
|
43 |
|
|
44 |
import java.util.Iterator; |
|
45 |
import java.util.Map; |
|
46 |
|
|
47 |
import com.google.gwt.core.client.GWT; |
|
48 |
import com.google.gwt.core.client.Scheduler; |
|
49 |
import com.google.gwt.dom.client.NativeEvent; |
|
50 |
import com.google.gwt.event.dom.client.ClickEvent; |
|
51 |
import com.google.gwt.event.dom.client.ClickHandler; |
|
52 |
import com.google.gwt.event.dom.client.KeyCodes; |
|
53 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
|
54 |
import com.google.gwt.http.client.Response; |
|
55 |
import com.google.gwt.http.client.URL; |
|
56 |
import com.google.gwt.user.client.Command; |
|
57 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
|
58 |
import com.google.gwt.user.client.ui.Anchor; |
|
59 |
import com.google.gwt.user.client.ui.Button; |
|
60 |
import com.google.gwt.user.client.ui.DialogBox; |
|
61 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
|
62 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
|
63 |
import com.google.gwt.user.client.ui.Label; |
|
64 |
import com.google.gwt.user.client.ui.VerticalPanel; |
|
65 |
|
|
66 |
/** |
|
67 |
* The 'Folder properties' dialog box implementation. |
|
68 |
*/ |
|
69 |
public class FolderPermissionsDialog extends DialogBox { |
|
70 |
|
|
71 |
protected Pithos app; |
|
72 |
|
|
73 |
/** |
|
74 |
* The widget that holds the folderName of the folder. |
|
75 |
*/ |
|
76 |
Label folderName = new Label(); |
|
77 |
|
|
78 |
protected PermissionsList permList; |
|
79 |
|
|
80 |
final Folder folder; |
|
81 |
|
|
82 |
final VerticalPanel inner; |
|
83 |
|
|
84 |
/** |
|
85 |
* The widget's constructor. |
|
86 |
*/ |
|
87 |
public FolderPermissionsDialog(final Pithos app, Folder selected) { |
|
88 |
this.app = app; |
|
89 |
Anchor close = new Anchor(); |
|
90 |
close.addStyleName("close"); |
|
91 |
close.addClickHandler(new ClickHandler() { |
|
92 |
|
|
93 |
@Override |
|
94 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
95 |
hide(); |
|
96 |
} |
|
97 |
}); |
|
98 |
|
|
99 |
setAnimationEnabled(true); |
|
100 |
setGlassEnabled(true); |
|
101 |
setStyleName("pithos-DialogBox"); |
|
102 |
|
|
103 |
// Enable IE selection for the dialog (must disable it upon closing it) |
|
104 |
Pithos.enableIESelection(); |
|
105 |
|
|
106 |
folder = selected; |
|
107 |
|
|
108 |
setText("Folder permissions"); |
|
109 |
|
|
110 |
// Outer contains inner and buttons |
|
111 |
VerticalPanel outer = new VerticalPanel(); |
|
112 |
outer.add(close); |
|
113 |
// Inner contains generalPanel and permPanel |
|
114 |
inner = new VerticalPanel(); |
|
115 |
inner.addStyleName("inner"); |
|
116 |
|
|
117 |
|
|
118 |
folderName.setText(folder.getName()); |
|
119 |
|
|
120 |
VerticalPanel permPanel = new VerticalPanel(); |
|
121 |
FilePermissionsDialog.Images images = GWT.create(FilePermissionsDialog.Images.class); |
|
122 |
boolean permsReadonly = folder.getInheritedPermissionsFrom() != null || folder.existChildrenPermissions(); |
|
123 |
permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), permsReadonly); |
|
124 |
permPanel.add(permList); |
|
125 |
|
|
126 |
if (!permsReadonly) { |
|
127 |
HorizontalPanel permButtons = new HorizontalPanel(); |
|
128 |
Button add = new Button("Add Group", new ClickHandler() { |
|
129 |
@Override |
|
130 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
131 |
PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); |
|
132 |
dlg.center(); |
|
133 |
} |
|
134 |
}); |
|
135 |
add.addStyleName("button"); |
|
136 |
permButtons.add(add); |
|
137 |
permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); |
|
138 |
|
|
139 |
Button addUser = new Button("Add User", new ClickHandler() { |
|
140 |
@Override |
|
141 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
142 |
PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); |
|
143 |
dlg.center(); |
|
144 |
} |
|
145 |
}); |
|
146 |
addUser.addStyleName("button"); |
|
147 |
permButtons.add(addUser); |
|
148 |
permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); |
|
149 |
permButtons.setSpacing(8); |
|
150 |
permPanel.add(permButtons); |
|
151 |
} |
|
152 |
|
|
153 |
inner.add(permPanel); |
|
154 |
|
|
155 |
outer.add(inner); |
|
156 |
|
|
157 |
// Create the 'Create/Update' button, along with a listener that hides the dialog |
|
158 |
// when the button is clicked and quits the application. |
|
159 |
String okLabel = "Update"; |
|
160 |
final Button ok = new Button(okLabel, new ClickHandler() { |
|
161 |
@Override |
|
162 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
163 |
updateFolder(); |
|
164 |
closeDialog(); |
|
165 |
} |
|
166 |
}); |
|
167 |
ok.addStyleName("button"); |
|
168 |
outer.add(ok); |
|
169 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
|
170 |
|
|
171 |
setWidget(outer); |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
|
176 |
super.onPreviewNativeEvent(preview); |
|
177 |
|
|
178 |
NativeEvent evt = preview.getNativeEvent(); |
|
179 |
if (evt.getType().equals(KeyDownEvent.getType().getName())) |
|
180 |
// Use the popup's key preview hooks to close the dialog when either |
|
181 |
// enter or escape is pressed. |
|
182 |
switch (evt.getKeyCode()) { |
|
183 |
case KeyCodes.KEY_ENTER: |
|
184 |
updateFolder(); |
|
185 |
closeDialog(); |
|
186 |
break; |
|
187 |
case KeyCodes.KEY_ESCAPE: |
|
188 |
closeDialog(); |
|
189 |
break; |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
/** |
|
195 |
* Enables IE selection prevention and hides the dialog |
|
196 |
* (we disable the prevention on creation of the dialog) |
|
197 |
*/ |
|
198 |
public void closeDialog() { |
|
199 |
Pithos.preventIESelection(); |
|
200 |
hide(); |
|
201 |
} |
|
202 |
|
|
203 |
void updateFolder() { |
|
204 |
final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null); |
|
205 |
final String newName = folderName.getText().trim(); |
|
206 |
if (!folder.isContainer() && !folder.getName().equals(newName)) { |
|
207 |
final String path = folder.getParent().getUri() + "/" + newName; |
|
208 |
PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getParent().getOwner(), path) { |
|
209 |
@Override |
|
210 |
public void onSuccess(@SuppressWarnings("unused") Resource result) { |
|
211 |
Iterator<File> iter = folder.getFiles().iterator(); |
|
212 |
app.copyFiles(iter, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() { |
|
213 |
@Override |
|
214 |
public void execute() { |
|
215 |
Iterator<Folder> iterf = folder.getSubfolders().iterator(); |
|
216 |
app.copySubfolders(iterf, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() { |
|
217 |
@Override |
|
218 |
public void execute() { |
|
219 |
app.deleteFolder(folder); |
|
220 |
updateMetadata(path + "?update=", perms); |
|
221 |
} |
|
222 |
}); |
|
223 |
} |
|
224 |
}); |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
public void onError(Throwable t) { |
|
229 |
GWT.log("", t); |
|
230 |
app.setError(t); |
|
231 |
if(t instanceof RestException){ |
|
232 |
app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText()); |
|
233 |
} |
|
234 |
else |
|
235 |
app.displayError("System error modifying folder: " + t.getMessage()); |
|
236 |
} |
|
237 |
|
|
238 |
@Override |
|
239 |
protected void onUnauthorized(@SuppressWarnings("unused") Response response) { |
|
240 |
app.sessionExpired(); |
|
241 |
} |
|
242 |
}; |
|
243 |
newFolder.setHeader("X-Auth-Token", app.getToken()); |
|
244 |
newFolder.setHeader("Content-Type", "application/folder"); |
|
245 |
newFolder.setHeader("Accept", "*/*"); |
|
246 |
newFolder.setHeader("Content-Length", "0"); |
|
247 |
Scheduler.get().scheduleDeferred(newFolder); |
|
248 |
} |
|
249 |
else |
|
250 |
updateMetadata(folder.getUri() + "?update=", perms); |
|
251 |
} |
|
252 |
|
|
253 |
protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) { |
|
254 |
if (newPermissions != null) { |
|
255 |
PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwner(), path) { |
|
256 |
@Override |
|
257 |
public void onSuccess(@SuppressWarnings("unused") Resource result) { |
|
258 |
app.updateFolder(folder.getParent(), false, new Command() { |
|
259 |
|
|
260 |
@Override |
|
261 |
public void execute() { |
|
262 |
app.updateMySharedRoot(); |
|
263 |
} |
|
264 |
}); |
|
265 |
} |
|
266 |
|
|
267 |
@Override |
|
268 |
public void onError(Throwable t) { |
|
269 |
GWT.log("", t); |
|
270 |
app.setError(t); |
|
271 |
if (t instanceof RestException) { |
|
272 |
if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder |
|
273 |
final String path1 = folder.getUri(); |
|
274 |
PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path1) { |
|
275 |
@Override |
|
276 |
public void onSuccess(@SuppressWarnings("unused") Resource result) { |
|
277 |
updateMetadata(path, newPermissions); |
|
278 |
} |
|
279 |
|
|
280 |
@Override |
|
281 |
public void onError(Throwable _t) { |
|
282 |
GWT.log("", _t); |
|
283 |
app.setError(_t); |
|
284 |
if(_t instanceof RestException){ |
|
285 |
app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText()); |
|
286 |
} |
|
287 |
else |
|
288 |
app.displayError("System error modifying folder: " + _t.getMessage()); |
|
289 |
} |
|
290 |
|
|
291 |
@Override |
|
292 |
protected void onUnauthorized(@SuppressWarnings("unused") Response response) { |
|
293 |
app.sessionExpired(); |
|
294 |
} |
|
295 |
}; |
|
296 |
newFolder.setHeader("X-Auth-Token", app.getToken()); |
|
297 |
newFolder.setHeader("Content-Type", "application/folder"); |
|
298 |
newFolder.setHeader("Accept", "*/*"); |
|
299 |
newFolder.setHeader("Content-Length", "0"); |
|
300 |
Scheduler.get().scheduleDeferred(newFolder); |
|
301 |
} |
|
302 |
else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) { |
|
303 |
app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set"); |
|
304 |
} |
|
305 |
else |
|
306 |
app.displayError("Wrror modifying folder: " + t.getMessage()); |
|
307 |
} |
|
308 |
else |
|
309 |
app.displayError("System error modifying folder: " + t.getMessage()); |
|
310 |
} |
|
311 |
|
|
312 |
@Override |
|
313 |
protected void onUnauthorized(@SuppressWarnings("unused") Response response) { |
|
314 |
app.sessionExpired(); |
|
315 |
} |
|
316 |
}; |
|
317 |
updateFolder.setHeader("X-Auth-Token", app.getToken()); |
|
318 |
String readPermHeader = "read="; |
|
319 |
String writePermHeader = "write="; |
|
320 |
for (String u : newPermissions.keySet()) { |
|
321 |
Boolean[] p = newPermissions.get(u); |
|
322 |
if (p[0] != null && p[0]) |
|
323 |
readPermHeader += u + ","; |
|
324 |
if (p[1] != null && p[1]) |
|
325 |
writePermHeader += u + ","; |
|
326 |
} |
|
327 |
if (readPermHeader.endsWith("=")) |
|
328 |
readPermHeader = ""; |
|
329 |
else if (readPermHeader.endsWith(",")) |
|
330 |
readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1); |
|
331 |
if (writePermHeader.endsWith("=")) |
|
332 |
writePermHeader = ""; |
|
333 |
else if (writePermHeader.endsWith(",")) |
|
334 |
writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1); |
|
335 |
String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader; |
|
336 |
if (permHeader.length() == 0) |
|
337 |
permHeader = "~"; |
|
338 |
else |
|
339 |
permHeader = URL.encodePathSegment(permHeader); |
|
340 |
updateFolder.setHeader("X-Object-Sharing", permHeader); |
|
341 |
Scheduler.get().scheduleDeferred(updateFolder); |
|
342 |
} |
|
343 |
else |
|
344 |
app.updateFolder(folder.getParent(), false, new Command() { |
|
345 |
|
|
346 |
@Override |
|
347 |
public void execute() { |
|
348 |
app.updateMySharedRoot(); |
|
349 |
} |
|
350 |
}); |
|
351 |
} |
|
352 |
} |
b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.core.client.Scheduler; |
|
38 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
|
39 |
import com.google.gwt.user.client.Command; |
|
40 | 37 |
import gr.grnet.pithos.web.client.foldertree.File; |
41 | 38 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
42 | 39 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
43 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
|
44 | 40 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
45 | 41 |
import gr.grnet.pithos.web.client.rest.RestException; |
46 | 42 |
|
43 |
import java.util.Iterator; |
|
44 |
|
|
47 | 45 |
import com.google.gwt.core.client.GWT; |
46 |
import com.google.gwt.core.client.Scheduler; |
|
48 | 47 |
import com.google.gwt.dom.client.NativeEvent; |
49 | 48 |
import com.google.gwt.event.dom.client.ChangeEvent; |
50 | 49 |
import com.google.gwt.event.dom.client.ChangeHandler; |
51 | 50 |
import com.google.gwt.event.dom.client.ClickEvent; |
52 | 51 |
import com.google.gwt.event.dom.client.ClickHandler; |
53 | 52 |
import com.google.gwt.event.dom.client.KeyCodes; |
53 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
|
54 | 54 |
import com.google.gwt.http.client.Response; |
55 |
import com.google.gwt.http.client.URL; |
|
56 | 55 |
import com.google.gwt.i18n.client.DateTimeFormat; |
56 |
import com.google.gwt.user.client.Command; |
|
57 | 57 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
58 | 58 |
import com.google.gwt.user.client.ui.Anchor; |
59 | 59 |
import com.google.gwt.user.client.ui.Button; |
60 |
import com.google.gwt.user.client.ui.DecoratedTabPanel; |
|
61 | 60 |
import com.google.gwt.user.client.ui.DialogBox; |
62 | 61 |
import com.google.gwt.user.client.ui.FlexTable; |
63 | 62 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
64 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
|
65 | 63 |
import com.google.gwt.user.client.ui.Label; |
66 |
import com.google.gwt.user.client.ui.TabPanel; |
|
67 | 64 |
import com.google.gwt.user.client.ui.TextBox; |
68 | 65 |
import com.google.gwt.user.client.ui.VerticalPanel; |
69 |
import java.util.Iterator; |
|
70 |
import java.util.Map; |
|
71 | 66 |
|
72 | 67 |
/** |
73 | 68 |
* The 'Folder properties' dialog box implementation. |
... | ... | |
87 | 82 |
*/ |
88 | 83 |
private final boolean create; |
89 | 84 |
|
90 |
protected PermissionsList permList; |
|
91 |
|
|
92 | 85 |
final Folder folder; |
93 | 86 |
|
94 |
final TabPanel inner;
|
|
87 |
final VerticalPanel inner;
|
|
95 | 88 |
|
96 | 89 |
/** |
97 | 90 |
* The widget's constructor. |
... | ... | |
103 | 96 |
close.addClickHandler(new ClickHandler() { |
104 | 97 |
|
105 | 98 |
@Override |
106 |
public void onClick(ClickEvent event) { |
|
99 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) {
|
|
107 | 100 |
hide(); |
108 | 101 |
} |
109 | 102 |
}); |
... | ... | |
129 | 122 |
VerticalPanel outer = new VerticalPanel(); |
130 | 123 |
outer.add(close); |
131 | 124 |
// Inner contains generalPanel and permPanel |
132 |
inner = new DecoratedTabPanel(); |
|
133 |
inner.setAnimationEnabled(true); |
|
125 |
inner = new VerticalPanel(); |
|
134 | 126 |
inner.addStyleName("inner"); |
135 |
inner.getDeckPanel().addStyleName("pithos-TabPanelBottom"); |
|
136 | 127 |
|
137 | 128 |
VerticalPanel generalPanel = new VerticalPanel(); |
138 | 129 |
FlexTable generalTable = new FlexTable(); |
... | ... | |
168 | 159 |
generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); |
169 | 160 |
generalTable.setCellSpacing(4); |
170 | 161 |
generalPanel.add(generalTable); |
171 |
inner.add(generalPanel, "General"); |
|
172 |
|
|
173 |
VerticalPanel permPanel = new VerticalPanel(); |
|
174 |
FilePermissionsDialog.Images images = GWT.create(FilePermissionsDialog.Images.class); |
|
175 |
boolean permsReadonly = folder.getInheritedPermissionsFrom() != null || folder.existChildrenPermissions(); |
|
176 |
permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), permsReadonly); |
|
177 |
permPanel.add(permList); |
|
178 |
|
|
179 |
if (!permsReadonly) { |
|
180 |
HorizontalPanel permButtons = new HorizontalPanel(); |
|
181 |
Button add = new Button("Add Group", new ClickHandler() { |
|
182 |
@Override |
|
183 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
184 |
PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); |
|
185 |
dlg.center(); |
|
186 |
} |
|
187 |
}); |
|
188 |
add.addStyleName("button"); |
|
189 |
permButtons.add(add); |
|
190 |
permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); |
|
191 |
|
|
192 |
Button addUser = new Button("Add User", new ClickHandler() { |
|
193 |
@Override |
|
194 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
|
195 |
PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); |
|
196 |
dlg.center(); |
|
197 |
} |
|
198 |
}); |
|
199 |
addUser.addStyleName("button"); |
|
200 |
permButtons.add(addUser); |
|
201 |
permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); |
|
202 |
permButtons.setSpacing(8); |
|
203 |
permPanel.add(permButtons); |
|
204 |
} |
|
205 |
|
|
206 |
if (!create) |
|
207 |
inner.add(permPanel, "Sharing"); |
|
208 |
inner.selectTab(0); |
|
162 |
inner.add(generalPanel); |
|
209 | 163 |
|
210 | 164 |
outer.add(inner); |
211 | 165 |
|
... | ... | |
310 | 264 |
} |
311 | 265 |
|
312 | 266 |
@Override |
313 |
protected void onUnauthorized(Response response) { |
|
267 |
protected void onUnauthorized(@SuppressWarnings("unused") Response response) {
|
|
314 | 268 |
app.sessionExpired(); |
315 | 269 |
} |
316 | 270 |
}; |
... | ... | |
335 | 289 |
} |
336 | 290 |
|
337 | 291 |
private void updateFolder() { |
338 |
final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null); |
|
339 | 292 |
final String newName = folderName.getText().trim(); |
340 | 293 |
if (!folder.isContainer() && !folder.getName().equals(newName)) { |
341 | 294 |
final String path = folder.getParent().getUri() + "/" + newName; |
... | ... | |
351 | 304 |
@Override |
352 | 305 |
public void execute() { |
353 | 306 |
app.deleteFolder(folder); |
354 |
updateMetadata(path + "?update=", perms); |
|
307 |
app.updateFolder(folder.getParent(), false, new Command() { |
|
308 |
|
|
309 |
@Override |
|
310 |
public void execute() { |
|
311 |
app.updateMySharedRoot(); |
|
312 |
} |
|
313 |
}); |
|
355 | 314 |
} |
356 | 315 |
}); |
357 | 316 |
} |
... | ... | |
370 | 329 |
} |
371 | 330 |
|
372 | 331 |
@Override |
373 |
protected void onUnauthorized(Response response) { |
|
332 |
protected void onUnauthorized(@SuppressWarnings("unused") Response response) {
|
|
374 | 333 |
app.sessionExpired(); |
375 | 334 |
} |
376 | 335 |
}; |
... | ... | |
381 | 340 |
Scheduler.get().scheduleDeferred(newFolder); |
382 | 341 |
} |
383 | 342 |
else |
384 |
updateMetadata(folder.getUri() + "?update=", perms); |
|
385 |
} |
|
386 |
|
|
387 |
protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) { |
|
388 |
if (newPermissions != null) { |
|
389 |
PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwner(), path) { |
|
390 |
@Override |
|
391 |
public void onSuccess(@SuppressWarnings("unused") Resource result) { |
|
392 |
app.updateFolder(folder.getParent(), false, new Command() { |
|
393 |
|
|
394 |
@Override |
|
395 |
public void execute() { |
|
396 |
app.updateMySharedRoot(); |
|
397 |
} |
|
398 |
}); |
|
399 |
} |
|
400 |
|
|
401 |
@Override |
|
402 |
public void onError(Throwable t) { |
|
403 |
GWT.log("", t); |
|
404 |
app.setError(t); |
|
405 |
if (t instanceof RestException) { |
|
406 |
if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder |
|
407 |
final String path1 = folder.getUri(); |
|
408 |
PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path1) { |
|
409 |
@Override |
|
410 |
public void onSuccess(@SuppressWarnings("unused") Resource result) { |
|
411 |
updateMetadata(path, newPermissions); |
|
412 |
} |
|
413 |
|
|
414 |
@Override |
|
415 |
public void onError(Throwable _t) { |
|
416 |
GWT.log("", _t); |
|
417 |
app.setError(_t); |
|
418 |
if(_t instanceof RestException){ |
|
419 |
app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText()); |
|
420 |
} |
|
421 |
else |
|
422 |
app.displayError("System error modifying folder: " + _t.getMessage()); |
|
423 |
} |
|
424 |
|
|
425 |
@Override |
|
426 |
protected void onUnauthorized(Response response) { |
|
427 |
app.sessionExpired(); |
|
428 |
} |
|
429 |
}; |
|
430 |
newFolder.setHeader("X-Auth-Token", app.getToken()); |
|
431 |
newFolder.setHeader("Content-Type", "application/folder"); |
|
432 |
newFolder.setHeader("Accept", "*/*"); |
|
433 |
newFolder.setHeader("Content-Length", "0"); |
|
434 |
Scheduler.get().scheduleDeferred(newFolder); |
|
435 |
} |
|
436 |
else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) { |
|
437 |
app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set"); |
|
438 |
} |
|
439 |
else |
|
440 |
app.displayError("Wrror modifying folder: " + t.getMessage()); |
|
441 |
} |
|
442 |
else |
|
443 |
app.displayError("System error modifying folder: " + t.getMessage()); |
|
444 |
} |
|
445 |
|
|
446 |
@Override |
|
447 |
protected void onUnauthorized(Response response) { |
|
448 |
app.sessionExpired(); |
|
449 |
} |
|
450 |
}; |
|
451 |
updateFolder.setHeader("X-Auth-Token", app.getToken()); |
|
452 |
String readPermHeader = "read="; |
|
453 |
String writePermHeader = "write="; |
|
454 |
for (String u : newPermissions.keySet()) { |
|
455 |
Boolean[] p = newPermissions.get(u); |
|
456 |
if (p[0] != null && p[0]) |
|
457 |
readPermHeader += u + ","; |
|
458 |
if (p[1] != null && p[1]) |
|
459 |
writePermHeader += u + ","; |
|
460 |
} |
|
461 |
if (readPermHeader.endsWith("=")) |
|
462 |
readPermHeader = ""; |
|
463 |
else if (readPermHeader.endsWith(",")) |
|
464 |
readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1); |
|
465 |
if (writePermHeader.endsWith("=")) |
|
466 |
writePermHeader = ""; |
|
467 |
else if (writePermHeader.endsWith(",")) |
|
468 |
writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1); |
|
469 |
String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader; |
|
470 |
if (permHeader.length() == 0) |
|
471 |
permHeader = "~"; |
|
472 |
else |
|
473 |
permHeader = URL.encodePathSegment(permHeader); |
|
474 |
updateFolder.setHeader("X-Object-Sharing", permHeader); |
|
475 |
Scheduler.get().scheduleDeferred(updateFolder); |
|
476 |
} |
|
477 |
else |
|
478 | 343 |
app.updateFolder(folder.getParent(), false, new Command() { |
479 |
|
|
480 |
@Override |
|
481 |
public void execute() { |
|
482 |
app.updateMySharedRoot(); |
|
483 |
} |
|
484 |
}); |
|
485 |
} |
|
486 |
|
|
487 |
public void selectTab(int _tab) { |
|
488 |
inner.selectTab(_tab); |
|
344 |
|
|
345 |
@Override |
|
346 |
public void execute() { |
|
347 |
app.updateMySharedRoot(); |
|
348 |
} |
|
349 |
}); |
|
489 | 350 |
} |
490 | 351 |
} |
b/src/gr/grnet/pithos/web/client/ToolsMenu.java | ||
---|---|---|
173 | 173 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.group()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PERMISSIONS))); |
174 | 174 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.VERSIONS))); |
175 | 175 |
} |
176 |
else if (!folder.isContainer()) |
|
177 |
contextMenu.addItem(new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Folder properties</span>", true, new PropertiesCommand(app, this, folder, 0))); |
|
176 |
else if (!folder.isContainer()) { |
|
177 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Folder properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES))); |
|
178 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Folder sharing</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS))); |
|
179 |
} |
|
178 | 180 |
} |
179 | 181 |
if (files != null && !files.isEmpty()) { |
180 | 182 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() { |
b/src/gr/grnet/pithos/web/client/commands/PropertiesCommand.java | ||
---|---|---|
38 | 38 |
import gr.grnet.pithos.web.client.FilePropertiesDialog; |
39 | 39 |
import gr.grnet.pithos.web.client.FileVersionsDialog; |
40 | 40 |
import gr.grnet.pithos.web.client.FilesPropertiesDialog; |
41 |
import gr.grnet.pithos.web.client.FolderPermissionsDialog; |
|
41 | 42 |
import gr.grnet.pithos.web.client.FolderPropertiesDialog; |
42 | 43 |
import gr.grnet.pithos.web.client.Pithos; |
43 | 44 |
import gr.grnet.pithos.web.client.foldertree.File; |
... | ... | |
85 | 86 |
|
86 | 87 |
if (resource instanceof Folder) { |
87 | 88 |
Folder folder = (Folder) resource; |
88 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder); |
|
89 |
dlg.selectTab(tabToShow); |
|
90 |
dlg.center(); |
|
89 |
switch (tabToShow) { |
|
90 |
case PROPERTIES: |
|
91 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(app, false, folder); |
|
92 |
dlg.center(); |
|
93 |
break; |
|
94 |
case PERMISSIONS: |
|
95 |
FolderPermissionsDialog dlg1 = new FolderPermissionsDialog(app, folder); |
|
96 |
dlg1.center(); |
|
97 |
break; |
|
98 |
default: |
|
99 |
break; |
|
100 |
} |
|
91 | 101 |
} |
92 | 102 |
else if (resource instanceof List) { |
93 | 103 |
@SuppressWarnings("unchecked") |
Also available in: Unified diff