Revision b3c9eba8 src/gr/grnet/pithos/web/client/FilePermissionsDialog.java

b/src/gr/grnet/pithos/web/client/FilePermissionsDialog.java
36 36

  
37 37
import gr.grnet.pithos.web.client.foldertree.File;
38 38
import gr.grnet.pithos.web.client.foldertree.Resource;
39
import gr.grnet.pithos.web.client.rest.HeadRequest;
39 40
import gr.grnet.pithos.web.client.rest.PostRequest;
40 41

  
41 42
import java.util.Map;
42 43

  
43 44
import com.google.gwt.core.client.GWT;
44 45
import com.google.gwt.core.client.Scheduler;
46
import com.google.gwt.dom.client.NativeEvent;
45 47
import com.google.gwt.event.dom.client.ClickEvent;
46 48
import com.google.gwt.event.dom.client.ClickHandler;
49
import com.google.gwt.event.dom.client.KeyCodes;
47 50
import com.google.gwt.http.client.Response;
48 51
import com.google.gwt.http.client.URL;
49 52
import com.google.gwt.resources.client.ImageResource;
50 53
import com.google.gwt.user.client.Command;
51 54
import com.google.gwt.user.client.Window;
55
import com.google.gwt.user.client.Event.NativePreviewEvent;
52 56
import com.google.gwt.user.client.ui.Anchor;
53 57
import com.google.gwt.user.client.ui.Button;
54 58
import com.google.gwt.user.client.ui.CheckBox;
......
68 72
	protected PermissionsList permList;
69 73

  
70 74
	protected CheckBox readForAll;
71

  
75
	
76
	private HorizontalPanel pathPanel;
77
	
78
	private TextBox path;
79
	
72 80
	/**
73 81
	 * An image bundle for this widgets images.
74 82
	 */
......
122 130

  
123 131
        outer.add(inner);
124 132

  
125
		// Create the 'OK' button, along with a listener that hides the dialog
126
		// when the button is clicked.
127
		final Button ok = new Button("OK", new ClickHandler() {
133
		final Button ok = new Button("Close", new ClickHandler() {
128 134
			@Override
129 135
			public void onClick(ClickEvent event) {
130
				accept();
131 136
				closeDialog();
132 137
			}
133 138
		});
......
178 183
        final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +
179 184
                    " by everyone. By checking this option, you are certifying that you have the right to " +
180 185
                    "distribute this file and that it does not violate the Terms of Use.", true);
181
        readForAllNote.setVisible(false);
182 186
        readForAllNote.setStylePrimaryName("pithos-readForAllNote");
183 187

  
184 188
        readForAll = new CheckBox();
......
186 190
        readForAll.addClickHandler(new ClickHandler() {
187 191
            @Override
188 192
            public void onClick(ClickEvent event) {
189
                readForAllNote.setVisible(readForAll.getValue());
193
            	accept();
190 194
            }
191 195
        });
192 196

  
......
201 205
            permPanel.add(permForAll);
202 206
        }
203 207

  
204
        if (file.isPublished()) {
205
            final HorizontalPanel pathPanel = new HorizontalPanel();
206
            pathPanel.setWidth("100%");
207
            pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
208
            pathPanel.add(new Label("Link"));
209
            pathPanel.setSpacing(8);
210
            pathPanel.addStyleName("pithos-TabPanelBottom");
211

  
212
            TextBox path = new TextBox();
213
            path.setWidth("100%");
214
            path.addClickHandler(new ClickHandler() {
215
                @Override
216
                public void onClick(ClickEvent event) {
217
                    Pithos.enableIESelection();
218
                    ((TextBox) event.getSource()).selectAll();
219
                    Pithos.preventIESelection();
220
                }
221
            });
222
            path.setText(Window.Location.getHost() + file.getPublicUri());
223
            path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
224
            path.setWidth("100%");
225
            path.setReadOnly(true);
226
            pathPanel.add(path);
227
            permPanel.add(pathPanel);
228
        }
229

  
208
        pathPanel = new HorizontalPanel();
