~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to deluge/ui/webui/templates/ajax/static/js/deluge-bars.js

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Script: deluge-bars.js
3
 
    Contains the various bars (Sidebar, Toolbar, Statusbar) used within Deluge.
4
 
 
5
 
 *
6
 
 * Copyright (C) Damien Churchill 2008 <damoxc@gmail.com>
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 3, or (at your option)
11
 
 * any later version.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program.  If not, write to:
20
 
 *     The Free Software Foundation, Inc.,
21
 
 *     51 Franklin Street, Fifth Floor
22
 
 *     Boston, MA  02110-1301, USA.
23
 
#
24
 
#    In addition, as a special exception, the copyright holders give
25
 
#    permission to link the code of portions of this program with the OpenSSL
26
 
#    library.
27
 
#    You must obey the GNU General Public License in all respects for all of
28
 
#    the code used other than OpenSSL. If you modify file(s) with this
29
 
#    exception, you may extend this exception to your version of the file(s),
30
 
#    but you are not obligated to do so. If you do not wish to do so, delete
31
 
#    this exception statement from your version. If you delete this exception
32
 
#    statement from all source files in the program, then also delete it here.
33
 
#
34
 
 
35
 
 *
36
 
 
37
 
 
38
 
    Class: Deluge.Widgets.Toolbar
39
 
        Manages the top toolbar handling clicks and actions.
40
 
 
41
 
    Example:
42
 
        toolbar = new Deluge.Widgets.Toolbar();
43
 
 
44
 
    Returns:
45
 
        An instance of the class wrapped about the toolbar.
46
 
*/
47
 
 
48
 
Deluge.Widgets.Toolbar = new Class({
49
 
    Implements: Events,
50
 
    Extends: Widgets.Base,
51
 
 
52
 
    initialize: function() {
53
 
        this.parent($('toolbar'));
54
 
        this.buttons = this.element.getFirst();
55
 
        this.buttons.getElements('li').each(function(el) {
56
 
            el.addEvent('click', function(e) {
57
 
                e.action = el.id;
58
 
                this.fireEvent('buttonClick', e);
59
 
            }.bind(this));
60
 
        }, this);
61
 
    }
62
 
});
63
 
 
64
 
 
65
 
/*
66
 
    Class: Deluge.Widgets.StatusBar
67
 
        Class to manage the bottom status bar
68
 
 
69
 
    Example:
70
 
        status = new Deluge.Widgets.StatusBar();
71
 
 
72
 
    Returns:
73
 
        An instance of the class wrapped about the status div
74
 
*/
75
 
Deluge.Widgets.StatusBar = new Class({
76
 
    Extends: Widgets.Base,
77
 
 
78
 
    initialize: function() {
79
 
        this.parent($('status'));
80
 
        this.bound = {
81
 
            onContextMenu: this.onContextMenu.bindWithEvent(this)
82
 
        };
83
 
 
84
 
        this.element.getElements('li').each(function(el) {
85
 
            this[el.id] = el;
86
 
        }, this);
87
 
        this.incoming_connections.setStyle('display', 'none');
88
 
 
89
 
        this.connections.addEvent('contextmenu', this.bound.onContextMenu);
90
 
        var menu = new Widgets.PopupMenu();
91
 
        menu.add(Deluge.Menus.Connections);
92
 
        menu.addEvent('action', this.onMenuAction);
93
 
        this.connections.store('menu', menu);
94
 
 
95
 
        this.downspeed.addEvent('contextmenu', this.bound.onContextMenu);
96
 
        menu = new Widgets.PopupMenu();
97
 
        menu.add(Deluge.Menus.Download);
98
 
        menu.addEvent('action', this.onMenuAction);
99
 
        this.downspeed.store('menu', menu);
100
 
 
101
 
        this.upspeed.addEvent('contextmenu', this.bound.onContextMenu);
102
 
        menu = new Widgets.PopupMenu();
103
 
        menu.add(Deluge.Menus.Upload);
104
 
        menu.addEvent('action', this.onMenuAction);
105
 
        this.upspeed.store('menu', menu);
106
 
    },
107
 
 
108
 
    /*
109
 
        Property: update
110
 
            Takes thes stats part of the update_ui rpc call and
111
 
            performs the required changes on the statusbar.
112
 
 
113
 
        Arguments:
114
 
            stats - A dictionary of the returned stats
115
 
 
116
 
        Example:
117
 
            statusbar.update(data['stats']);
118
 
    */
119
 
    update: function(stats) {
120
 
        this.connections.set('text', stats.num_connections + ' (' + stats.max_num_connections + ')');
121
 
        this.downspeed.set('text', stats.download_rate.toSpeed() + ' (' + stats.max_download + ' KiB/s)');
122
 
        this.upspeed.set('text', stats.upload_rate.toSpeed() + ' (' + stats.max_upload + ' KiB/s)');
123
 
        this.dht.set('text', stats.dht_nodes);
124
 
        this.free_space.set('text', stats.free_space.toBytes());
125
 
        if (stats.has_incoming_connections) {
126
 
            this.incoming_connections.setStyle('display', 'none');
127
 
        } else {
128
 
            this.incoming_connections.setStyle('display', 'inline');
129
 
        }
130
 
    },
131
 
 
132
 
    /*
133
 
        Property: onContextMenu
134
 
            Event handler for when certain parts of the statusbar have been
135
 
            right clicked.
136
 
 
137
 
        Arguments:
138
 
            e - The event args
139
 
 
140
 
        Example:
141
 
            el.addEvent('contextmenu', this.onContextMenu.bindWithEvent(this));
142
 
    */
143
 
    onContextMenu: function(e) {
144
 
        e.stop();
145
 
        var menu = e.target.retrieve('menu');
146
 
        if (menu) menu.show(e);
147
 
    },
148
 
 
149
 
    /*
150
 
        Property: onMenuAction
151
 
            Event handler for when an item in one of the menus is clicked.
152
 
            Note that it does not need to be bound as it doesn't use `this`
153
 
            anywhere within the method.
154
 
 
155
 
        Arguments:
156
 
            e - The event args
157
 
 
158
 
        Example:
159
 
            menu.addEvent('action', this.onMenuAction);
160
 
    */
161
 
    onMenuAction: function(e) {
162
 
        if (e.action == 'max_connections') e.action = 'max_connections_global';
163
 
        config = {}
164
 
        config[e.action] = e.value;
165
 
        Deluge.Client.set_config(config);
166
 
        Deluge.UI.update();
167
 
    }
168
 
});
169
 
 
170
 
 
171
 
/*
172
 
    Class: Deluge.Wdigets.Labels
173
 
        Class to manage the filtering labels in the sidebar
174
 
 
175
 
    Example:
176
 
        labels = new Deluge.Widgets.Labels();
177
 
 
178
 
    Returns:
179
 
        An instance of the class wrapped about the labels div
180
 
*/
181
 
Deluge.Widgets.Labels = new Class({
182
 
 
183
 
    Extends: Widgets.Base,
184
 
 
185
 
    initialize: function() {
186
 
        this.parent($('labels'));
187
 
        this.bound = {
188
 
            labelClicked: this.labelClicked.bindWithEvent(this)
189
 
        };
190
 
        this.filters = {};
191
 
    },
192
 
 
193
 
    /*
194
 
        Property: update
195
 
            Takes thes filters part of the update_ui rpc call and
196
 
            performs the required changes on the filtering
197
 
 
198
 
        Arguments:
199
 
            filters - A dictionary of the available filters
200
 
 
201
 
        Example:
202
 
            labels.update({'state': [['All', '3'], ['Downloading', '2']]);
203
 
    */
204
 
    update: function(filters) {
205
 
        $each(filters, function(values, name) {
206
 
            if ($defined(this.filters[name])) {
207
 
                this.filters[name].update(values);
208
 
            } else {
209
 
                this.filters[name] = new Deluge.Widgets.LabelSection(name);
210
 
                this.filters[name].addEvent('labelClicked', this.bound.labelClicked);
211
 
                this.element.grab(this.filters[name]);
212
 
                this.filters[name].update(values);
213
 
                if (!this.filterType && !this.filterName) {
214
 
                    var el = this.filters[name].list.getElements('li')[0];
215
 
                    this.currentFilter = el;
216
 
                    this.filterType = name;
217
 
                    this.filterName = el.retrieve('filterName');
218
 
                    this.currentFilter.addClass('activestate');
219
 
                }
220
 
            }
221
 
        }, this);
222
 
    },
223
 
 
224
 
    /*
225
 
        Property: labelClicked
226
 
 
227
 
        Arguments:
228
 
            e - The event args
229
 
 
230
 
        Example:
231
 
            labelSection.addEvent('labelClicked', this.bound.labelClicked);
232
 
    */
233
 
    labelClicked: function(e) {
234
 
        this.currentFilter.removeClass('activestate');
235
 
        this.filterType = e.name;
236
 
        this.filterName = e.filter;
237
 
        this.currentFilter = e.target;
238
 
        e.target.addClass('activestate');
239
 
        this.fireEvent('filterChanged');
240
 
    }
241
 
});
242
 
 
243
 
