root / src / gr / grnet / pithos / web / client / FileUploadDialog.java @ ecc4ef81
History | View | Annotate | Download (12.1 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | e6e9f6e6 | Christos KK Loverdos | * Copyright 2011-2013 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | bdda6b2f | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
38 | a57faaf0 | Christos Stathis | |
39 | 89dddc7d | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
40 | b57df15e | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
41 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
42 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
43 | b57df15e | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
44 | 64f42c0b | Christos Stathis | import com.google.gwt.user.client.Command; |
45 | b57df15e | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
46 | ebead1b5 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
48 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.DialogBox; |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.FileUpload; |
50 | 0c73a8ff | Christos Stathis | import com.google.gwt.user.client.ui.FlowPanel; |
51 | fea6cde7 | Christos Stathis | import com.google.gwt.user.client.ui.FormPanel; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Grid; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Hidden; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Label; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
58 | a57faaf0 | Christos Stathis | |
59 | a57faaf0 | Christos Stathis | /**
|
60 | a57faaf0 | Christos Stathis | * The 'File upload' dialog box implementation.
|
61 | a57faaf0 | Christos Stathis | */
|
62 | bdda6b2f | Christos Stathis | public class FileUploadDialog extends DialogBox { |
63 | a57faaf0 | Christos Stathis | |
64 | bdda6b2f | Christos Stathis | public static final boolean DONE = true; |
65 | a57faaf0 | Christos Stathis | |
66 | 78989564 | Christos Stathis | Anchor close; |
67 | 78989564 | Christos Stathis | |
68 | a57faaf0 | Christos Stathis | /**
|
69 | a57faaf0 | Christos Stathis | * The Form element that performs the file upload.
|
70 | a57faaf0 | Christos Stathis | */
|
71 | 7811b9d1 | Christos Stathis | protected final FormPanel form = new FormPanel(); |
72 | a57faaf0 | Christos Stathis | |
73 | a57faaf0 | Christos Stathis | private final FileUpload upload = new FileUpload(); |
74 | a57faaf0 | Christos Stathis | |
75 | bdda6b2f | Christos Stathis | private final Label filenameLabel = new Label(); |
76 | a57faaf0 | Christos Stathis | |
77 | bdda6b2f | Christos Stathis | private final Label foldernameLabel = new Label(); |
78 | a57faaf0 | Christos Stathis | |
79 | bdda6b2f | Christos Stathis | private Button submit; |
80 | a57faaf0 | Christos Stathis | |
81 | bdda6b2f | Christos Stathis | protected Folder folder;
|
82 | a57faaf0 | Christos Stathis | |
83 | 749068ba | Christos Stathis | protected Pithos app;
|
84 | 78989564 | Christos Stathis | |
85 | 78989564 | Christos Stathis | private boolean inProgress = false; |
86 | a57faaf0 | Christos Stathis | |
87 | a57faaf0 | Christos Stathis | /**
|
88 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
89 | a57faaf0 | Christos Stathis | */
|
90 | 1a0db4f4 | Christos Stathis | public FileUploadDialog(Pithos _app) {
|
91 | eb2ae14b | Christos Stathis | app = _app; |
92 | 78989564 | Christos Stathis | close = new Anchor("close"); |
93 | 4420a247 | Christos Stathis | close.addStyleName("close");
|
94 | 4420a247 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
95 | 4420a247 | Christos Stathis | |
96 | 4420a247 | Christos Stathis | @Override
|
97 | 4420a247 | Christos Stathis | public void onClick(ClickEvent event) { |
98 | 1a0db4f4 | Christos Stathis | close(); |
99 | 4420a247 | Christos Stathis | } |
100 | 4420a247 | Christos Stathis | }); |
101 | a57faaf0 | Christos Stathis | // Set the dialog's caption.
|
102 | a57faaf0 | Christos Stathis | setText("File upload");
|
103 | 4420a247 | Christos Stathis | setStyleName("pithos-DialogBox");
|
104 | 1a0db4f4 | Christos Stathis | setVisible(false);
|
105 | 1a0db4f4 | Christos Stathis | |
106 | a57faaf0 | Christos Stathis | // Since we're going to add a FileUpload widget, we'll need to set the
|
107 | a57faaf0 | Christos Stathis | // form to use the POST method, and multipart MIME encoding.
|
108 | a57faaf0 | Christos Stathis | form.setEncoding(FormPanel.ENCODING_MULTIPART); |
109 | a57faaf0 | Christos Stathis | form.setMethod(FormPanel.METHOD_POST); |
110 | a57faaf0 | Christos Stathis | |
111 | a57faaf0 | Christos Stathis | // Create a panel to hold all of the form widgets.
|
112 | a57faaf0 | Christos Stathis | VerticalPanel panel = new VerticalPanel();
|
113 | b57df15e | Christos Stathis | panel.setWidth("470px");
|
114 | 4420a247 | Christos Stathis | panel.add(close); |
115 | a57faaf0 | Christos Stathis | form.setWidget(panel); |
116 | bdda6b2f | Christos Stathis | |
117 | 4420a247 | Christos Stathis | VerticalPanel inner = new VerticalPanel();
|
118 | 4420a247 | Christos Stathis | inner.addStyleName("inner");
|
119 | 4420a247 | Christos Stathis | |
120 | 0d01524d | Christos Stathis | final Hidden auth = new Hidden("X-Auth-Token"); |
121 | 4420a247 | Christos Stathis | inner.add(auth); |
122 | 4123152d | Christos Stathis | upload.setName("X-Object-Data");
|
123 | eb2ae14b | Christos Stathis | upload.setVisible(false);
|
124 | a57faaf0 | Christos Stathis | filenameLabel.setText("");
|
125 | a57faaf0 | Christos Stathis | filenameLabel.setVisible(false);
|
126 | a57faaf0 | Christos Stathis | filenameLabel.setStyleName("props-labels");
|
127 | bdda6b2f | Christos Stathis | HorizontalPanel fileUploadPanel = new HorizontalPanel();
|
128 | eb2ae14b | Christos Stathis | fileUploadPanel.setVisible(false);
|
129 | bdda6b2f | Christos Stathis | fileUploadPanel.add(filenameLabel); |
130 | bdda6b2f | Christos Stathis | fileUploadPanel.add(upload); |
131 | a57faaf0 | Christos Stathis | Grid generalTable = new Grid(2, 2); |
132 | a57faaf0 | Christos Stathis | generalTable.setText(0, 0, "Folder"); |
133 | bdda6b2f | Christos Stathis | generalTable.setWidget(0, 1, foldernameLabel); |
134 | bdda6b2f | Christos Stathis | generalTable.setWidget(1, 1, fileUploadPanel); |
135 | a57faaf0 | Christos Stathis | generalTable.getCellFormatter().setStyleName(0, 0, "props-labels"); |
136 | bdda6b2f | Christos Stathis | generalTable.getCellFormatter().setStyleName(0, 1, "props-values"); |
137 | eb2ae14b | Christos Stathis | generalTable.getCellFormatter().setVisible(1, 0, false); |
138 | a57faaf0 | Christos Stathis | generalTable.setCellSpacing(4);
|
139 | a57faaf0 | Christos Stathis | |
140 | 4420a247 | Christos Stathis | inner.add(generalTable); |
141 | a57faaf0 | Christos Stathis | |
142 | 0c73a8ff | Christos Stathis | FlowPanel uploader = new FlowPanel();
|
143 | 0c73a8ff | Christos Stathis | uploader.getElement().setId("uploader");
|
144 | 0c73a8ff | Christos Stathis | inner.add(uploader); |
145 | 0c73a8ff | Christos Stathis | |
146 | 4420a247 | Christos Stathis | panel.add(inner); |
147 | 4420a247 | Christos Stathis | panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
148 | 4420a247 | Christos Stathis | |
149 | a57faaf0 | Christos Stathis | setWidget(form); |
150 | 89dddc7d | Christos Stathis | |
151 | 89dddc7d | Christos Stathis | Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
|
152 | 89dddc7d | Christos Stathis | |
153 | 89dddc7d | Christos Stathis | @Override
|
154 | 89dddc7d | Christos Stathis | public void execute() { |
155 | 89dddc7d | Christos Stathis | center(); |
156 | 89dddc7d | Christos Stathis | close(); |
157 | 89dddc7d | Christos Stathis | } |
158 | 89dddc7d | Christos Stathis | }); |
159 | a57faaf0 | Christos Stathis | } |
160 | a57faaf0 | Christos Stathis | |
161 | eb2ae14b | Christos Stathis | private void refreshFolder() { |
162 | eb2ae14b | Christos Stathis | if (app.getSelectedTree().equals(app.getFolderTreeView()))
|
163 | eb2ae14b | Christos Stathis | app.updateFolder(folder, true, new Command() { |
164 | eb2ae14b | Christos Stathis | |
165 | eb2ae14b | Christos Stathis | @Override
|
166 | eb2ae14b | Christos Stathis | public void execute() { |
167 | eb2ae14b | Christos Stathis | app.updateStatistics(); |
168 | eb2ae14b | Christos Stathis | } |
169 | 6acd4df3 | Christos Stathis | }, true);
|
170 | eb2ae14b | Christos Stathis | else
|
171 | 3646552f | Christos Stathis | app.updateOtherSharedFolder(folder, true, null); |
172 | eb2ae14b | Christos Stathis | } |
173 | eb2ae14b | Christos Stathis | |
174 | 89dddc7d | Christos Stathis | native void setupUpload(FileUploadDialog dlg, Pithos app, String token) /*-{ |
175 | b57df15e | Christos Stathis | var uploader = $wnd.$('#uploader').pluploadQueue();
|
176 | fefc5343 | Christos Stathis | var createUploader = function() {
|
177 | b57df15e | Christos Stathis | $wnd.$("#uploader").pluploadQueue({
|
178 | b57df15e | Christos Stathis | // General settings
|
179 | b57df15e | Christos Stathis | runtimes : 'html5, flash, gears, silverlight, browserplus, html4',
|
180 | b57df15e | Christos Stathis | unique_names : true,
|
181 | b57df15e | Christos Stathis |
|
182 | b57df15e | Christos Stathis | // Flash settings
|
183 | b57df15e | Christos Stathis | flash_swf_url : 'plupload/js/plupload.flash.swf',
|
184 | b57df15e | Christos Stathis |
|
185 | b57df15e | Christos Stathis | // Silverlight settings
|
186 | b57df15e | Christos Stathis | silverlight_xap_url : 'plupload/js/plupload.silverlight.xap',
|
187 | 0c26bcb8 | Christos Stathis |
|
188 | b57df15e | Christos Stathis | multiple_queues: true,
|
189 | b57df15e | Christos Stathis |
|
190 | b57df15e | Christos Stathis | preinit: {
|
191 | b57df15e | Christos Stathis | Init: function(up, info) {
|
192 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
193 | 3aa012b0 | Christos Stathis | $wnd.console.log("Init fired");
|
194 | b57df15e | Christos Stathis | up.settings.file_data_name = "X-Object-Data";
|
195 | b57df15e | Christos Stathis | }
|
196 | b57df15e | Christos Stathis |
|
197 | eb2ae14b | Christos Stathis | },
|
198 | eb2ae14b | Christos Stathis |
|
199 | b57df15e | Christos Stathis | init: {
|
200 | 1a0db4f4 | Christos Stathis | FilesAdded: function(up, files) {
|
201 | 89dddc7d | Christos Stathis | var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
|
202 | 89dddc7d | Christos Stathis | var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
|
203 | 4eaecbac | Christos KK Loverdos | var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwnerID()();
|
204 | 89dddc7d | Christos Stathis | var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
|
205 | 89dddc7d | Christos Stathis | var path = api + owner + uri;
|
206 | 1a0db4f4 | Christos Stathis | for (var j=0; j<files.length; j++)
|
207 | 3646552f | Christos Stathis | files[j].url = path + "/" + files[j].name;
|
208 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(true);
|
209 | 249fbc5b | Christos Stathis | if (up.state == $wnd.plupload.STOPPED)
|
210 | 249fbc5b | Christos Stathis | up.start();
|
211 | 89dddc7d | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::showUploadIndicator()();
|
212 | c4818b9d | Christos Stathis | if (!dlg.@gr.grnet.pithos.web.client.FileUploadDialog::isVisible()())
|
213 | 249fbc5b | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::showUploadAlert(I)(up.files.length);
|
214 | 78989564 | Christos Stathis | },
|
215 | 78989564 | Christos Stathis |
|
216 | 78989564 | Christos Stathis | FilesRemoved: function(up, files) {
|
217 | 78989564 | Christos Stathis | if (up.files.length == 0)
|
218 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(false);
|
219 | 78989564 | Christos Stathis | else
|
220 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(true);
|
221 | b57df15e | Christos Stathis | },
|
222 | b57df15e | Christos Stathis |
|
223 | b57df15e | Christos Stathis | BeforeUpload: function(up, file) {
|
224 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
225 | 3aa012b0 | Christos Stathis | $wnd.console.log('About to upload ' + file.url);
|
226 | 3646552f | Christos Stathis | up.settings.url = file.url + + "?X-Auth-Token=" + encodeURIComponent(token);
|
227 | b57df15e | Christos Stathis | },
|
228 | b57df15e | Christos Stathis |
|
229 | c4818b9d | Christos Stathis | UploadProgress: function(up, file) {
|
230 | c4818b9d | Christos Stathis | $wnd.$('#upload_alert_progress_bar').css('width', up.total.percent + '%');
|
231 | c4818b9d | Christos Stathis | $wnd.$('#upload_alert_percent').html(up.total.percent + '%');
|
232 | c4818b9d | Christos Stathis | },
|
233 | c4818b9d | Christos Stathis |
|
234 | b57df15e | Christos Stathis | FileUploaded: function(up, file, response) {
|
235 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log) {
|
236 | 3aa012b0 | Christos Stathis | $wnd.console.log('File ' + file.name + ' uploaded');
|
237 | 3aa012b0 | Christos Stathis | $wnd.console.log('Response: ' + response);
|
238 | 3aa012b0 | Christos Stathis | }
|
239 | 89dddc7d | Christos Stathis | var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
|
240 | 89dddc7d | Christos Stathis | if (folder == file.folder)
|
241 | 89dddc7d | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder()();
|
242 | b57df15e | Christos Stathis | },
|
243 | b57df15e | Christos Stathis |
|
244 | b57df15e | Christos Stathis | UploadComplete: function(up, files) {
|
245 | ecf96721 | Christos Stathis | if ($wnd.console && $wnd.console.log) {
|
246 | 3aa012b0 | Christos Stathis | $wnd.console.log('All files finished');
|
247 | ecf96721 | Christos Stathis | }
|
248 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(false);
|
249 | 1a0db4f4 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::hideUploadIndicator()();
|
250 | 3646552f | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::hideUploadAlert()();
|
251 | 3646552f | Christos Stathis | var uris = [];
|
252 | ecf96721 | Christos Stathis | if (!dlg.@gr.grnet.pithos.web.client.FileUploadDialog::isVisible()())
|
253 | ecf96721 | Christos Stathis | while (files.length > 0) {
|
254 | ecf96721 | Christos Stathis | uris.push(files[0].url);
|
255 | ecf96721 | Christos Stathis | up.removeFile(files[0]);
|
256 | ecf96721 | Christos Stathis | }
|
257 | ecf96721 | Christos Stathis | else
|
258 | ecf96721 | Christos Stathis | for (var i=0; i<files.length; i++)
|
259 | ecf96721 | Christos Stathis | uris.push(files[i].url);
|
260 | 3646552f | Christos Stathis | app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder(Lcom/google/gwt/core/client/JsArrayString;)(uris);
|
261 | fefc5343 | Christos Stathis | },
|
262 | fefc5343 | Christos Stathis |
|
263 | fefc5343 | Christos Stathis | Error: function(up, error) {
|
264 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
265 | 3aa012b0 | Christos Stathis | $wnd.console.log("Error occured:" + error);
|
266 | b57df15e | Christos Stathis | }
|
267 | b57df15e | Christos Stathis | }
|
268 | b57df15e | Christos Stathis | });
|
269 | fefc5343 | Christos Stathis | return $wnd.$('#uploader').pluploadQueue();
|
270 | fefc5343 | Christos Stathis | };
|
271 | fefc5343 | Christos Stathis |
|
272 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
273 | 3aa012b0 | Christos Stathis | $wnd.console.log(uploader);
|
274 | fefc5343 | Christos Stathis | if (!uploader) {
|
275 | fefc5343 | Christos Stathis | uploader = createUploader();
|
276 | b57df15e | Christos Stathis | }
|
277 | b57df15e | Christos Stathis | else {
|
278 | 89dddc7d | Christos Stathis | var dropElm = $wnd.document.getElementById('rightPanel');
|
279 | 89dddc7d | Christos Stathis | $wnd.plupload.removeAllEvents(dropElm, uploader.id);
|
280 | 1a0db4f4 | Christos Stathis | var removeAll = true;
|
281 | 1a0db4f4 | Christos Stathis | var files = uploader.files;
|
282 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
283 | 3aa012b0 | Christos Stathis | $wnd.console.log('About to check ' + files.length + ' files');
|
284 | 1a0db4f4 | Christos Stathis | for (var i=0; i<files.length; i++) {
|
285 | 1a0db4f4 | Christos Stathis | var f = files[i];
|
286 | 1a0db4f4 | Christos Stathis | if (f.status != $wnd.plupload.DONE && f.status != $wnd.plupload.FAILED) {
|
287 | 1a0db4f4 | Christos Stathis | removeAll = false;
|
288 | b57df15e | Christos Stathis | break;
|
289 | 0c73a8ff | Christos Stathis | }
|
290 | 0c73a8ff | Christos Stathis | }
|
291 | 1a0db4f4 | Christos Stathis | if (removeAll) {
|
292 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
293 | 3aa012b0 | Christos Stathis | $wnd.console.log('About to remove ' + files.length + ' files');
|
294 | fefc5343 | Christos Stathis | uploader.destroy();
|
295 | fefc5343 | Christos Stathis | uploader = createUploader();
|
296 | 3aa012b0 | Christos Stathis | if ($wnd.console && $wnd.console.log)
|
297 | 3aa012b0 | Christos Stathis | $wnd.console.log(uploader);
|
298 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(false);
|
299 | 78989564 | Christos Stathis | }
|
300 | 78989564 | Christos Stathis | else {
|
301 | 78989564 | Christos Stathis | dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(true);
|
302 | 1a0db4f4 | Christos Stathis | }
|
303 | b57df15e | Christos Stathis | }
|
304 | 1a0db4f4 | Christos Stathis | }-*/;
|
305 | 1a0db4f4 | Christos Stathis | |
306 | 1a0db4f4 | Christos Stathis | native boolean isUploading()/*-{ |
307 | 1a0db4f4 | Christos Stathis | var uploader = $wnd.$("#uploader").pluploadQueue();
|
308 | 1a0db4f4 | Christos Stathis | var files = uploader.files;
|
309 | 1a0db4f4 | Christos Stathis | for (var i=0; i<files.length; i++) {
|
310 | 1a0db4f4 | Christos Stathis | var f = files[i];
|
311 | 1a0db4f4 | Christos Stathis | if (f.status == $wnd.plupload.UPLOADING) {
|
312 | 1a0db4f4 | Christos Stathis | return true;
|
313 | 1a0db4f4 | Christos Stathis | }
|
314 | 1a0db4f4 | Christos Stathis | }
|
315 | 1a0db4f4 | Christos Stathis | return false;
|
316 | 0c73a8ff | Christos Stathis | }-*/;
|
317 | b57df15e | Christos Stathis | |
318 | b57df15e | Christos Stathis | @Override
|
319 | b57df15e | Christos Stathis | protected void onPreviewNativeEvent(NativePreviewEvent event) { |
320 | b57df15e | Christos Stathis | super.onPreviewNativeEvent(event);
|
321 | b57df15e | Christos Stathis | |
322 | b57df15e | Christos Stathis | NativeEvent evt = event.getNativeEvent(); |
323 | b57df15e | Christos Stathis | if (evt.getType().equals("keydown")) |
324 | b57df15e | Christos Stathis | // Use the popup's key preview hooks to close the dialog when
|
325 | b57df15e | Christos Stathis | // escape is pressed.
|
326 | b57df15e | Christos Stathis | switch (evt.getKeyCode()) {
|
327 | b57df15e | Christos Stathis | case KeyCodes.KEY_ESCAPE:
|
328 | 1a0db4f4 | Christos Stathis | close(); |
329 | b57df15e | Christos Stathis | break;
|
330 | b57df15e | Christos Stathis | } |
331 | b57df15e | Christos Stathis | } |
332 | 1a0db4f4 | Christos Stathis | |
333 | 1a0db4f4 | Christos Stathis | public void setFolder(Folder folder) { |
334 | 1a0db4f4 | Christos Stathis | this.folder = folder;
|
335 | 1a0db4f4 | Christos Stathis | foldernameLabel.setText(folder.getName()); |
336 | 1a0db4f4 | Christos Stathis | } |
337 | 1a0db4f4 | Christos Stathis | |
338 | 1a0db4f4 | Christos Stathis | @Override
|
339 | 1a0db4f4 | Christos Stathis | public void center() { |
340 | 1a0db4f4 | Christos Stathis | app.hideUploadIndicator(); |
341 | 1a0db4f4 | Christos Stathis | setVisible(true);
|
342 | 1a0db4f4 | Christos Stathis | setModal(true);
|
343 | 1a0db4f4 | Christos Stathis | super.center();
|
344 | cc0120ab | Christos KK Loverdos | setupUpload(this, app, app.getUserToken());
|
345 | 1a0db4f4 | Christos Stathis | super.center();
|
346 | 1a0db4f4 | Christos Stathis | } |
347 | 1a0db4f4 | Christos Stathis | |
348 | 1a0db4f4 | Christos Stathis | private void hideUploadIndicator() { |
349 | 1a0db4f4 | Christos Stathis | app.hideUploadIndicator(); |
350 | 1a0db4f4 | Christos Stathis | } |
351 | 1a0db4f4 | Christos Stathis | |
352 | 1a0db4f4 | Christos Stathis | void close() {
|
353 | 1a0db4f4 | Christos Stathis | setVisible(false);
|
354 | 1a0db4f4 | Christos Stathis | setModal(false);
|
355 | ecf96721 | Christos Stathis | clearUploader(); |
356 | 1a0db4f4 | Christos Stathis | if (isUploading())
|
357 | 1a0db4f4 | Christos Stathis | app.showUploadIndicator(); |
358 | 89dddc7d | Christos Stathis | setGlobalDropArea(); |
359 | 1a0db4f4 | Christos Stathis | } |
360 | ecf96721 | Christos Stathis | |
361 | ecf96721 | Christos Stathis | private native void clearUploader() /*-{ |
362 | ecf96721 | Christos Stathis | var uploader = $wnd.$("#uploader").pluploadQueue();
|
363 | ecf96721 | Christos Stathis | var files = uploader.files;
|
364 | 14d29f68 | Christos Stathis | var clear = true;
|
365 | 14d29f68 | Christos Stathis | for (var i=0; i<files.length; i++)
|
366 | 14d29f68 | Christos Stathis | if (files[i].status == $wnd.plupload.UPLOADING)
|
367 | 14d29f68 | Christos Stathis | clear = false;
|
368 | 14d29f68 | Christos Stathis | if (clear)
|
369 | 14d29f68 | Christos Stathis | while (files.length > 0)
|
370 | 14d29f68 | Christos Stathis | uploader.removeFile(files[0]);
|
371 | ecf96721 | Christos Stathis | }-*/;
|
372 | 78989564 | Christos Stathis | |
373 | 89dddc7d | Christos Stathis | native void setGlobalDropArea() /*-{ |
374 | 89dddc7d | Christos Stathis | var uploader = $wnd.$("#uploader").pluploadQueue();
|
375 | 89dddc7d | Christos Stathis | if (uploader.runtime == 'html5') {
|
376 | 89dddc7d | Christos Stathis | uploader.settings.drop_element = 'rightPanel';
|
377 | 89dddc7d | Christos Stathis | uploader.trigger('PostInit');
|
378 | 89dddc7d | Christos Stathis | }
|
379 | 89dddc7d | Christos Stathis | }-*/;
|
380 | 89dddc7d | Christos Stathis | |
381 | 78989564 | Christos Stathis | private void setInProgress(boolean _inProgress) { |
382 | 78989564 | Christos Stathis | inProgress = _inProgress; |
383 | 78989564 | Christos Stathis | if (inProgress)
|
384 | 78989564 | Christos Stathis | close.setText("hide");
|
385 | 78989564 | Christos Stathis | else
|
386 | 78989564 | Christos Stathis | close.setText("close");
|
387 | 78989564 | Christos Stathis | } |
388 | a57faaf0 | Christos Stathis | } |