root / src / gr / ebs / gss / client / FolderPropertiesDialog.java @ 783db80b
History | View | Annotate | Download (16.1 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | c62f0b96 | Natasa Kapravelou | * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client; |
20 | 14ad7326 | pastith | |
21 | 14ad7326 | pastith | import gr.ebs.gss.client.FilePropertiesDialog.Images; |
22 | a52ea5e4 | pastith | import gr.ebs.gss.client.dnd.DnDTreeItem; |
23 | 895035a2 | pastith | import gr.ebs.gss.client.rest.PostCommand; |
24 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.RestException; |
25 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FolderResource; |
26 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.GroupResource; |
27 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.PermissionHolder; |
28 | 14ad7326 | pastith | |
29 | 14ad7326 | pastith | import java.util.List; |
30 | 14ad7326 | pastith | import java.util.Set; |
31 | 14ad7326 | pastith | |
32 | 14ad7326 | pastith | import com.google.gwt.core.client.GWT; |
33 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.dom.client.NativeEvent; |
34 | 78729465 | Natasa Kapravelou | import com.google.gwt.event.dom.client.ChangeEvent; |
35 | 78729465 | Natasa Kapravelou | import com.google.gwt.event.dom.client.ChangeHandler; |
36 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickEvent; |
37 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickHandler; |
38 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.KeyCodes; |
39 | eba21118 | Natasa Kapravelou | import com.google.gwt.event.dom.client.KeyDownEvent; |
40 | eba21118 | Natasa Kapravelou | import com.google.gwt.event.dom.client.KeyDownHandler; |
41 | 82d67942 | droutsis | import com.google.gwt.http.client.URL; |
42 | 14ad7326 | pastith | import com.google.gwt.i18n.client.DateTimeFormat; |
43 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONArray; |
44 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONBoolean; |
45 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONObject; |
46 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONString; |
47 | a52ea5e4 | pastith | import com.google.gwt.user.client.DeferredCommand; |
48 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.user.client.Event.NativePreviewEvent; |
49 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Button; |
50 | 9e6a28ed | Natasa Kapravelou | import com.google.gwt.user.client.ui.CheckBox; |
51 | 5c6b2883 | Panagiotis Astithas | import com.google.gwt.user.client.ui.DecoratedTabPanel; |
52 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.DialogBox; |
53 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.FlexTable; |
54 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
55 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HorizontalPanel; |
56 | 9e6a28ed | Natasa Kapravelou | import com.google.gwt.user.client.ui.Label; |
57 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TabPanel; |
58 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TextBox; |
59 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.VerticalPanel; |
60 | 14ad7326 | pastith | |
61 | 14ad7326 | pastith | /**
|
62 | 14ad7326 | pastith | * The 'Folder properties' dialog box implementation.
|
63 | 14ad7326 | pastith | */
|
64 | 14ad7326 | pastith | public class FolderPropertiesDialog extends DialogBox { |
65 | 14ad7326 | pastith | |
66 | a52ea5e4 | pastith | private List<GroupResource> groups = null; |
67 | 14ad7326 | pastith | |
68 | 14ad7326 | pastith | final PermissionsList permList;
|
69 | 14ad7326 | pastith | |
70 | 9e6a28ed | Natasa Kapravelou | private CheckBox readForAll;
|
71 | 9e6a28ed | Natasa Kapravelou | |
72 | 14ad7326 | pastith | /**
|
73 | 14ad7326 | pastith | * The widget that holds the folderName of the folder.
|
74 | 14ad7326 | pastith | */
|
75 | 14ad7326 | pastith | private TextBox folderName = new TextBox(); |
76 | 14ad7326 | pastith | |
77 | 14ad7326 | pastith | /**
|
78 | 14ad7326 | pastith | * A flag that denotes whether the dialog will be used to create or modify a
|
79 | 14ad7326 | pastith | * folder.
|
80 | 14ad7326 | pastith | */
|
81 | 14ad7326 | pastith | private final boolean create; |
82 | 14ad7326 | pastith | |
83 | a52ea5e4 | pastith | final FolderResource folder;
|
84 | 892a2836 | fstamatelopoulos | |
85 | 892a2836 | fstamatelopoulos | final TabPanel inner;
|
86 | 892a2836 | fstamatelopoulos | |
87 | 14ad7326 | pastith | /**
|
88 | 14ad7326 | pastith | * The widget's constructor.
|
89 | 14ad7326 | pastith | *
|
90 | 14ad7326 | pastith | * @param images the image icons from the file properties dialog
|
91 | 14ad7326 | pastith | * @param _create true if the dialog is displayed for creating a new
|
92 | 14ad7326 | pastith | * sub-folder of the selected folder, false if it is displayed
|
93 | 14ad7326 | pastith | * for modifying the selected folder
|
94 | 14ad7326 | pastith | */
|
95 | 41d05cc8 | pastith | public FolderPropertiesDialog(Images images, boolean _create, final List<GroupResource> _groups) { |
96 | 14ad7326 | pastith | setAnimationEnabled(true);
|
97 | 14ad7326 | pastith | |
98 | f46a13ff | fstamatelopoulos | // Enable IE selection for the dialog (must disable it upon closing it)
|
99 | f46a13ff | fstamatelopoulos | GSS.enableIESelection(); |
100 | f46a13ff | fstamatelopoulos | |
101 | 14ad7326 | pastith | create = _create; |
102 | 5f19c494 | koutsoub | DnDTreeItem folderItem = (DnDTreeItem)GSS.get().getFolders().getCurrent(); |
103 | 5f19c494 | koutsoub | folder = folderItem.getFolderResource(); |
104 | a52ea5e4 | pastith | permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner());
|
105 | 41d05cc8 | pastith | groups = _groups; |
106 | 29bbf2d3 | Fotis Stamatelopoulos | |
107 | 14ad7326 | pastith | // Use this opportunity to set the dialog's caption.
|
108 | 14ad7326 | pastith | if (create)
|
109 | 14ad7326 | pastith | setText("Create folder");
|
110 | 14ad7326 | pastith | else
|
111 | 14ad7326 | pastith | setText("Folder properties");
|
112 | 14ad7326 | pastith | |
113 | 14ad7326 | pastith | // Outer contains inner and buttons
|
114 | 41d05cc8 | pastith | VerticalPanel outer = new VerticalPanel();
|
115 | 14ad7326 | pastith | // Inner contains generalPanel and permPanel
|
116 | 5c6b2883 | Panagiotis Astithas | inner = new DecoratedTabPanel();
|
117 | 5c6b2883 | Panagiotis Astithas | inner.setAnimationEnabled(true);
|
118 | 41d05cc8 | pastith | VerticalPanel generalPanel = new VerticalPanel();
|
119 | 41d05cc8 | pastith | VerticalPanel permPanel = new VerticalPanel();
|
120 | 9e6a28ed | Natasa Kapravelou | final HorizontalPanel permForAll = new HorizontalPanel(); |
121 | 9e6a28ed | Natasa Kapravelou | final HorizontalPanel pathPanel = new HorizontalPanel(); |
122 | 41d05cc8 | pastith | HorizontalPanel buttons = new HorizontalPanel();
|
123 | 41d05cc8 | pastith | HorizontalPanel permButtons = new HorizontalPanel();
|
124 | 9e6a28ed | Natasa Kapravelou | |
125 | 14ad7326 | pastith | inner.add(generalPanel, "General");
|
126 | 14ad7326 | pastith | if (!create)
|
127 | 892a2836 | fstamatelopoulos | inner.add(permPanel, "Sharing");
|
128 | 14ad7326 | pastith | inner.selectTab(0);
|
129 | 14ad7326 | pastith | |
130 | 8b79a1c8 | Natasa Kapravelou | final Label folderNameNote = new Label("Please note that slashes ('/') are not allowed in folder names.", true); |
131 | eba21118 | Natasa Kapravelou | folderNameNote.setVisible(false);
|
132 | eba21118 | Natasa Kapravelou | folderNameNote.setStylePrimaryName("gss-readForAllNote");
|
133 | eba21118 | Natasa Kapravelou | |
134 | 41d05cc8 | pastith | FlexTable generalTable = new FlexTable();
|
135 | 14ad7326 | pastith | generalTable.setText(0, 0, "Name"); |
136 | 14ad7326 | pastith | generalTable.setText(1, 0, "Parent"); |
137 | 14ad7326 | pastith | generalTable.setText(2, 0, "Creator"); |
138 | e164b7ca | Panagiotis Astithas | generalTable.setText(3, 0, "Last modified"); |
139 | 14ad7326 | pastith | folderName.setText(create ? "" : folder.getName());
|
140 | 14ad7326 | pastith | generalTable.setWidget(0, 1, folderName); |
141 | 78729465 | Natasa Kapravelou | folderName.addChangeHandler(new ChangeHandler() {
|
142 | 78729465 | Natasa Kapravelou | |
143 | eba21118 | Natasa Kapravelou | @Override
|
144 | 78729465 | Natasa Kapravelou | public void onChange(ChangeEvent event) { |
145 | 78729465 | Natasa Kapravelou | if(folderName.getText().contains("/")) |
146 | 78729465 | Natasa Kapravelou | folderNameNote.setVisible(true);
|
147 | 78729465 | Natasa Kapravelou | else
|
148 | 78729465 | Natasa Kapravelou | folderNameNote.setVisible(false);
|
149 | 78729465 | Natasa Kapravelou | |
150 | eba21118 | Natasa Kapravelou | } |
151 | eba21118 | Natasa Kapravelou | }); |
152 | eba21118 | Natasa Kapravelou | |
153 | 78729465 | Natasa Kapravelou | |
154 | 8b79a1c8 | Natasa Kapravelou | if (create)
|
155 | 14ad7326 | pastith | generalTable.setText(1, 1, folder.getName()); |
156 | d6ba3052 | koutsoub | else if(folder.getParentName() == null) |
157 | 5f19c494 | koutsoub | generalTable.setText(1, 1, "-"); |
158 | a5296182 | koutsoub | else
|
159 | d6ba3052 | koutsoub | generalTable.setText(1, 1, folder.getParentName()); |
160 | 8b79a1c8 | Natasa Kapravelou | generalTable.setWidget(0, 2, folderNameNote); |
161 | a52ea5e4 | pastith | generalTable.setText(2, 1, folder.getOwner()); |
162 | 41d05cc8 | pastith | DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
|
163 | e164b7ca | Panagiotis Astithas | if(folder.getModificationDate() != null) |
164 | e164b7ca | Panagiotis Astithas | generalTable.setText(3, 1, formatter.format(folder.getModificationDate())); |
165 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
166 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
167 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); |
168 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); |
169 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
170 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
171 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); |
172 | 14ad7326 | pastith | generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); |
173 | 14ad7326 | pastith | generalTable.setCellSpacing(4);
|
174 | 14ad7326 | pastith | |
175 | c8239751 | Fotis Stamatelopoulos | // Create the 'Create/Update' button, along with a listener that hides the dialog
|
176 | 14ad7326 | pastith | // when the button is clicked and quits the application.
|
177 | c8239751 | Fotis Stamatelopoulos | String okLabel;
|
178 | c8239751 | Fotis Stamatelopoulos | if (create)
|
179 | c8239751 | Fotis Stamatelopoulos | okLabel = "Create";
|
180 | c8239751 | Fotis Stamatelopoulos | else
|
181 | c8239751 | Fotis Stamatelopoulos | okLabel = "Update";
|
182 | afd3a0ef | Giannis Koutsoubos | Button ok = new Button(okLabel, new ClickHandler() { |
183 | afd3a0ef | Giannis Koutsoubos | @Override
|
184 | 78729465 | Natasa Kapravelou | public void onClick(ClickEvent event) { |
185 | 78729465 | Natasa Kapravelou | if(folderName.getText().contains("/")) |
186 | 78729465 | Natasa Kapravelou | folderNameNote.setVisible(true);
|
187 | 78729465 | Natasa Kapravelou | else {
|
188 | 78729465 | Natasa Kapravelou | folderNameNote.setVisible(false);
|
189 | 78729465 | Natasa Kapravelou | createOrUpdateFolder(); |
190 | 78729465 | Natasa Kapravelou | closeDialog(); |
191 | 78729465 | Natasa Kapravelou | } |
192 | 14ad7326 | pastith | |
193 | 14ad7326 | pastith | } |
194 | 78729465 | Natasa Kapravelou | }); |
195 | 14ad7326 | pastith | buttons.add(ok); |
196 | 14ad7326 | pastith | buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
197 | 14ad7326 | pastith | // Create the 'Cancel' button, along with a listener that hides the
|
198 | 14ad7326 | pastith | // dialog
|
199 | 14ad7326 | pastith | // when the button is clicked.
|
200 | afd3a0ef | Giannis Koutsoubos | Button cancel = new Button("Cancel", new ClickHandler() { |
201 | afd3a0ef | Giannis Koutsoubos | @Override
|
202 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
203 | f46a13ff | fstamatelopoulos | closeDialog(); |
204 | 14ad7326 | pastith | } |
205 | 14ad7326 | pastith | }); |
206 | 14ad7326 | pastith | buttons.add(cancel); |
207 | 14ad7326 | pastith | buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
208 | 14ad7326 | pastith | buttons.setSpacing(8);
|
209 | 5c6b2883 | Panagiotis Astithas | buttons.addStyleName("gss-TabPanelBottom");
|
210 | 14ad7326 | pastith | |
211 | afd3a0ef | Giannis Koutsoubos | Button add = new Button("Add Group", new ClickHandler() { |
212 | afd3a0ef | Giannis Koutsoubos | @Override
|
213 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
214 | 41d05cc8 | pastith | PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false); |
215 | 14ad7326 | pastith | dlg.center(); |
216 | 14ad7326 | pastith | } |
217 | 14ad7326 | pastith | }); |
218 | 14ad7326 | pastith | permButtons.add(add); |
219 | 14ad7326 | pastith | permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); |
220 | 14ad7326 | pastith | |
221 | afd3a0ef | Giannis Koutsoubos | Button addUser = new Button("Add User", new ClickHandler() { |
222 | afd3a0ef | Giannis Koutsoubos | @Override
|
223 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
224 | 41d05cc8 | pastith | PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true); |
225 | 14ad7326 | pastith | dlg.center(); |
226 | 14ad7326 | pastith | } |
227 | 14ad7326 | pastith | }); |
228 | 14ad7326 | pastith | permButtons.add(addUser); |
229 | 14ad7326 | pastith | permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); |
230 | 14ad7326 | pastith | |
231 | 14ad7326 | pastith | permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
232 | 14ad7326 | pastith | permButtons.setSpacing(8);
|
233 | 5c6b2883 | Panagiotis Astithas | permButtons.addStyleName("gss-TabPanelBottom");
|
234 | 14ad7326 | pastith | |
235 | 3ef43fed | Panagiotis Astithas | final Label readForAllNote = new Label("When this option is enabled, the folder will be readable" + |
236 | 9e6a28ed | Natasa Kapravelou | " by everyone. By checking this option, you are certifying that you have the right to " +
|
237 | 3ef43fed | Panagiotis Astithas | "distribute this folder's contents and that it does not violate the Terms of Use.", true); |
238 | 9e6a28ed | Natasa Kapravelou | readForAllNote.setVisible(false);
|
239 | 9e6a28ed | Natasa Kapravelou | readForAllNote.setStylePrimaryName("gss-readForAllNote");
|
240 | 9e6a28ed | Natasa Kapravelou | |
241 | 9e6a28ed | Natasa Kapravelou | readForAll = new CheckBox();
|
242 | 9e6a28ed | Natasa Kapravelou | readForAll.setValue(folder.isReadForAll()); |
243 | 9e6a28ed | Natasa Kapravelou | readForAll.addClickHandler(new ClickHandler() {
|
244 | 9e6a28ed | Natasa Kapravelou | @Override
|
245 | 9e6a28ed | Natasa Kapravelou | public void onClick(ClickEvent event) { |
246 | 9e6a28ed | Natasa Kapravelou | readForAllNote.setVisible(readForAll.getValue()); |
247 | 9e6a28ed | Natasa Kapravelou | } |
248 | 9e6a28ed | Natasa Kapravelou | |
249 | 9e6a28ed | Natasa Kapravelou | }); |
250 | 9e6a28ed | Natasa Kapravelou | |
251 | 14ad7326 | pastith | generalPanel.add(generalTable); |
252 | 14ad7326 | pastith | permPanel.add(permList); |
253 | 14ad7326 | pastith | permPanel.add(permButtons); |
254 | 9e6a28ed | Natasa Kapravelou | |
255 | 9e6a28ed | Natasa Kapravelou | // Only show the read for all permission if the user is the owner.
|
256 | 9e6a28ed | Natasa Kapravelou | if (folder.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {
|
257 | 9e6a28ed | Natasa Kapravelou | permForAll.add(new Label("Public")); |
258 | 9e6a28ed | Natasa Kapravelou | permForAll.add(readForAll); |
259 | 9e6a28ed | Natasa Kapravelou | permForAll.setSpacing(8);
|
260 | 9e6a28ed | Natasa Kapravelou | permForAll.addStyleName("gss-TabPanelBottom");
|
261 | 9e6a28ed | Natasa Kapravelou | permForAll.add(readForAllNote); |
262 | 9e6a28ed | Natasa Kapravelou | permPanel.add(permForAll); |
263 | 9e6a28ed | Natasa Kapravelou | } |
264 | 9e6a28ed | Natasa Kapravelou | TextBox path = new TextBox();
|
265 | 9e6a28ed | Natasa Kapravelou | path.setWidth("100%");
|
266 | 9e6a28ed | Natasa Kapravelou | path.addClickHandler(new ClickHandler() {
|
267 | 9e6a28ed | Natasa Kapravelou | @Override
|
268 | 9e6a28ed | Natasa Kapravelou | public void onClick(ClickEvent event) { |
269 | 9e6a28ed | Natasa Kapravelou | GSS.enableIESelection(); |
270 | 9e6a28ed | Natasa Kapravelou | ((TextBox) event.getSource()).selectAll(); |
271 | 9e6a28ed | Natasa Kapravelou | GSS.preventIESelection(); |
272 | 9e6a28ed | Natasa Kapravelou | } |
273 | 9e6a28ed | Natasa Kapravelou | |
274 | 9e6a28ed | Natasa Kapravelou | }); |
275 | 9e6a28ed | Natasa Kapravelou | path.setText(folder.getUri()); |
276 | 3ef43fed | Panagiotis Astithas | path.setTitle("Use this link for sharing the folder via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
|
277 | 9e6a28ed | Natasa Kapravelou | path.setWidth("100%");
|
278 | 9e6a28ed | Natasa Kapravelou | path.setReadOnly(true);
|
279 | 9e6a28ed | Natasa Kapravelou | pathPanel.setWidth("100%");
|
280 | 9e6a28ed | Natasa Kapravelou | pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
281 | 9e6a28ed | Natasa Kapravelou | pathPanel.add(new Label("Link")); |
282 | 9e6a28ed | Natasa Kapravelou | pathPanel.setSpacing(8);
|
283 | 9e6a28ed | Natasa Kapravelou | pathPanel.addStyleName("gss-TabPanelBottom");
|
284 | 9e6a28ed | Natasa Kapravelou | pathPanel.add(path); |
285 | 9e6a28ed | Natasa Kapravelou | permPanel.add(pathPanel); |
286 | 9e6a28ed | Natasa Kapravelou | |
287 | 14ad7326 | pastith | outer.add(inner); |
288 | 14ad7326 | pastith | outer.add(buttons); |
289 | 14ad7326 | pastith | outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
290 | 5c6b2883 | Panagiotis Astithas | outer.addStyleName("gss-TabPanelBottom");
|
291 | 14ad7326 | pastith | |
292 | 14ad7326 | pastith | setWidget(outer); |
293 | 14ad7326 | pastith | |
294 | f46a13ff | fstamatelopoulos | /*if (create)
|
295 | f46a13ff | fstamatelopoulos | folderName.setFocus(true);
|
296 | f46a13ff | fstamatelopoulos | else
|
297 | f46a13ff | fstamatelopoulos | ok.setFocus(true);*/
|
298 | 14ad7326 | pastith | } |
299 | 14ad7326 | pastith | |
300 | 41d05cc8 | pastith | @Override
|
301 | 14ad7326 | pastith | public void center() { |
302 | 14ad7326 | pastith | super.center();
|
303 | 14ad7326 | pastith | folderName.setFocus(true);
|
304 | 14ad7326 | pastith | } |
305 | 14ad7326 | pastith | |
306 | 41d05cc8 | pastith | @Override
|
307 | afd3a0ef | Giannis Koutsoubos | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
308 | afd3a0ef | Giannis Koutsoubos | super.onPreviewNativeEvent(preview);
|
309 | afd3a0ef | Giannis Koutsoubos | |
310 | afd3a0ef | Giannis Koutsoubos | NativeEvent evt = preview.getNativeEvent(); |
311 | afd3a0ef | Giannis Koutsoubos | if (evt.getType().equals("keydown")) |
312 | afd3a0ef | Giannis Koutsoubos | // Use the popup's key preview hooks to close the dialog when either
|
313 | afd3a0ef | Giannis Koutsoubos | // enter or escape is pressed.
|
314 | afd3a0ef | Giannis Koutsoubos | switch (evt.getKeyCode()) {
|
315 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ENTER:
|
316 | afd3a0ef | Giannis Koutsoubos | closeDialog(); |
317 | afd3a0ef | Giannis Koutsoubos | createOrUpdateFolder(); |
318 | afd3a0ef | Giannis Koutsoubos | break;
|
319 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ESCAPE:
|
320 | afd3a0ef | Giannis Koutsoubos | closeDialog(); |
321 | afd3a0ef | Giannis Koutsoubos | break;
|
322 | afd3a0ef | Giannis Koutsoubos | } |
323 | 14ad7326 | pastith | } |
324 | 14ad7326 | pastith | |
325 | afd3a0ef | Giannis Koutsoubos | |
326 | 14ad7326 | pastith | /**
|
327 | f46a13ff | fstamatelopoulos | * Enables IE selection prevention and hides the dialog
|
328 | f46a13ff | fstamatelopoulos | * (we disable the prevention on creation of the dialog)
|
329 | f46a13ff | fstamatelopoulos | */
|
330 | f46a13ff | fstamatelopoulos | public void closeDialog() { |
331 | f46a13ff | fstamatelopoulos | GSS.preventIESelection(); |
332 | f46a13ff | fstamatelopoulos | hide(); |
333 | f46a13ff | fstamatelopoulos | } |
334 | f46a13ff | fstamatelopoulos | |
335 | f46a13ff | fstamatelopoulos | /**
|
336 | 14ad7326 | pastith | * Generate an RPC request to create a new folder.
|
337 | 14ad7326 | pastith | *
|
338 | 14ad7326 | pastith | * @param userId the ID of the user whose namespace will be searched for
|
339 | 14ad7326 | pastith | * folders
|
340 | 14ad7326 | pastith | * @param _folderName the name of the folder to create
|
341 | 14ad7326 | pastith | */
|
342 | a52ea5e4 | pastith | private void createFolder() { |
343 | 4315bcc5 | Panagiotis Astithas | String name = folderName.getText();
|
344 | 4315bcc5 | Panagiotis Astithas | if (!GSS.isValidResourceName(name)) {
|
345 | 4315bcc5 | Panagiotis Astithas | GSS.get().displayError("The folder name '" + name + "' is invalid"); |
346 | 4315bcc5 | Panagiotis Astithas | return;
|
347 | 4315bcc5 | Panagiotis Astithas | } |
348 | 2fcae28c | Panagiotis Astithas | PostCommand ep = new PostCommand(folder.getUri() + "?new=" + |
349 | 4315bcc5 | Panagiotis Astithas | URL.encodeComponent(name), "", 201) { |
350 | 14ad7326 | pastith | |
351 | 41d05cc8 | pastith | @Override
|
352 | a52ea5e4 | pastith | public void onComplete() { |
353 | 2fcae28c | Panagiotis Astithas | GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getCurrent()); |
354 | 14ad7326 | pastith | } |
355 | 14ad7326 | pastith | |
356 | 41d05cc8 | pastith | @Override
|
357 | a52ea5e4 | pastith | public void onError(Throwable t) { |
358 | a52ea5e4 | pastith | GWT.log("", t);
|
359 | a52ea5e4 | pastith | if(t instanceof RestException){ |
360 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
361 | a52ea5e4 | pastith | if(statusCode == 405) |
362 | 2fcae28c | Panagiotis Astithas | GSS.get().displayError("You don't have the necessary" +
|
363 | 2fcae28c | Panagiotis Astithas | " permissions or a folder with same name " +
|
364 | 2fcae28c | Panagiotis Astithas | "already exists");
|
365 | a52ea5e4 | pastith | else if(statusCode == 404) |
366 | a52ea5e4 | pastith | GSS.get().displayError("Resource not found");
|
367 | 14ad7326 | pastith | else
|
368 | 2fcae28c | Panagiotis Astithas | GSS.get().displayError("Unable to create folder:" +
|
369 | 2fcae28c | Panagiotis Astithas | ((RestException)t).getHttpStatusText()); |
370 | 14ad7326 | pastith | } |
371 | a52ea5e4 | pastith | else
|
372 | 2fcae28c | Panagiotis Astithas | GSS.get().displayError("System error creating folder:" +
|
373 | 2fcae28c | Panagiotis Astithas | t.getMessage()); |
374 | 14ad7326 | pastith | } |
375 | a52ea5e4 | pastith | }; |
376 | a52ea5e4 | pastith | DeferredCommand.addCommand(ep); |
377 | a52ea5e4 | pastith | |
378 | 14ad7326 | pastith | } |
379 | 14ad7326 | pastith | |
380 | 14ad7326 | pastith | /**
|
381 | 14ad7326 | pastith | * Upon closing the dialog by clicking OK or pressing ENTER this method does
|
382 | 14ad7326 | pastith | * the actual work of modifying folder properties or creating a new Folder
|
383 | 14ad7326 | pastith | * depending on the value of the create field
|
384 | 14ad7326 | pastith | *
|
385 | 14ad7326 | pastith | * @param userId
|
386 | 14ad7326 | pastith | */
|
387 | a52ea5e4 | pastith | private void createOrUpdateFolder() { |
388 | 14ad7326 | pastith | if (create)
|
389 | a52ea5e4 | pastith | createFolder(); |
390 | a52ea5e4 | pastith | else
|
391 | a52ea5e4 | pastith | updateFolder(); |
392 | 14ad7326 | pastith | |
393 | a52ea5e4 | pastith | } |
394 | 14ad7326 | pastith | |
395 | a52ea5e4 | pastith | private void updateFolder() { |
396 | a52ea5e4 | pastith | permList.updatePermissionsAccordingToInput(); |
397 | a52ea5e4 | pastith | Set<PermissionHolder> perms = permList.getPermissions();
|
398 | a52ea5e4 | pastith | JSONObject json = new JSONObject();
|
399 | a52ea5e4 | pastith | if(!folder.getName().equals(folderName.getText()))
|
400 | a52ea5e4 | pastith | json.put("name", new JSONString(folderName.getText())); |
401 | 9e6a28ed | Natasa Kapravelou | //only update the read for all perm if the user is the owner
|
402 | 9e6a28ed | Natasa Kapravelou | if (readForAll.getValue() != folder.isReadForAll())
|
403 | 9e6a28ed | Natasa Kapravelou | if (folder.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
|
404 | 9e6a28ed | Natasa Kapravelou | json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));
|
405 | 29bbf2d3 | Fotis Stamatelopoulos | if (permList.hasChanges()) {
|
406 | 29bbf2d3 | Fotis Stamatelopoulos | JSONArray perma = new JSONArray();
|
407 | 29bbf2d3 | Fotis Stamatelopoulos | int i=0; |
408 | 29bbf2d3 | Fotis Stamatelopoulos | for(PermissionHolder p : perms){
|
409 | 29bbf2d3 | Fotis Stamatelopoulos | JSONObject po = new JSONObject();
|
410 | 29bbf2d3 | Fotis Stamatelopoulos | if(p.getUser() != null) |
411 | 29bbf2d3 | Fotis Stamatelopoulos | po.put("user", new JSONString(p.getUser())); |
412 | 29bbf2d3 | Fotis Stamatelopoulos | if(p.getGroup() != null) |
413 | 29bbf2d3 | Fotis Stamatelopoulos | po.put("group", new JSONString(p.getGroup())); |
414 | 29bbf2d3 | Fotis Stamatelopoulos | po.put("read", JSONBoolean.getInstance(p.isRead()));
|
415 | 29bbf2d3 | Fotis Stamatelopoulos | po.put("write", JSONBoolean.getInstance(p.isWrite()));
|
416 | 29bbf2d3 | Fotis Stamatelopoulos | po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));
|
417 | 29bbf2d3 | Fotis Stamatelopoulos | perma.set(i,po); |
418 | 29bbf2d3 | Fotis Stamatelopoulos | i++; |
419 | 29bbf2d3 | Fotis Stamatelopoulos | } |
420 | 29bbf2d3 | Fotis Stamatelopoulos | json.put("permissions", perma);
|
421 | 29bbf2d3 | Fotis Stamatelopoulos | GWT.log(json.toString(), null);
|
422 | a52ea5e4 | pastith | } |
423 | 895035a2 | pastith | PostCommand ep = new PostCommand(folder.getUri()+"?update=", json.toString(), 200){ |
424 | a52ea5e4 | pastith | |
425 | 41d05cc8 | pastith | @Override
|
426 | a52ea5e4 | pastith | public void onComplete() { |
427 | cae9f83e | koutsoub | if(getPostBody() != null && !"".equals(getPostBody().trim())){ |
428 | a52ea5e4 | pastith | DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent(); |
429 | a52ea5e4 | pastith | FolderResource fres = folderItem.getFolderResource(); |
430 | 555e8e59 | pastith | String initialPath = fres.getUri();
|
431 | cae9f83e | koutsoub | String newPath = getPostBody().trim();
|
432 | 555e8e59 | pastith | fres.setUri(newPath); |
433 | 305d648d | koutsoub | |
434 | 305d648d | koutsoub | if(folderItem.getParentItem() != null && ((DnDTreeItem)folderItem.getParentItem()).getFolderResource() != null){ |
435 | a52ea5e4 | pastith | ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().removeSubfolderPath(initialPath); |
436 | cae9f83e | koutsoub | ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().getSubfolderPaths().add(newPath); |
437 | a52ea5e4 | pastith | } |
438 | a52ea5e4 | pastith | } |
439 | a52ea5e4 | pastith | GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent()); |
440 | 85df72e1 | koutsoub | GSS.get().showFileList(true);
|
441 | 14ad7326 | pastith | } |
442 | 14ad7326 | pastith | |
443 | 41d05cc8 | pastith | @Override
|
444 | a52ea5e4 | pastith | public void onError(Throwable t) { |
445 | a52ea5e4 | pastith | GWT.log("", t);
|
446 | a52ea5e4 | pastith | if(t instanceof RestException){ |
447 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
448 | a52ea5e4 | pastith | if(statusCode == 405) |
449 | 41d05cc8 | pastith | GSS.get().displayError("You don't have the necessary permissions or" +
|
450 | 41d05cc8 | pastith | " a folder with same name already exists");
|
451 | a52ea5e4 | pastith | else if(statusCode == 404) |
452 | 41d05cc8 | pastith | GSS.get().displayError("Resource not found, or user specified in sharing does not exist");
|
453 | a52ea5e4 | pastith | else
|
454 | 41d05cc8 | pastith | GSS.get().displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());
|
455 | a52ea5e4 | pastith | } |
456 | 14ad7326 | pastith | else
|
457 | 41d05cc8 | pastith | GSS.get().displayError("System error moifying file: "+t.getMessage());
|
458 | d805967a | droutsis | GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent()); |
459 | 14ad7326 | pastith | } |
460 | a52ea5e4 | pastith | }; |
461 | a52ea5e4 | pastith | DeferredCommand.addCommand(ep); |
462 | 14ad7326 | pastith | } |
463 | 14ad7326 | pastith | |
464 | 892a2836 | fstamatelopoulos | public void selectTab(int _tab) { |
465 | 892a2836 | fstamatelopoulos | inner.selectTab(_tab); |
466 | 892a2836 | fstamatelopoulos | } |
467 | a52ea5e4 | pastith | |
468 | 14ad7326 | pastith | } |