/*
244
 
    Class: Deluge.Widgets.LabelSection
245
 
        Class to manage a section of filters within the labels block
246
 
 
247
 
    Arguments:
248
 
        string (the name of the section)
249
 
 
250
 
    Returns:
251
 
        A widget with the ability to manage the filters
252
 
*/
253
 
Deluge.Widgets.LabelSection = new Class({
254
 
 
255
 
    Extends: Widgets.Base,
256
 
 
257
 
    regex: /([\w]+)\s\((\d)\)/,
258
 
 
259
 
    initialize: function(name) {
260
 
        this.parent(new Element('div'));
261
 
        this.name = name;
262
 
        this.bound = {
263
 
            'clicked': this.clicked.bindWithEvent(this)
264
 
        }
265
 
 
266
 
        name = name.replace('_', ' ');
267
 
        parts = name.split(' ');
268
 
        name = '';
269
 
        parts.each(function(part) {
270
 
            firstLetter = part.substring(0, 1);
271
 
            firstLetter = firstLetter.toUpperCase();
272
 
            part = firstLetter + part.substring(1);
273
 
            name += part + ' ';
274
 
        });
275
 
 
276
 
        this.header = new Element('h3').set('text', name);
277
 
        this.list = new Element('ul');
278
 
 
279
 
        this.element.grab(this.header);
280
 
        this.element.grab(this.list);
281
 
    },
282
 
 
283
 
    /*
284
 
        Property: update
285
 
            Updates the filters list
286
 
 
287
 
        Arguments:
288
 
            values - a list of name/count values for the filters
289
 
 
290
 
        Example:
291
 
            labelSection.update([['All', '3'], ['Downloading', '2']]);
292
 
    */
293
 
    update: function(values) {
294
 
        names = new Array();
295
 
        $each(values, function(value) {
296
 
            var name = value[0], count = value[1], lname = name.toLowerCase();
297
 
            lname = lname.replace('.', '_');
298
 
            names.include(lname);
299
 
            var el = this.list.getElement('li.' + lname);
300
 
            if (!el) {
301
 
                el = new Element('li').addClass(lname);
302
 
                el.store('filterName', name)
303
 
                el.addEvent('click', this.bound.clicked);
304
 
                if (this.name == 'tracker_host') {
305
 
                    var icon = 'url(/tracker/icon/' + name + ')';
306
 
                    el.setStyle('background-image', icon);
307
 
                };
308
 
                this.list.grab(el);
309
 
            }
310
 
            el.set('text', name + ' (' + count +')');
311
 
        }, this);
312
 
 
313
 
        // Clean out any labels that are no longer returned
314
 
        this.list.getElements('li').each(function(el) {
315
 
            var hasName = false;
316
 
            names.each(function(name) {
317
 
                if (hasName) return;
318
 
                hasName = el.hasClass(name);
319
 
            });
320
 
 
321
 
            if (!hasName) {
322
 
                el.destroy();
323
 
            }
324
 
        });
325
 
    },
326
 
 
327
 
    /*
328
 
        Property: clicked
329
 
            Event handler for when a list item is clicked
330
 
 
331
 
        Arguments:
332
 
            e - The event args
333
 
 
334
 
        Example:
335
 
            listItem.addEvent('click', this.clicked.bindWithEvent(this));
336
 
    */
337
 
    clicked: function(e) {
338
 
        e.filter = e.target.retrieve('filterName');
339
 
        e.name = this.name
340
 
        this.fireEvent('labelClicked', e);
341
 
    }
342
 
});