Statistics
| Branch: | Revision:

root / src / pithos / content / pithos_object.js @ 33:116a091c338b

History | View | Annotate | Download (6.3 kB)

1
pithos_object = null;
2

    
3
function PithosObject() {
4
        // public properties
5
        
6
        // private properties
7
        var currentDirectoryRight = '';
8
        var currentDirectoryLeft = '';
9
        var left_panel = new TreeModel('treech-left');
10
        var right_panel = new TreeModel('treech-right');
11
        var left_tree = document.getElementById('tree-files-left');
12
        var right_tree = document.getElementById('tree-files-right');
13
        var combo_current_left = document.getElementById('currentdirectory-left');
14
        var combo_current_right = document.getElementById('currentdirectory-right');
15
        var fileroot = connection_obj.user_homepage().fileroot;
16
        var source_tree = left_tree;
17
        var destination_tree = right_tree;
18
        var source_tree_children = left_panel;
19
        var current = this;
20
        
21
        // public methods
22
        this.refreshLists = function() {
23
                if (isRemoteDirectory(this.getSelectedDirectoryLeft)) {
24
                        cache.remove(this.getSelectedDirectoryLeft());
25
                }
26
                if ( isRemoteDirectory(this.getSelectedDirectoryRight)) {
27
                        cache.remove(this.getSelectedDirectoryRight());        
28
                }
29
                
30
                this.navigateSelectedDirectoryLeft();
31
                this.navigateSelectedDirectoryRight();
32
        }
33
        
34
        this.getSelectedResources = function() {
35
                var results = new Array();
36
                var rowCount = source_tree.view.rowCount;
37
                
38
                for (i = 0; i < rowCount; i++) {
39
                        if (source_tree.view.selection.isSelected(i)) {
40
                                results.push(source_tree_children.children_tag.childNodes[i].childNodes[0].id);                                
41
                        }
42
                }
43
                
44
                return results;
45
        }
46
        
47
        this.getSourceCurrentDirectory = function() {
48
                if (this.getSourceTree().id == 'tree-files-left') {
49
                        return currentDirectoryLeft;
50
                } else {
51
                        return currentDirectoryRight;
52
                }
53
        }
54
        
55
        this.getDestinationCurrentDirectory = function() {
56
                if (this.getDestinationTree.id == 'tree-files-left') {
57
                        return currentDirectoryLeft;
58
                } else {
59
                        return currentDirectoryRight;
60
                }
61
        }
62
        
63
        this.setTreeFocus = function(tree_id) {
64
                if ( tree_id == 'tree-files-left' ) {
65
                        source_tree = left_tree;
66
                        destination_tree = right_tree;
67
                        source_tree_children = left_panel;
68
                } else {
69
                        source_tree = right_tree;
70
                        destination_tree = left_tree;
71
                        source_tree_children = right_panel;
72
                }
73
        }
74
        
75
        this.getSourceTree = function() {
76
                return source_tree;
77
        }
78
        
79
        this.getDestinationTree = function() {
80
                return destination_tree;
81
        }
82
                
83
        this.getSelectedDirectoryLeft = function() {
84
                return combo_current_left.parentNode.value;
85
        }
86
        
87
        this.getSelectedDirectoryRight = function() {
88
                return combo_current_right.parentNode.value;
89
        }
90
        
91
        this.navigateSelectedDirectoryLeft = function() {
92
                this.populateLeftTree(this.getSelectedDirectoryLeft());
93
        }
94
        
95
        this.navigateSelectedDirectoryRight = function() {
96
                this.populateRightTree(this.getSelectedDirectoryRight());
97
        }
98
        
99
        this.populateLeftTree = function(directory) {
100
                currentDirectoryLeft = directory;
101
                // combos
102
                initialize_current_directory(combo_current_left, directory);
103
                // populate left tree
104
                var fo = vfs.getDirectory(directory);
105
                left_panel.populate(fo);
106
        }
107
        
108
        this.populateRightTree = function(directory) {
109
                currentDirectoryRight = directory;
110
                // combos
111
                initialize_current_directory(combo_current_right, directory);
112
                // populate right tree
113
                var fo = vfs.getDirectory(directory);
114
                right_panel.populate(fo);
115
        }
116
        
117
        this.navigateLeftTree = function() {
118
                navigate(left_tree.currentIndex, left_panel.children_tag, this.populateLeftTree, true);
119
        }
120
        
121
        this.navigateRightTree = function() {
122
                navigate(right_tree.currentIndex, right_panel.children_tag, this.populateRightTree, true);
123
        }
124
        
125
        this.arrowNavigate = function() {
126
                navigate(source_tree.currentIndex, source_tree_children.children_tag, source_tree_children.populate, false);
127
        }
128
                
129
        // private methods
130
        function navigate(row, tree_children, populate_function, open_file) {
131
                if (row < 0) {
132
                        return;
133
                }
134
                
135
                var isFileStr = tree_children.childNodes[row].childNodes[0].attributes['isFile'].value;
136
                var path = tree_children.childNodes[row].childNodes[0].id;
137
                
138
                if (isFileStr != 'false') {
139
                        if (open_file) {
140
                                window.open(connection_obj.create_request_get(path));
141
                        }
142
                } else {
143
                        populate_function(path);
144
                }
145
        }
146
        
147
        function initialize_current_directory(list, directory) {
148
                // clear
149
                while(list.hasChildNodes()) {
150
                        list.removeChild(list.firstChild);
151
                }
152
                
153
                // if it is Root directory then, add it, 
154
                if ( isRootDirectory(directory) ) {
155
                        add_item(directory, directory);
156
                } else {
157
                        if ( isRemoteDirectory(directory) ) {
158
                                // remote code
159
                                var arr = getRemoteParentDirList(directory);
160
                                for ( i = 0; i < arr.length; i++ ) {
161
                                        add_item(arr[i], arr[i]);
162
                                }
163
                        } else {
164
                                // local code
165
                                var arr = getLocalParentDirList(directory);
166
                                for ( i = 0; i < arr.length; i++) {
167
                                        add_item(arr[i], arr[i]);
168
                                }
169
                        }
170
                }
171

    
172
                list.parentNode.selectedIndex = 0;
173

    
174
                function add_item(item_name, item_value) {
175
                        var menuitem = document.createElement("menuitem");
176
                        menuitem.setAttribute("label", item_name);
177
                        menuitem.setAttribute("value", item_value);
178
                        menuitem.setAttribute("crop", "left");
179
                        menuitem.setAttribute("tooltiptext", item_name);
180

    
181
                        list.appendChild(menuitem);
182
                }
183
        }
184
        
185
        // populate with menu items, local drives
186
        function initialize_menulist(list_id, navigate_command) {
187
                var list = document.getElementById(list_id);
188
                
189
                add_item("Remote - Home", fileroot, navigate_command.replace('[DIR]', fileroot));
190
                list.parentNode.selectedIndex = 0;
191
                
192
                if (isWindows()) {
193
                        var drives = getLocalDrives();
194
                
195
                        for ( i = 0;i < drives.length; i++ ) {
196
                                add_item("Local - " + drives[i], drives[i], navigate_command.replace('[DIR]', drives[i] + '\\'));
197
                        }
198
                }
199
                if (isUnix()) {
200
                        add_item("Local - Home", getHomeDirectory(), navigate_command.replace('[DIR]', getHomeDirectory()));
201
                }
202
                
203
                add_item("Remote - Others", connection_obj.user_homepage().others, navigate_command.replace('[DIR]', connection_obj.user_homepage().others));
204
        
205
                // inner functions
206
                function add_item(item_name, item_value, item_onclick) {
207
                        var menuitem = document.createElement("menuitem");
208
                        
209
                        menuitem.setAttribute("label", item_name);
210
                        menuitem.setAttribute("value", item_value);
211
                        menuitem.setAttribute("onclick", item_onclick);
212
                        list.appendChild(menuitem);
213
                }
214
        }
215
        
216
        // initialize
217
        // combos
218
        initialize_menulist("menupopup-left", "pithos_object.populateLeftTree('[DIR]');");
219
        initialize_menulist("menupopup-right", "pithos_object.populateRightTree('[DIR]');");
220

    
221
        this.populateLeftTree(fileroot);
222
        this.populateRightTree(fileroot);
223
        
224
        left_tree.focus();
225
}