209
        pathPanel.setVisible(false);
210
        pathPanel.setWidth("100%");
211
        pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
212
        pathPanel.add(new Label("Link"));
213
        pathPanel.setSpacing(8);
214
        pathPanel.addStyleName("pithos-TabPanelBottom");
215

  
216
        path = new TextBox();
217
        path.setWidth("100%");
218
        path.addClickHandler(new ClickHandler() {
219
            @Override
220
            public void onClick(ClickEvent event) {
221
                Pithos.enableIESelection();
222
                ((TextBox) event.getSource()).selectAll();
223
                Pithos.preventIESelection();
224
            }
225
        });
226
        path.setText(Window.Location.getHost() + file.getPublicUri());
227
        path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");
228
        path.setWidth("100%");
229
        path.setReadOnly(true);
230
        pathPanel.add(path);
231
        permPanel.add(pathPanel);
232

  
233
        Scheduler.get().scheduleDeferred(new Command() {
234
			
235
			@Override
236
			public void execute() {
237
				showLinkIfPublished();
238
			}
239
		});
230 240
        return permPanel;
231 241
    }
232 242

  
243
    void showLinkIfPublished() {
244
		if (file.isPublished()) {
245
	        path.setText(Window.Location.getHost() + file.getPublicUri());
246
	        pathPanel.setVisible(true);
247
		}
248
		else {
249
			pathPanel.setVisible(false);
250
		}
251
    }
233 252
	/**
234 253
	 * Accepts any change and updates the file
235 254
	 *
......
238 257
	protected void accept() {
239 258
		final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);
240 259

  
241
		//only update the read for all perm if the user is the owner
242 260
        Boolean published = null;
243 261
		if (readForAll.getValue() != file.isPublished())
244 262
			if (file.getOwner().equals(app.getUsername()))
245 263
                published = readForAll.getValue();
246
        final Boolean finalPublished = published;
247

  
248
        updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", finalPublished, perms);
264
        updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", published, perms);
249 265
	}
250 266

  
251
	protected void updateMetaData(String api, String owner, String path, final Boolean published, final Map<String, Boolean[]> newPermissions) {
267
	protected void updateMetaData(String api, String owner, final String path, final Boolean published, final Map<String, Boolean[]> newPermissions) {
252 268
        if (published != null || newPermissions != null) {
253 269
            PostRequest updateFile = new PostRequest(api, owner, path) {
254 270
                @Override
255 271
                public void onSuccess(Resource result) {
256
                    app.updateFolder(file.getParent(), true, new Command() {
257
						
272
                	HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwner(), path, file) {
273

  
258 274
						@Override
259
						public void execute() {
260
							app.updateMySharedRoot();
275
						public void onSuccess(File _result) {
276
							showLinkIfPublished();
277
		                    app.updateFolder(file.getParent(), true, new Command() {
278
								
279
								@Override
280
								public void execute() {
281
									app.updateMySharedRoot();
282
								}
283
							});
261 284
						}
262
					});
285

  
286
						@Override
287
						public void onError(Throwable t) {
288
		                    GWT.log("", t);
289
							app.setError(t);
290
		                    app.displayError("System error modifying file:" + t.getMessage());
291
						}
292

  
293
						@Override
294
						protected void onUnauthorized(Response response) {
295
							app.sessionExpired();
296
						}
297
					};
298
					headFile.setHeader("X-Auth-Token", app.getToken());
299
					Scheduler.get().scheduleDeferred(headFile);
263 300
                }
264 301

  
265 302
                @Override
......
315 352
				}
316 353
			});
317 354
    }
355

  
356
	@Override
357
	protected void onPreviewNativeEvent(NativePreviewEvent preview) {
358
	    super.onPreviewNativeEvent(preview);
359

  
360
	    NativeEvent evt = preview.getNativeEvent();
361
	    if (evt.getType().equals("keydown") && evt.getKeyCode() == KeyCodes.KEY_ENTER)
362
			        closeDialog();
363
	}
318 364
}

Also available in: Unified diff