Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (8.5 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');
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');
49
        window.openDialog("dialogs/file_properties.xul", "Trash", "chrome,modal,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
        
61
        // public functions
62
        
63
        this.populate = function(dir_obj) {
64
                while(current.children_tag.hasChildNodes()) {
65
                        current.children_tag.removeChild(current.children_tag.firstChild);
66
                }
67

    
68
                // add previous dir
69
                if(dir_obj.parentFolder != null) {
70
                        var a = new Array();
71

    
72
                        // Data for columns in the UI
73
                        a[0] = "../skin/up.png";
74
                        a[1] = "..";
75
                        a[2] = "<PARENT-DIR>";
76
                        a[3] = "";
77
                        a[4] = "";
78
                        
79
                        addData(dir_obj.parentFolder, a, false);
80
                }
81
                
82
                // add the following
83
                for (var fldr in dir_obj.folders) {
84
                        this.addFolder(dir_obj.folders[fldr]);
85
                }
86

    
87
                for (var fl in dir_obj.files) {
88
            // trash exception
89
            if ( dir_obj.URI == connection_obj.user_homepage().trash) {
90
                this.addFile(dir_obj.files[fl]);
91
            } else if(!dir_obj.files[fl].deleted) {
92
                                this.addFile(dir_obj.files[fl]);
93
                        }
94
                }
95
        }
96
        
97
        this.addFolder = function(folder_obj) {
98
                var a = new Array();
99
                
100
                a[0] = folder_obj.contentImage;
101
                a[1] = folder_obj.name;
102
                a[2] = "<DIRECTORY>";
103
                a[3] = "";
104
                a[4] = "";
105
                
106
                addData(folder_obj.URI, a, false);
107
        }
108
        
109
        this.addFile = function(file_obj) {
110
                var a = new Array();
111
                var d = new Date();
112
                d.setTime(file_obj.creationDate);
113
                
114
                a[0] = file_obj.contentImage;
115
                a[1] = file_obj.name;
116
                a[2] = format_number(file_obj.size);
117
                a[3] = d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear();
118
                a[4] = file_obj.version;
119
                
120
                addData(file_obj.URI, a, true);
121
        }
122
                
123
        // private functions        
124
        function addData(id, data_array, isFile) {
125
                var treeitem = document.createElement('treeitem');
126
                current.children_tag.appendChild(treeitem);
127
                
128
                // treerow addition
129
                var treerow = document.createElement('treerow');
130
        treerow.setAttribute('id', id);
131
                treerow.setAttribute('isFile', isFile); // custom attribute to help with navigation
132
                treeitem.appendChild(treerow);
133
                // treecell addition
134
                for (var i in data_array) {
135
                        var treecell = document.createElement('treecell');
136
                        if(i == 0) {
137
                                treecell.setAttribute('src', data_array[i]);
138
                        } else {
139
                                treecell.setAttribute('label', data_array[i]);
140
                        }
141
                        treerow.appendChild(treecell);
142
                }
143
        }
144
        
145
        // initialisation
146
}
147

    
148
function changetreefocus(event) {
149
        if (event.explicitOriginalTarget.id == 'tree-files-left') {
150
                document.getElementById('tree-files-right').focus();
151
        } else {
152
                document.getElementById('tree-files-left').focus();
153
        }
154
}
155

    
156
function populatePopupMenu(){
157
        var milist = document.getElementById('treepopupmenu');
158
        var selection = pithos_object.getCurrentSelection();    
159
        var resource = vfs.getResourceMetadata(selection);
160

    
161
    if ( isWindows() && vfs.isLocalResource(selection) ) {
162
        selection = replace_windows(selection);
163
    }
164

    
165
        while (milist.hasChildNodes()) {
166
                milist.removeChild(milist.firstChild);
167
        }
168
                
169
        // populate menupopup
170
        if (vfs.isDirectory(selection)) {
171
                addItem(resource.directoryName + " <folder>", '');
172
        } else {
173
                addItem(resource.name + " <file>", '');
174
        }
175
        
176
        addSeparator();
177

    
178
    if ( pithos_object.getSourceCurrentDirectory() == connection_obj.user_homepage().trash ) {
179
        addItem('Undelete', "restore_context_menu_trash('" + selection + "')");
180
        addItem('Purge', "delete_context_menu_trash('" + selection + "')");
181
        addItem('Delete All', 'delete_all_async(pithos_object.getAllResources())');
182
    } else {
183
        if ( vfs.isRemoteResource(selection) ) {
184
            if ( connection_obj.isShared(selection) ) {
185
                addItem('Modify shares', "share_event('" + selection + "');");
186
                addItem('Unshare', "unshare_event('" + selection + "');");
187
            } else {
188
                addItem('Share', "share_event('" + selection + "');");
189
            }
190
            if ( vfs.isFile(selection) ) {
191
                addItem('Modify tags', "modifytags_event('" + selection + "');");
192
                if ( !resource.versioned ) {
193
                    addItem('Enable versioning', "enable_version_event('" + selection + "');");
194
                } else {
195
                    addItem('Open version', "download_version_event('" + selection + "', " + resource.version + ");");
196
                }
197
            }
198
        }
199

    
200
        addItem('Rename', "rename_context_menu('" + selection + "');");
201
        if ( vfs.isRemoteResource(selection) ) {
202
            addItem('Move to trash', "movetotrash_context_menu('" + selection + "');");
203
        }
204
        addItem('Delete', "delete_context_menu('" + selection + "');");
205
    }
206

    
207
    addSeparator();
208

    
209
    if ( vfs.isLocalResource(selection) && vfs.isFile(selection) ) {
210
        addItem('Launch', "launch_local_resource('" + selection + "');");
211
    }
212
    addItem('Properties', "show_properties('" + selection + "');");
213
        
214
        // helper functions
215
        function addSeparator() {
216
                var mi = document.createElement('menuseparator');
217
                milist.appendChild(mi);
218
        }
219
        
220
        function addItem(item_label, item_action) {
221
                var mi = document.createElement('menuitem');
222
                mi.setAttribute('label', item_label);
223
                mi.setAttribute('onclick', item_action);
224
                milist.appendChild(mi);
225
        }
226

    
227
    function replace_windows(uri) {
228
        var a = uri.split('\\');
229
        var r = "";
230

    
231
        for ( i = 0; i < a.length; i++ ) {
232
            if ( i == (a.length - 1) ) {
233
                r += a[i];
234
            } else {
235
                r += (a[i] + '\\\\');
236
            }
237
        }
238

    
239
        return r;
240
    }    
241
}
242

    
243
function select(event) {
244
    var tree_id = event.explicitOriginalTarget.id;
245

    
246
        if ( event.keyCode == 0 ) { // VK_SPACE
247
                /*var tree_obj = pithos_object.getSourceTree();
248
                var rowCount = tree_obj.view.rowCount;
249
                var current_index = tree_obj.view.selection.currentIndex;
250
                tree_obj.view.selection.isSelected
251
                tree_obj.view.selection.select(current_index + 1);*/
252
        } else if ( event.keyCode == 9  ) { // VK_TAB
253
                if ( tree_id == 'tree-files-left' ) {
254
                        pithos_object.setTreeFocus('tree-files-right');
255
                } else {
256
                        pithos_object.setTreeFocus('tree-files-left');
257
                }
258
        } else if ( event.keyCode == 13 ) { // VK_ENTER
259
        if ( tree_id == 'tree-files-left' ) {
260
            pithos_object.navigateLeftTree();
261
        } else {
262
            pithos_object.navigateRightTree();
263
        }        
264
    }
265
}