improve removing of torrents by adding a "torrentRemoved" event

This commit is contained in:
Damien Churchill 2009-04-02 09:54:06 +00:00
parent 71ef3f3ddc
commit 6897cd8b6b
3 changed files with 22 additions and 0 deletions

View File

@ -66,6 +66,7 @@ Deluge.ToolBar = {
switch (item.id) {
case 'remove':
Deluge.Events.fire('torrentRemoved', ids);
Deluge.Client.core.remove_torrent(ids, null, {
onSuccess: function() {
Deluge.Ui.update();

View File

@ -56,6 +56,7 @@ Deluge.Menus = {
});
break;
case 'remove':
Deluge.Events.fire('torrentRemoved', ids);
Deluge.Client.core.remove_torrent(ids, null, {
onSuccess: function() {
Deluge.Ui.update();

View File

@ -105,6 +105,22 @@ Deluge.Torrents = {
getSelections: function() {
return this.Grid.getSelectionModel().getSelections();
},
onRender: function() {
Deluge.Events.on('torrentRemoved', this.onTorrentRemoved.bindWithEvent(this));
},
onTorrentRemoved: function(torrentIds) {
var selModel = this.Grid.getSelectionModel();
$each(torrentIds, function(torrentId) {
var record = this.Store.getById(torrentId);
if (selModel.isSelected(record)) {
selModel.deselectRow(this.Store.indexOf(record));
}
this.Store.remove(record);
}, this);
}
}
Deluge.Torrents.Store.setDefaultSort("queue");
@ -134,6 +150,10 @@ Deluge.Torrents.Grid = new Ext.grid.GridPanel({
autoScroll:true,
margins: '5 5 0 0',
listeners: {
'render': {
fn: Deluge.Torrents.onRender,
scope: Deluge.Torrents
},
'rowcontextmenu': {
fn: function(grid, rowIndex, e) {
e.stopEvent();