hugely improve the labels bar and disable filtering until i fix the grid

This commit is contained in:
Damien Churchill 2008-09-27 17:11:02 +00:00
parent 80659e882e
commit 04abf85433
2 changed files with 118 additions and 69 deletions

View File

@ -46,77 +46,126 @@ Deluge.Widgets.Labels = new Class({
Extends: Widgets.Base, Extends: Widgets.Base,
regex: /([\w]+)\s\((\d)\)/,
initialize: function() { initialize: function() {
this.parent($('labels')) this.parent($('labels'));
this.bound = { this.bound = {
resized: this.resized.bindWithEvent(this), labelClicked: this.labelClicked.bindWithEvent(this)
clickedState: this.clickedState.bindWithEvent(this) };
} this.filters = {};
this.list = new Element('ul')
this.element.grab(this.list)
this.addStates()
this.state = 'All'
this.islabels = false;
this.addEvent('resize', this.resized)
}, },
addStates: function() { labelClicked: function(e) {
this.list.grab(new Element('li').set('text', 'All').addClass('all').addClass('activestate')) this.currentFilter.removeClass('activestate');
this.list.grab(new Element('li').set('text', 'Downloading').addClass('downloading')) this.filterType = e.filter;
this.list.grab(new Element('li').set('text', 'Seeding').addClass('seeding')) this.filterName = e.name;
this.list.grab(new Element('li').set('text', 'Queued').addClass('queued')) this.currentFilter = e.target;
this.list.grab(new Element('li').set('text', 'Paused').addClass('paused')) e.target.addClass('activestate');
this.list.grab(new Element('li').set('text', 'Error').addClass('error'))
this.list.grab(new Element('li').set('text', 'Checking').addClass('checking'))
this.list.grab(new Element('hr'))
},
addLabel: function(name) {
},
clickedState: function(e) {
if (this.islabels) {
var old = this.list.getElement('.' + this.state.toLowerCase())
old.removeClass('activestate')
this.state = e.target.get('text').match(/^(\w+)/)[1]
e.target.addClass('activestate')
this.fireEvent('stateChanged', this.state)
} else {
}
}, },
update: function(filters) { update: function(filters) {
if (filters.state.length == 1) $each(filters, function(values, name) {
this.updateNoLabels(filters); if ($defined(this.filters[name])) {
else this.filters[name].update(values);
this.updateLabels(filters) } else {
}, this.filters[name] = new Deluge.Widgets.LabelSection(name);
this.filters[name].addEvent('labelClicked', this.bound.labelClicked);
updateNoLabels: function(filters) { this.element.grab(this.filters[name]);
this.islabels = false; this.filters[name].update(values);
}, if (!this.filterType && !this.filterName) {
var el = this.filters[name].list.getElements('li')[0];
updateLabels: function(filters) { this.currentFilter = el;
this.islabels = true; this.filterType = name;
$each(filters.state, function(state) { this.filterName = el.retrieve('filterName');
var el = this.list.getElement('.' + state[0].toLowerCase()) this.currentFilter.addClass('activestate');
if (!el) return }
}
el.set('text', state[0] + ' (' + state[1] + ')') }, this);
el.removeEvent('click', this.bound.clickedState) }
el.addEvent('click', this.bound.clickedState) });
}, this)
}, /*
Class: Deluge.Widgets.LabelSection
resized: function(event) { Class to manage a section of filters within the labels block
var height = this.element.getInnerSize().y;
this.list.getSizeModifiers(); Arguments:
height -= this.list.modifiers.y; string (the name of the section)
this.list.setStyle('height', height)
Returns:
A widget with the ability to manage the filters
*/
Deluge.Widgets.LabelSection = new Class({
Extends: Widgets.Base,
regex: /([\w]+)\s\((\d)\)/,
initialize: function(name) {
this.parent(new Element('div'));
this.name = name;
this.bound = {
'clicked': this.clicked.bindWithEvent(this)
}
name = name.replace('_', ' ');
parts = name.split(' ');
name = '';
parts.each(function(part) {
firstLetter = part.substring(0, 1);
firstLetter = firstLetter.toUpperCase();
part = firstLetter + part.substring(1);
name += part + ' ';
});
this.header = new Element('h3').set('text', name);
this.list = new Element('ul');
this.element.grab(this.header);
this.element.grab(this.list);
},
/*
Property: update
Updates the filters list
Arguments:
values - a list of name/count values for the filters
Example:
labelSection.update([['All', '3'], ['Downloading', '2']]);
*/
update: function(values) {
names = new Array();
$each(values, function(value) {
var name = value[0], count = value[1], lname = name.toLowerCase();
lname = lname.replace('.', '_');
names.include(lname);
var el = this.list.getElement('li.' + lname);
if (!el) {
el = new Element('li').addClass(lname);
el.store('filterName', name)
el.addEvent('click', this.bound.clicked);
this.list.grab(el);
}
el.set('text', name + ' (' + count +')');
}, this);
// Clean out any labels that are no longer returned
this.list.getElements('li').each(function(el) {
var hasName = false;
names.each(function(name) {
if (hasName) return;
hasName = el.hasClass(name);
});
if (!hasName) {
el.destroy();
}
});
},
clicked: function(e) {
e.filter = e.target.retrieve('filterName');
e.name = this.name
this.fireEvent('labelClicked', e);
} }
}); });

View File

@ -135,17 +135,17 @@ Deluge.UI = {
}, },
update: function() { update: function() {
filter = {} filter = {};
if (this.labels.state != 'All') filter.state = this.labels.state //if (this.labels.state != 'All') filter['state'] = this.labels.state;
Deluge.Client.update_ui(Deluge.Keys.Grid, filter, { Deluge.Client.update_ui(Deluge.Keys.Grid, filter, {
onSuccess: this.bound.updated onSuccess: this.bound.updated
}) });
}, },
updated: function(data) { updated: function(data) {
this.torrents = new Hash(data.torrents); this.torrents = new Hash(data.torrents);
this.stats = data.stats; this.stats = data.stats;
this.filters = data.filters this.filters = data.filters;
this.torrents.each(function(torrent, torrent_id) { this.torrents.each(function(torrent, torrent_id) {
torrent.id = torrent_id; torrent.id = torrent_id;
}) })