add helper methods for adding and removing columns to the torrent status grid

This commit is contained in:
Damien Churchill 2010-04-26 00:10:10 +01:00
commit bfdaa47aff
2 changed files with 157 additions and 110 deletions

View file

@ -78,6 +78,49 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, {
enable: function() { enable: function() {
this.fireEvent("enable", this); this.fireEvent("enable", this);
if (this.onEnable) this.onEnable(); if (this.onEnable) this.onEnable();
},
registerTorrentStatus: function(key, header, options) {
options = options || {};
var cc = options.colCfg || {}, sc = options.storeCfg || {};
sc = Ext.apply(sc, {name: key});
deluge.torrents.meta.fields.push(sc);
deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);
cc = Ext.apply(cc, {
header: header,
dataIndex: key
});
var cols = deluge.torrents.columns.slice(0);
cols.push(cc);
deluge.torrents.colModel.setConfig(cols);
deluge.torrents.columns = cols;
Deluge.Keys.Grid.push(key);
deluge.torrents.getView().refresh(true);
},
deregisterTorrentStatus: function(key) {
var fields = [];
Ext.each(deluge.torrents.meta.fields, function(field) {
if (field.name != key) fields.push(field);
});
deluge.torrents.meta.fields = fields;
deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);
var cols = [];
Ext.each(deluge.torrents.columns, function(col) {
if (col.dataIndex != key) cols.push(col);
});
deluge.torrents.colModel.setConfig(cols);
deluge.torrents.columns = cols;
var keys = [];
Ext.each(Deluge.Keys.Grid, function(k) {
if (k == key) keys.push(k);
});
Deluge.Keys.Grid = keys;
deluge.torrents.getView().refresh(true);
} }
}); });

View file

@ -91,32 +91,6 @@
// object to store contained torrent ids // object to store contained torrent ids
torrents: {}, torrents: {},
constructor: function(config) {
config = Ext.apply({
id: 'torrentGrid',
store: new Ext.data.JsonStore({
root: 'torrents',
idProperty: 'id',
fields: [
{name: 'queue', sortType: Deluge.data.SortTypes.asQueuePosition},
{name: 'name'},
{name: 'total_size', type: 'int'},
{name: 'state'},
{name: 'progress', type: 'float'},
{name: 'num_seeds', type: 'int'},
{name: 'total_seeds', type: 'int'},
{name: 'num_peers', type: 'int'},
{name: 'total_peers', type: 'int'},
{name: 'download_payload_rate', type: 'int'},
{name: 'upload_payload_speed', type: 'int'},
{name: 'eta', type: 'int', sortType: etaSorter},
{name: 'ratio', type: 'float'},
{name: 'distributed_copies', type: 'float'},
{name: 'time_added', type: 'int'},
{name: 'tracker_host'},
{name: 'save_path'}
]
}),
columns: [{ columns: [{
id:'queue', id:'queue',
header: _('#'), header: _('#'),
@ -204,6 +178,36 @@
renderer: fplain, renderer: fplain,
dataIndex: 'save_path' dataIndex: 'save_path'
}], }],
meta: {
root: 'torrents',
idProperty: 'id',
fields: [
{name: 'queue', sortType: Deluge.data.SortTypes.asQueuePosition},
{name: 'name'},
{name: 'total_size', type: 'int'},
{name: 'state'},
{name: 'progress', type: 'float'},
{name: 'num_seeds', type: 'int'},
{name: 'total_seeds', type: 'int'},
{name: 'num_peers', type: 'int'},
{name: 'total_peers', type: 'int'},
{name: 'download_payload_rate', type: 'int'},
{name: 'upload_payload_speed', type: 'int'},
{name: 'eta', type: 'int', sortType: etaSorter},
{name: 'ratio', type: 'float'},
{name: 'distributed_copies', type: 'float'},
{name: 'time_added', type: 'int'},
{name: 'tracker_host'},
{name: 'save_path'}
]
},
constructor: function(config) {
config = Ext.apply({
id: 'torrentGrid',
store: new Ext.data.JsonStore(this.meta),
columns: this.columns,
region: 'center', region: 'center',
cls: 'deluge-torrents', cls: 'deluge-torrents',
stripeRows: true, stripeRows: true,