root / src / pithos / content / pithos.js @ 68:0ec0b09ea126
History | View | Annotate | Download (12.2 kB)
1 |
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
|
---|---|
2 |
// (http://www.grnet.gr)
|
3 |
//
|
4 |
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
|
5 |
// All rights reserved.
|
6 |
//
|
7 |
// Redistribution and use in source and binary forms, with or without
|
8 |
// modification, are permitted provided that the following conditions are
|
9 |
// met:
|
10 |
//
|
11 |
// - Redistributions of source code must retain the above copyright
|
12 |
// notice, this list of conditions and the following disclaimer.
|
13 |
// - Redistributions in binary form must reproduce the above
|
14 |
// copyright notice, this list of conditions and the following
|
15 |
// disclaimer in the documentation and/or other materials provided
|
16 |
// with the distribution.
|
17 |
// - Neither the name of GRNET S.A. nor the names of its contributors
|
18 |
// may be used to endorse or promote products derived from this
|
19 |
// software without specific prior written permission.
|
20 |
//
|
21 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25 |
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
27 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
29 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
30 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
33 |
// Basic UI functions
|
34 |
|
35 |
// event to quit toolbar button
|
36 |
function quit_client() { |
37 |
alert('Pithos Firefox client will now disconnect from the server');
|
38 |
window.location.replace('https://pithos.grnet.gr/Shibboleth.sso/Logout');
|
39 |
} |
40 |
|
41 |
function open_groups() { |
42 |
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalFileRead UniversalBrowserRead");
|
43 |
window.openDialog("groups/groups.xul", "Groups", "chrome,dialog,resizable,centerscreen"); |
44 |
pithos_object.refreshLists(); |
45 |
} |
46 |
|
47 |
function show_properties(uri) { |
48 |
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalFileRead UniversalBrowserRead");
|
49 |
window.openDialog("dialogs/file_properties.xul", "Trash", "chrome,dialog,resizable,centerscreen,width=400, height=300", uri); |
50 |
} |
51 |
|
52 |
//
|
53 |
function TreeModel(tree_id) { |
54 |
// public members
|
55 |
this.children_tag = document.getElementById(tree_id);
|
56 |
// private members
|
57 |
|
58 |
var leftTree = (tree_id == 'treech-left'); // root tag for children rows (data) |
59 |
var current = this; |
60 |
var descending = true; |
61 |
|
62 |
// public functions
|
63 |
|
64 |
this.populate = function(dir_obj) { |
65 |
while(current.children_tag.hasChildNodes()) {
|
66 |
current.children_tag.removeChild(current.children_tag.firstChild); |
67 |
} |
68 |
|
69 |
// add previous dir
|
70 |
if(dir_obj.parentFolder != null) { |
71 |
var a = new Array(); |
72 |
|
73 |
// Data for columns in the UI
|
74 |
a[0] = "../skin/up.png"; |
75 |
a[1] = ".."; |
76 |
a[2] = "<PARENT-DIR>"; |
77 |
a[3] = ""; |
78 |
a[4] = ""; |
79 |
|
80 |
addData(dir_obj.parentFolder, a, false);
|
81 |
} |
82 |
|
83 |
// add the following
|
84 |
for (var fldr in dir_obj.folders) { |
85 |
this.addFolder(dir_obj.folders[fldr]);
|
86 |
} |
87 |
|
88 |
for (var fl in dir_obj.files) { |
89 |
// trash exception
|
90 |
if ( dir_obj.URI == connection_obj.user_homepage().trash) {
|
91 |
this.addFile(dir_obj.files[fl]);
|
92 |
} else if(!dir_obj.files[fl].deleted) { |
93 |
this.addFile(dir_obj.files[fl]);
|
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
this.populateSortBy = function(column_name, dir_obj) { |
99 |
while(current.children_tag.hasChildNodes()) {
|
100 |
current.children_tag.removeChild(current.children_tag.firstChild); |
101 |
} |
102 |
|
103 |
// add previous dir
|
104 |
if(dir_obj.parentFolder != null) { |
105 |
var a = new Array(); |
106 |
|
107 |
// Data for columns in the UI
|
108 |
a[0] = "../skin/up.png"; |
109 |
a[1] = ".."; |
110 |
a[2] = "<PARENT-DIR>"; |
111 |
a[3] = ""; |
112 |
a[4] = ""; |
113 |
|
114 |
addData(dir_obj.parentFolder, a, false);
|
115 |
} |
116 |
|
117 |
//
|
118 |
if (column_name == 'name') { |
119 |
dir_obj.folders.sort(compare_name); |
120 |
dir_obj.files.sort(compare_name); |
121 |
} else if (column_name == 'size') { |
122 |
dir_obj.files.sort(compare_size); |
123 |
} else if (column_name == 'version') { |
124 |
dir_obj.files.sort(compare_version); |
125 |
} else if (column_name == 'date') { |
126 |
dir_obj.files.sort(compare_date); |
127 |
} |
128 |
|
129 |
if (descending) {
|
130 |
dir_obj.folders.reverse(); |
131 |
dir_obj.files.reverse(); |
132 |
} |
133 |
|
134 |
for (var fldr in dir_obj.folders) { |
135 |
this.addFolder(dir_obj.folders[fldr]);
|
136 |
} |
137 |
|
138 |
for (var fl in dir_obj.files) { |
139 |
// trash exception
|
140 |
if ( dir_obj.URI == connection_obj.user_homepage().trash) {
|
141 |
this.addFile(dir_obj.files[fl]);
|
142 |
} else if(!dir_obj.files[fl].deleted) { |
143 |
this.addFile(dir_obj.files[fl]);
|
144 |
} |
145 |
} |
146 |
|
147 |
descending = !descending; |
148 |
|
149 |
function compare_name(a, b) { |
150 |
if (a.name == b.name) { return 0; } |
151 |
var arr = new Array(); |
152 |
|
153 |
arr.push(a.name); |
154 |
arr.push(b.name); |
155 |
arr.sort(); |
156 |
|
157 |
if(arr[0] == a.name) { return -1; } else { return 1; } |
158 |
} |
159 |
|
160 |
function compare_size(a, b) { return (a.size - b.size); } |
161 |
|
162 |
function compare_version(a, b) { return (a.version - b.version); } |
163 |
|
164 |
function compare_date(a, b) { return (a.creationDate - b.creationDate); } |
165 |
} |
166 |
|
167 |
this.addFolder = function(folder_obj) { |
168 |
var a = new Array(); |
169 |
|
170 |
a[0] = folder_obj.contentImage;
|
171 |
a[1] = folder_obj.name;
|
172 |
a[2] = "<DIRECTORY>"; |
173 |
a[3] = ""; |
174 |
a[4] = ""; |
175 |
|
176 |
addData(folder_obj.URI, a, false);
|
177 |
} |
178 |
|
179 |
this.addFile = function(file_obj) { |
180 |
var a = new Array(); |
181 |
var d = new Date(); |
182 |
d.setTime(file_obj.creationDate); |
183 |
|
184 |
a[0] = file_obj.contentImage;
|
185 |
a[1] = file_obj.name;
|
186 |
a[2] = format_number(file_obj.size);
|
187 |
a[3] = d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear(); |
188 |
a[4] = file_obj.version;
|
189 |
|
190 |
addData(file_obj.URI, a, true);
|
191 |
} |
192 |
|
193 |
// private functions
|
194 |
function addData(id, data_array, isFile) { |
195 |
var treeitem = document.createElement('treeitem'); |
196 |
current.children_tag.appendChild(treeitem); |
197 |
|
198 |
// treerow addition
|
199 |
var treerow = document.createElement('treerow'); |
200 |
treerow.setAttribute('id', id);
|
201 |
treerow.setAttribute('isFile', isFile); // custom attribute to help with navigation |
202 |
treeitem.appendChild(treerow); |
203 |
// treecell addition
|
204 |
for (var i in data_array) { |
205 |
var treecell = document.createElement('treecell'); |
206 |
if(i == 0) { |
207 |
treecell.setAttribute('src', data_array[i]);
|
208 |
} else {
|
209 |
treecell.setAttribute('label', data_array[i]);
|
210 |
} |
211 |
treerow.appendChild(treecell); |
212 |
} |
213 |
} |
214 |
|
215 |
// initialisation
|
216 |
} |
217 |
|
218 |
function changetreefocus(event) { |
219 |
if (event.explicitOriginalTarget.id == 'tree-files-left') { |
220 |
document.getElementById('tree-files-right').focus();
|
221 |
} else {
|
222 |
document.getElementById('tree-files-left').focus();
|
223 |
} |
224 |
} |
225 |
|
226 |
function populatePopupMenuMultiple() { |
227 |
var milist = document.getElementById('treepopupmenu'); |
228 |
var selections = pithos_object.getSelectedResources();
|
229 |
|
230 |
if ( isWindows() && vfs.isLocalResource(selections[0]) ) { |
231 |
for ( i = 0; i < selections.length; i++ ) { |
232 |
selections[i] = replace_windows(selections[i]); |
233 |
} |
234 |
} |
235 |
|
236 |
while (milist.hasChildNodes()) {
|
237 |
milist.removeChild(milist.firstChild); |
238 |
} |
239 |
|
240 |
addItem('<Multiple Items>', ''); |
241 |
|
242 |
addSeparator(); |
243 |
|
244 |
addItem('Move to trash', 'movetotrash_context_menu_multiple(pithos_object.getSanitizedSelectedResources())'); |
245 |
addItem('Delete', 'delete_all_async(pithos_object.getSanitizedSelectedResources())'); |
246 |
|
247 |
function addSeparator() { |
248 |
var mi = document.createElement('menuseparator'); |
249 |
milist.appendChild(mi); |
250 |
} |
251 |
|
252 |
function addItem(item_label, item_action) { |
253 |
var mi = document.createElement('menuitem'); |
254 |
mi.setAttribute('label', item_label);
|
255 |
mi.setAttribute('onclick', item_action);
|
256 |
milist.appendChild(mi); |
257 |
} |
258 |
|
259 |
function replace_windows(uri) { |
260 |
var a = uri.split('\\'); |
261 |
var r = ""; |
262 |
|
263 |
for ( i = 0; i < a.length; i++ ) { |
264 |
if ( i == (a.length - 1) ) { |
265 |
r += a[i]; |
266 |
} else {
|
267 |
r += (a[i] + '\\\\');
|
268 |
} |
269 |
} |
270 |
|
271 |
return r;
|
272 |
} |
273 |
} |
274 |
|
275 |
function populatePopupMenu() { |
276 |
if ( pithos_object.getSelectedResources().length > 1 && pithos_object.getSourceCurrentDirectory() != connection_obj.user_homepage().trash) { |
277 |
populatePopupMenuMultiple(); |
278 |
return;
|
279 |
} |
280 |
|
281 |
var milist = document.getElementById('treepopupmenu'); |
282 |
var selection = pithos_object.getCurrentSelection();
|
283 |
var resource = vfs.getResourceMetadata(selection);
|
284 |
|
285 |
if ( isWindows() && vfs.isLocalResource(selection) ) {
|
286 |
selection = replace_windows(selection); |
287 |
} |
288 |
|
289 |
while (milist.hasChildNodes()) {
|
290 |
milist.removeChild(milist.firstChild); |
291 |
} |
292 |
|
293 |
// populate menupopup
|
294 |
if (vfs.isDirectory(selection)) {
|
295 |
addItem(resource.directoryName + " <folder>", ''); |
296 |
} else {
|
297 |
addItem(resource.name + " <file>", ''); |
298 |
} |
299 |
|
300 |
addSeparator(); |
301 |
|
302 |
if ( pithos_object.getSourceCurrentDirectory() == connection_obj.user_homepage().trash ) {
|
303 |
addItem('Undelete', "restore_context_menu_trash('" + selection + "')"); |
304 |
addItem('Purge', "delete_context_menu_trash('" + selection + "')"); |
305 |
addItem('Delete All', 'delete_all_async(pithos_object.getAllResources())'); |
306 |
} else {
|
307 |
if ( vfs.isRemoteResource(selection) ) {
|
308 |
if ( connection_obj.isShared(selection) ) {
|
309 |
addItem('Modify shares', "share_event('" + selection + "');"); |
310 |
addItem('Unshare', "unshare_event('" + selection + "');"); |
311 |
} else {
|
312 |
addItem('Share', "share_event('" + selection + "');"); |
313 |
} |
314 |
if ( vfs.isFile(selection) ) {
|
315 |
addItem('Modify tags', "modifytags_event('" + selection + "');"); |
316 |
if ( !resource.versioned ) {
|
317 |
addItem('Enable versioning', "enable_version_event('" + selection + "');"); |
318 |
} else {
|
319 |
addItem('Open version', "download_version_event('" + selection + "', " + resource.version + ");"); |
320 |
} |
321 |
} |
322 |
} |
323 |
|
324 |
addItem('Rename', "rename_context_menu('" + selection + "');"); |
325 |
if ( vfs.isRemoteResource(selection) ) {
|
326 |
addItem('Move to trash', "movetotrash_context_menu('" + selection + "');"); |
327 |
} |
328 |
addItem('Delete', "delete_context_menu('" + selection + "');"); |
329 |
} |
330 |
|
331 |
addSeparator(); |
332 |
|
333 |
if ( vfs.isLocalResource(selection) && vfs.isFile(selection) ) {
|
334 |
addItem('Launch', "launch_local_resource('" + selection + "');"); |
335 |
} |
336 |
addItem('Properties', "show_properties('" + selection + "');"); |
337 |
|
338 |
// helper functions
|
339 |
function addSeparator() { |
340 |
var mi = document.createElement('menuseparator'); |
341 |
milist.appendChild(mi); |
342 |
} |
343 |
|
344 |
function addItem(item_label, item_action) { |
345 |
var mi = document.createElement('menuitem'); |
346 |
mi.setAttribute('label', item_label);
|
347 |
mi.setAttribute('onclick', item_action);
|
348 |
milist.appendChild(mi); |
349 |
} |
350 |
|
351 |
function replace_windows(uri) { |
352 |
var a = uri.split('\\'); |
353 |
var r = ""; |
354 |
|
355 |
for ( i = 0; i < a.length; i++ ) { |
356 |
if ( i == (a.length - 1) ) { |
357 |
r += a[i]; |
358 |
} else {
|
359 |
r += (a[i] + '\\\\');
|
360 |
} |
361 |
} |
362 |
|
363 |
return r;
|
364 |
} |
365 |
} |
366 |
|
367 |
function select(event) { |
368 |
var tree_id = event.explicitOriginalTarget.id;
|
369 |
|
370 |
if ( event.keyCode == 0 ) { // VK_SPACE |
371 |
/*var tree_obj = pithos_object.getSourceTree();
|
372 |
var rowCount = tree_obj.view.rowCount;
|
373 |
var current_index = tree_obj.view.selection.currentIndex;
|
374 |
tree_obj.view.selection.isSelected
|
375 |
tree_obj.view.selection.select(current_index + 1);*/
|
376 |
} else if ( event.keyCode == 9 ) { // VK_TAB |
377 |
if ( tree_id == 'tree-files-left' ) { |
378 |
pithos_object.setTreeFocus('tree-files-right');
|
379 |
} else {
|
380 |
pithos_object.setTreeFocus('tree-files-left');
|
381 |
} |
382 |
} else if ( event.keyCode == 13 ) { // VK_ENTER |
383 |
if ( tree_id == 'tree-files-left' ) { |
384 |
pithos_object.navigateLeftTree(); |
385 |
} else {
|
386 |
pithos_object.navigateRightTree(); |
387 |
} |
388 |
} |
389 |
} |