From 80f151be9497be704534d389c69901c37b03ceef Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sun, 25 Apr 2010 19:07:26 +0100 Subject: [PATCH] move the state updating into the FilterPanel to allow for a custom show_zero value to be specified --- deluge/ui/web/js/deluge-all/FilterPanel.js | 47 +++++++++++++++++- deluge/ui/web/js/deluge-all/Sidebar.js | 55 +--------------------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/deluge/ui/web/js/deluge-all/FilterPanel.js b/deluge/ui/web/js/deluge-all/FilterPanel.js index dd7422313..53ab3b345 100644 --- a/deluge/ui/web/js/deluge-all/FilterPanel.js +++ b/deluge/ui/web/js/deluge-all/FilterPanel.js @@ -39,6 +39,8 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { border: false, + show_zero: null, + initComponent: function() { Deluge.FilterPanel.superclass.initComponent.call(this); this.filterType = this.initialConfig.filter; @@ -101,7 +103,50 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, { */ getStore: function() { return this.list.getStore(); - } + }, + + /** + * Update the states in the FilterPanel + */ + updateStates: function(states) { + var show_zero = (this.show_zero == null) ? deluge.config.sidebar_show_zero : this.show_zero; + if (!show_zero) { + var newStates = []; + Ext.each(states, function(state) { + if (state[1] > 0 || state[0] == _('All')) { + newStates.push(state); + } + }); + states = newStates; + } + + var store = this.getStore(); + var filters = {}; + Ext.each(states, function(s, i) { + var record = store.getById(s[0]); + if (!record) { + record = new store.recordType({ + filter: s[0], + count: s[1] + }); + record.id = s[0]; + store.insert(i, [record]); + } + record.beginEdit(); + record.set('filter', s[0]); + record.set('count', s[1]); + record.endEdit(); + filters[s[0]] = true; + }, this); + + store.each(function(record) { + if (filters[record.id]) return; + store.remove(record); + }, this); + + store.commitChanges(); + }, + }); Deluge.FilterPanel.templates = { diff --git a/deluge/ui/web/js/deluge-all/Sidebar.js b/deluge/ui/web/js/deluge-all/Sidebar.js index 0b533f357..9c2478c0c 100644 --- a/deluge/ui/web/js/deluge-all/Sidebar.js +++ b/deluge/ui/web/js/deluge-all/Sidebar.js @@ -77,12 +77,7 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { panel.on('selectionchange', function(view, nodes) { deluge.ui.update(); }); - - if (deluge.config.sidebar_show_zero == false) { - states = this.removeZero(states); - } - - panel.getStore().loadData(states); + panel.updateStates(states); this.add(panel); this.doLayout(); @@ -116,24 +111,11 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { deluge.ui.update(); }, - /** - * Remove the states with zero torrents in them. - */ - removeZero: function(states) { - var newStates = []; - Ext.each(states, function(state) { - if (state[1] > 0 || state[0] == _('All')) { - newStates.push(state); - } - }); - return newStates; - }, - update: function(filters) { for (var filter in filters) { var states = filters[filter]; if (Ext.getKeys(this.panels).indexOf(filter) > -1) { - this.updateFilter(filter, states); + this.panels[filter].updateStates(states); } else { this.createFilter(filter, states); } @@ -148,38 +130,5 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, { delete this.panels[filter]; } }, this); - }, - - updateFilter: function(filter, states) { - if (deluge.config.sidebar_show_zero == false) { - states = this.removeZero(states); - } - - var store = this.panels[filter].getStore(); - var filters = []; - Ext.each(states, function(s, i) { - var record = store.getById(s[0]); - if (!record) { - record = new store.recordType({ - filter: s[0], - count: s[1] - }); - record.id = s[0]; - store.insert(i, [record]); - } - record.beginEdit(); - record.set('filter', s[0]); - record.set('count', s[1]); - record.endEdit(); - filters[s[0]] = true; - }, this); - - store.each(function(record) { - if (filters[record.id]) return; - - store.remove(record); - }, this); - - store.commitChanges(); } });