Statistics
| Branch: | Revision:

root / src / pithos / content / dialogs / operation_dialog.js @ 46:f16f6e0e5b69

History | View | Annotate | Download (4.8 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
var current_request = null;
34

    
35
function init() {
36
        connection_obj = new ConnectionObject();
37
        mimes = new Mimes();
38
        cache = new FileCache();
39
        vfs = new VFS();
40
        var operation = window.arguments[0];
41
        var uris = window.arguments[1];           
42
        if ( operation == 'delete_all' ) {
43
            delete_all_resources(uris);
44
        } else if ( operation == 'copy' ) {
45
                var destination = window.arguments[2];
46
                copy_resources(uris, destination);
47
        } else if ( operation == 'move' ) {
48
                var destination = window.arguments[2];
49
                move_resources(uris, destination);
50
        }
51
}
52

    
53
function update_status(message) {
54
    var l = document.getElementById('label-info');
55
    l.value = message;
56
    l.tooltipText = message;
57
}
58

    
59
function delete_all_resources(uris) {
60
    if (uris.length == 0) { return; }
61
    
62
    if( promptBox('Are you sure you want to delete forever the contents of the trash?') ) {
63
        for (var i = 0; i < uris.length; i++ ) {
64
            update_status('Deleting ... ' + uris[i]);
65
            if(!delete_resource(uris[i])) {
66
                if( !promptBox('Could not delete ' + uris[i] + '. Continue?') ) {
67
                    return;
68
                }
69
            }
70
            update_status('Succesfully deleted ... ' + uris[i]);
71
        }
72
    } else {
73
        promptAlert('Action Canceled');
74
    }
75
    window.close();
76
}
77

    
78
function copy_resources(uris, destination) {
79
        if (uris.length == 0) { return; }
80
        
81
        for (var i = 0; i < uris.length; i++) {
82
                update_status('Copying ... ' + uris[i] + ' -> ' + destination);
83
                if ( !copy(uris[i], destination) ) {
84
                        if ( !promptBox('Cannot copy ' + uris[i] + '. Continue?') ) {
85
                                return;
86
                        }
87
                }
88
                update_status('Succesfull Copy of ' + uris[i]);
89
        }
90
        
91
        window.close();
92
}
93

    
94
function move_resources(uris, destination) {
95
        if (uris.length == 0) { return; }
96
        
97
        for (var i = 0; i < uris.length; i++) {
98
                update_status('Copying ... ' + uris[i] + ' -> ' + destination);
99
                if ( !copy(uris[i], destination) ) {
100
                        if ( !promptBox('Cannot copy ' + uris[i] + '. Continue?') ) {
101
                                return;
102
                        }
103
                }
104
                update_status('Succesfull Copy of ' + uris[i]);
105
                if (!delete_resource(uris[i])) {
106
                        if ( !promptBox('Cannot delete ' + uris[i] + '. Continue?') ) {
107
                                return;
108
                        }
109
                }
110
                update_status(uris[i] + ' deleted.');
111
        }
112
        
113
        window.close();
114
}
115

    
116
function abort() {
117
    if (current_request != null) {
118
        // abort
119
    }
120
    window.close();
121
}
122

    
123
function promptBox(message) {
124
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
125
    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
126
    var result = prompts.confirm(window, "Confirm action", message);
127
    
128
    return result;
129
}
130

    
131
// This is just an alert box, using the prompt xpcom service
132
function promptAlert(message) {
133
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
134
    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
135
    prompts.alert(window, "Information", message);
136
}