Revision 46:f16f6e0e5b69 src/pithos/content/operations.js
b/src/pithos/content/operations.js | ||
---|---|---|
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 |
|
|
1 | 33 |
//////////////////////////////////// CREATE FOLDER ////////////////////////////////////////////////////////////// |
2 | 34 |
|
3 | 35 |
function create_folder_event() { |
4 | 36 |
var new_directory = window.prompt("Enter the directory name:", ""); |
5 | 37 |
var source_directory = pithos_object.getSourceCurrentDirectory(); |
6 | 38 |
if (new_directory == null) { |
7 |
alert('Directory creation canceled');
|
|
39 |
promptAlert('Directory creation canceled');
|
|
8 | 40 |
return; |
9 | 41 |
} else { |
10 | 42 |
if( create_folder(source_directory, new_directory) ) { |
11 |
alert(source_directory + new_directory + ' - created');
|
|
43 |
promptAlert(source_directory + new_directory + ' - created');
|
|
12 | 44 |
pithos_object.refreshLists(); |
13 | 45 |
} else { |
14 |
alert(source_directory + new_directory + ' - Directory creation failed');
|
|
46 |
promptAlert(source_directory + new_directory + ' - Directory creation failed');
|
|
15 | 47 |
} |
16 | 48 |
} |
17 | 49 |
} |
18 | 50 |
|
19 | 51 |
function create_folder(uri, new_directory) { |
20 |
if ( isRemoteDirectory(uri) ) {
|
|
52 |
if ( vfs.isRemoteResource(uri) ) {
|
|
21 | 53 |
var req = connection_obj.rest_request_post(uri, '?new=' + encodeURIComponent(new_directory), ''); |
22 | 54 |
return (connection_obj.success(req.status)); |
23 |
} else if ( isLocalDirectory(uri) ) {
|
|
55 |
} else if ( vfs.isLocalResource(uri) ) {
|
|
24 | 56 |
try { |
25 | 57 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
26 | 58 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
... | ... | |
47 | 79 |
var copied = 0; |
48 | 80 |
|
49 | 81 |
if (sources.length == 0) { |
50 |
alert('No Files/Folders are selected');
|
|
82 |
promptAlert('No Files/Folders are selected');
|
|
51 | 83 |
return; |
52 | 84 |
} |
53 | 85 |
|
54 | 86 |
if ( sources.length > 1 ) { |
55 |
alert('Copy ' + sources.length + ' items to ' + destination);
|
|
87 |
promptAlert('Copy ' + sources.length + ' items to ' + destination);
|
|
56 | 88 |
} else if (sources.length == 1) { |
57 |
alert('Copy ' + sources[0] + ' to ' + destination);
|
|
89 |
promptAlert('Copy ' + sources[0] + ' to ' + destination);
|
|
58 | 90 |
} |
59 | 91 |
|
60 | 92 |
for ( i = 0; i < sources.length; i++ ) { |
61 | 93 |
if ( vfs.isDirectory(sources[i]) ) { |
62 |
alert('Copy of directories is not supported!'); |
|
63 |
continue; |
|
64 |
} |
|
65 |
|
|
66 |
if ( !copy(sources[i], destination) ) { |
|
67 |
alert('Could not copy - ' + sources[i] + '. Copy canceled!'); |
|
68 |
return; |
|
69 |
} else { |
|
70 |
copied++; |
|
94 |
promptAlert('Copy of directories is not supported! Operation Canceled.'); |
|
95 |
return; |
|
71 | 96 |
} |
72 | 97 |
} |
98 |
|
|
99 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
100 |
window.openDialog("dialogs/operation_dialog.xul", "Copy Files", "chrome,resizable,centerscreen,window", "copy", sources, destination); |
|
101 |
|
|
73 | 102 |
pithos_object.refreshLists(); |
74 |
alert('Copied ' + copied + ' file(s) (total: ' + sources.length + ')'); |
|
75 | 103 |
} |
76 | 104 |
|
77 | 105 |
function copy(source, destination) { |
... | ... | |
87 | 115 |
|
88 | 116 |
return connection_obj.success(req.status); |
89 | 117 |
} else if ( vfs.isLocalResource(source) && vfs.isRemoteResource(destination) ) { |
90 |
var req = connection_obj.rest_request_put_upload(source, destination + encodeURIComponent(source_metadata.name), data, mimes.getByExtension(source_metadata.name));
|
|
118 |
var req = connection_obj.rest_request_put_upload(source, destination + source_metadata.name, data, mimes.getByExtension(source_metadata.name));
|
|
91 | 119 |
|
92 | 120 |
return connection_obj.success(req.status); |
93 | 121 |
} else if ( vfs.isRemoteResource(source) && vfs.isLocalResource(destination) ) { |
... | ... | |
127 | 155 |
function move_event() { |
128 | 156 |
var sources = pithos_object.getSelectedResources(); |
129 | 157 |
var destination = pithos_object.getDestinationCurrentDirectory(); |
130 |
var moved = 0; |
|
131 | 158 |
|
132 | 159 |
if (sources.length == 0) { |
133 |
alert('No Files/Folders are selected');
|
|
160 |
promptAlert('No Files/Folders are selected');
|
|
134 | 161 |
return; |
135 | 162 |
} |
136 | 163 |
|
137 | 164 |
for ( i = 0; i < sources.length; i++ ) { |
138 | 165 |
if ( vfs.isDirectory(sources[i]) ) { |
139 |
alert('Moving directories is not supported!');
|
|
166 |
promptAlert('Moving directories is not supported!');
|
|
140 | 167 |
continue; |
141 | 168 |
} |
142 | 169 |
|
143 |
if ( !move(sources[i], destination) ) { |
|
144 |
alert('Move failed (' + sources[i] + ')'); |
|
145 |
return; |
|
146 |
} else { |
|
147 |
moved++; |
|
148 |
} |
|
149 | 170 |
} |
171 |
|
|
172 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
173 |
window.openDialog("dialogs/operation_dialog.xul", "Move Files", "chrome,resizable,centerscreen,window", "move", sources, destination); |
|
150 | 174 |
|
151 | 175 |
pithos_object.refreshLists(); |
152 |
alert('Moved ' + moved + ' file(s) (total: ' + sources.length + ')'); |
|
153 | 176 |
} |
154 | 177 |
|
155 | 178 |
function move(source, destination) { |
... | ... | |
184 | 207 |
|
185 | 208 |
////////////////////////////////////////////////////// DELETE ///////////////////////////////////////////////////////////////////// |
186 | 209 |
|
210 |
function delete_all_async(uris) { |
|
211 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
212 |
window.openDialog("dialogs/operation_dialog.xul", "Delete Files", "chrome,resizable,centerscreen,window", "delete_all", uris); |
|
213 |
pithos_object.refreshLists(); |
|
214 |
} |
|
215 |
|
|
187 | 216 |
function delete_context_menu(uri) { |
188 | 217 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
189 | 218 |
var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); |
190 | 219 |
var result = prompt.confirm(window, "Confirm action", "Delete " + uri + "?"); |
191 | 220 |
if ( result ) { |
192 | 221 |
if ( !delete_resource(uri) ) { |
193 |
alert('Cannot delete ' + uri);
|
|
222 |
promptAlert('Cannot delete ' + uri);
|
|
194 | 223 |
return; |
195 | 224 |
} |
196 | 225 |
} else { |
197 |
alert('Action canceled');
|
|
226 |
promptAlert('Action canceled');
|
|
198 | 227 |
return; |
199 | 228 |
} |
200 | 229 |
pithos_object.refreshLists(); |
... | ... | |
204 | 233 |
var resources = pithos_object.getSelectedResources(); |
205 | 234 |
|
206 | 235 |
if (resources.length == 0) { |
207 |
alert('No File/Directory is selected');
|
|
236 |
promptAlert('No File/Directory is selected');
|
|
208 | 237 |
return; |
209 | 238 |
} |
210 | 239 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
... | ... | |
217 | 246 |
if (!b) { |
218 | 247 |
b = prompt.confirm(window, "Failed!", "Deletion of " + resources[i] + " failed. Continue?"); |
219 | 248 |
if (!b) { |
220 |
alert('Action canceled');
|
|
249 |
promptAlert('Action canceled');
|
|
221 | 250 |
return; |
222 | 251 |
} |
223 | 252 |
} |
224 | 253 |
} |
225 | 254 |
} else { |
226 |
alert('Action canceled');
|
|
255 |
promptAlert('Action canceled');
|
|
227 | 256 |
return; |
228 | 257 |
} |
229 |
alert('Removed ' + resources.length + ' items.'); |
|
258 |
promptAlert('Removed ' + resources.length + ' items.'); |
|
259 |
pithos_object.refreshLists(); |
|
260 |
} |
|
261 |
|
|
262 |
function delete_context_menu_trash(uri) { |
|
263 |
if(promptBox('Realy delete ' + uri)) { |
|
264 |
if ( delete_resource(uri) ) { |
|
265 |
promptAlert(uri + ' purged'); |
|
266 |
} |
|
267 |
} else { |
|
268 |
promptAlert('Purge canceled'); |
|
269 |
} |
|
230 | 270 |
pithos_object.refreshLists(); |
231 | 271 |
} |
232 | 272 |
|
233 | 273 |
function delete_resource(uri) { |
234 |
if ( isRemoteDirectory(uri) ) {
|
|
274 |
if ( vfs.isRemoteResource(uri) ) {
|
|
235 | 275 |
var req = connection_obj.rest_request_delete(uri, '?trash=', ''); |
236 | 276 |
return connection_obj.success(req.status); |
237 |
} else if ( isLocalDirectory(uri) ) {
|
|
277 |
} else if ( vfs.isLocalResource(uri) ) {
|
|
238 | 278 |
try { |
239 | 279 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
240 | 280 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
... | ... | |
260 | 300 |
var result = prompt.confirm(window, "Confirm action", "Delete " + uri + "?"); |
261 | 301 |
if ( result ) { |
262 | 302 |
if ( !movetotrash_resource(uri) ) { |
263 |
alert('Cannot delete ' + uri);
|
|
303 |
promptAlert('Cannot delete ' + uri);
|
|
264 | 304 |
return; |
265 | 305 |
} |
266 | 306 |
} else { |
267 |
alert('Action canceled');
|
|
307 |
promptAlert('Action canceled');
|
|
268 | 308 |
return; |
269 | 309 |
} |
270 | 310 |
pithos_object.refreshLists(); |
271 | 311 |
} |
272 | 312 |
|
273 | 313 |
function movetotrash_resource(uri) { |
274 |
if ( isRemoteDirectory(uri) ) {
|
|
314 |
if ( vfs.isRemoteResource(uri) ) {
|
|
275 | 315 |
var req = connection_obj.rest_request_post(uri, '?trash=', ''); |
276 | 316 |
return connection_obj.success(req.status); |
277 |
} else if ( isLocalDirectory(uri) ) {
|
|
317 |
} else if ( vfs.isLocalResource(uri) ) {
|
|
278 | 318 |
try { |
279 | 319 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
280 | 320 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
... | ... | |
308 | 348 |
// Create a parameter list |
309 | 349 |
var params = { inp: source, out: null }; |
310 | 350 |
|
311 |
window.openDialog("share/addshare.xul", "Share item", "chrome,dialog,modal,resizable",params);
|
|
351 |
window.openDialog("share/addshare.xul", "Share item", "chrome,dialog,resizable,centerscreen",params);
|
|
312 | 352 |
connection_obj.get_shared_data(); |
313 | 353 |
pithos_object.refreshLists(); |
314 | 354 |
} |
... | ... | |
348 | 388 |
connection_obj.get_shared_data(); |
349 | 389 |
pithos_object.refreshLists(); |
350 | 390 |
} else { |
351 |
alert('Unshare failed');
|
|
391 |
promptAlert('Unshare failed');
|
|
352 | 392 |
} |
353 | 393 |
} else { |
354 |
alert('Unshare process canceled');
|
|
394 |
promptAlert('Unshare process canceled');
|
|
355 | 395 |
} |
356 | 396 |
} |
357 | 397 |
|
... | ... | |
397 | 437 |
var new_name = window.prompt("Enter the new name:", ""); |
398 | 438 |
if ( new_name != null ) { |
399 | 439 |
if ( !rename_resource(uri, new_name) ) { |
400 |
alert('Cannot rename ' + uri + ' to ' + new_name);
|
|
440 |
promptAlert('Cannot rename ' + uri + ' to ' + new_name);
|
|
401 | 441 |
return; |
402 | 442 |
} |
403 | 443 |
} else { |
404 |
alert('Action canceled');
|
|
444 |
promptAlert('Action canceled');
|
|
405 | 445 |
} |
406 | 446 |
pithos_object.refreshLists(); |
407 | 447 |
} |
408 | 448 |
|
409 | 449 |
function rename_resource(uri, new_name) { |
410 |
if ( isRemoteDirectory(uri) ) {
|
|
450 |
if ( vfs.isRemoteResource(uri) ) {
|
|
411 | 451 |
var update = new Object(); |
412 | 452 |
if ( vfs.isFile(uri) ) { |
413 | 453 |
update.name = new_name; |
... | ... | |
416 | 456 |
} |
417 | 457 |
var req = connection_obj.rest_request_post(uri, '?update=', jsonToString(update)); |
418 | 458 |
return (connection_obj.success(req.status)); |
419 |
} else if ( isLocalDirectory(uri) ) {
|
|
459 |
} else if ( vfs.isLocalResource(uri) ) {
|
|
420 | 460 |
try { |
421 | 461 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
422 | 462 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
... | ... | |
459 | 499 |
|
460 | 500 |
function enable_version_event(uri) { |
461 | 501 |
if ( vfs.isLocalResource(uri) ) { |
462 |
alert('Cannot enable versioning in local files');
|
|
502 |
promptAlert('Cannot enable versioning in local files');
|
|
463 | 503 |
return; |
464 | 504 |
} |
465 | 505 |
if ( enable_version_resource(uri) ) { |
466 |
alert('File versioning is enabled');
|
|
506 |
promptAlert('File versioning is enabled');
|
|
467 | 507 |
} else { |
468 |
alert('Could not enable file versioning for ' + uri);
|
|
508 |
promptAlert('Could not enable file versioning for ' + uri);
|
|
469 | 509 |
} |
470 | 510 |
} |
471 | 511 |
|
... | ... | |
482 | 522 |
} |
483 | 523 |
|
484 | 524 |
function download_version_event(uri, current_version) { |
485 |
var version = window.prompt("Download version:", current_version); |
|
486 |
if (version != null) { |
|
487 |
if ( (new Number(version) >= 1) && (new Number(version) <= current_version) ) { |
|
488 |
var local_url = connection_obj.create_request_get(uri) + '&version=' + version; |
|
525 |
//var version = window.prompt("Download version:", current_version); |
|
526 |
var versions = new Array(); |
|
527 |
var outChoice = new Object(); |
|
528 |
|
|
529 |
for ( i = 0; i < current_version; i++ ) { |
|
530 |
versions.push(i + 1); |
|
531 |
} |
|
532 |
|
|
533 |
if (promptSelect('Open Resource', 'Download version:', versions, outChoice)) { |
|
534 |
var version_number = new Number(versions[outChoice.value]); |
|
535 |
if ( (version_number >= 1) && (version_number <= current_version) ) { |
|
536 |
var local_url = connection_obj.create_request_get(uri) + '&version=' + version_number; |
|
489 | 537 |
window.open(local_url); |
490 | 538 |
} else { |
491 |
alert('Invalid version number (' + version + '). Available versions: 1 ... ' + current_version);
|
|
539 |
promptAlert('Invalid version number (' + version_number + '). Available versions: 1 ... ' + current_version);
|
|
492 | 540 |
} |
493 | 541 |
} else { |
494 |
alert('Action canceled');
|
|
542 |
promptAlert('Action canceled');
|
|
495 | 543 |
} |
496 | 544 |
} |
497 | 545 |
|
498 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
546 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
547 |
|
|
548 |
////////////////////////////////////////////////// UNDELETE /////////////////////////////////////////////////////////////////////////////// |
|
549 |
|
|
550 |
function restore_context_menu_trash(uri) { |
|
551 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
552 |
|
|
553 |
var theuri = uri; |
|
554 |
var theobj = vfs.getResourceMetadata(theuri); |
|
555 |
|
|
556 |
// Set the metadata delete property to false (i.e. not deleted) |
|
557 |
theobj.deleted = false; |
|
558 |
|
|
559 |
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); |
|
560 |
var theitem_with_path = ''; |
|
561 |
|
|
562 |
if (theobj.hasOwnProperty('directoryName')) { |
|
563 |
theitem_with_path = theobj.parentFolder + '/' + theobj.directoryName; |
|
564 |
theitem_with_path = theitem_with_path.replace(connection_obj.user_homepage().fileroot, ""); |
|
565 |
} else { |
|
566 |
theitem_with_path = theobj.path + theobj.name; |
|
567 |
} |
|
568 |
|
|
569 |
if (prompts.confirm(window, "Confirm action", "Are you sure you want to restore " + theitem_with_path + ' ?')) { |
|
570 |
// trim the trailing slash ... |
|
571 |
theuri = theuri.replace(/\/$/,''); |
|
572 |
if (restore_resource(theuri)) { |
|
573 |
promptAlert(theuri + ' succesfully restored'); |
|
574 |
pithos_object.refreshLists(); |
|
575 |
} else { |
|
576 |
promptAlert('Restoration of ' + theuri + ' failed'); |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
|
|
581 |
function restore_resource(uri) { |
|
582 |
var retcode = connection_obj.rest_request_post(uri,'?restore=', ''); |
|
583 |
return connection_obj.success(retcode.status); |
|
584 |
} |
|
585 |
|
|
586 |
|
|
587 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff