fix #1537 editing trackers list, trackers have to be reselected

This commit is contained in:
Damien Churchill 2011-05-06 23:43:40 +01:00
parent 58134925a2
commit d658c8fe47
1 changed files with 29 additions and 21 deletions

View File

@ -1,6 +1,6 @@
/*! /*!
* Deluge.EditTrackers.js * Deluge.EditTrackers.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -49,17 +49,17 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
buttonAlign: 'right', buttonAlign: 'right',
closeAction: 'hide', closeAction: 'hide',
iconCls: 'x-deluge-edit-trackers', iconCls: 'x-deluge-edit-trackers',
initComponent: function() { initComponent: function() {
Deluge.EditTrackersWindow.superclass.initComponent.call(this); Deluge.EditTrackersWindow.superclass.initComponent.call(this);
this.addButton(_('Cancel'), this.onCancelClick, this); this.addButton(_('Cancel'), this.onCancelClick, this);
this.addButton(_('Ok'), this.onOkClick, this); this.addButton(_('Ok'), this.onOkClick, this);
this.addEvents('save'); this.addEvents('save');
this.on('show', this.onShow, this); this.on('show', this.onShow, this);
this.on('save', this.onSave, this); this.on('save', this.onSave, this);
this.addWindow = new Deluge.AddTrackerWindow(); this.addWindow = new Deluge.AddTrackerWindow();
this.addWindow.on('add', this.onAddTrackers, this); this.addWindow.on('add', this.onAddTrackers, this);
this.editWindow = new Deluge.EditTrackerWindow(); this.editWindow = new Deluge.EditTrackerWindow();
@ -91,7 +91,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
'selectionchange': {fn: this.onSelect, scope: this} 'selectionchange': {fn: this.onSelect, scope: this}
} }
}); });
this.panel = this.add({ this.panel = this.add({
margins: '0 0 0 0', margins: '0 0 0 0',
items: [this.list], items: [this.list],
@ -128,11 +128,11 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
}) })
}); });
}, },
onAddClick: function() { onAddClick: function() {
this.addWindow.show(); this.addWindow.show();
}, },
onAddTrackers: function(trackers) { onAddTrackers: function(trackers) {
var store = this.list.getStore(); var store = this.list.getStore();
Ext.each(trackers, function(tracker) { Ext.each(trackers, function(tracker) {
@ -150,15 +150,15 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
store.add(new store.recordType({'tier': heightestTier + 1, 'url': tracker})); store.add(new store.recordType({'tier': heightestTier + 1, 'url': tracker}));
}, this); }, this);
}, },
onCancelClick: function() { onCancelClick: function() {
this.hide(); this.hide();
}, },
onEditClick: function() { onEditClick: function() {
this.editWindow.show(this.list.getSelectedRecords()[0]); this.editWindow.show(this.list.getSelectedRecords()[0]);
}, },
onHide: function() { onHide: function() {
this.list.getStore().removeAll(); this.list.getStore().removeAll();
}, },
@ -166,7 +166,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
onListNodeDblClicked: function(list, index, node, e) { onListNodeDblClicked: function(list, index, node, e) {
this.editWindow.show(this.list.getRecord(node)); this.editWindow.show(this.list.getRecord(node));
}, },
onOkClick: function() { onOkClick: function() {
var trackers = []; var trackers = [];
this.list.getStore().each(function(record) { this.list.getStore().each(function(record) {
@ -175,7 +175,7 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
'url': record.get('url') 'url': record.get('url')
}) })
}, this); }, this);
deluge.client.core.set_torrent_trackers(this.torrentId, trackers, { deluge.client.core.set_torrent_trackers(this.torrentId, trackers, {
failure: this.onSaveFail, failure: this.onSaveFail,
scope: this scope: this
@ -183,27 +183,27 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
this.hide(); this.hide();
}, },
onRemoveClick: function() { onRemoveClick: function() {
// Remove from the grid // Remove from the grid
this.list.getStore().remove(this.list.getSelectedRecords()[0]); this.list.getStore().remove(this.list.getSelectedRecords()[0]);
}, },
onRequestComplete: function(status) { onRequestComplete: function(status) {
this.list.getStore().loadData(status); this.list.getStore().loadData(status);
this.list.getStore().sort('tier', 'ASC'); this.list.getStore().sort('tier', 'ASC');
}, },
onSaveFail: function() { onSaveFail: function() {
}, },
onSelect: function(list) { onSelect: function(list) {
if (list.getSelectionCount()) { if (list.getSelectionCount()) {
this.panel.getBottomToolbar().items.get(4).enable(); this.panel.getBottomToolbar().items.get(4).enable();
} }
}, },
onShow: function() { onShow: function() {
this.panel.getBottomToolbar().items.get(4).disable(); this.panel.getBottomToolbar().items.get(4).disable();
var r = deluge.torrents.getSelected(); var r = deluge.torrents.getSelected();
@ -216,16 +216,24 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
onDownClick: function() { onDownClick: function() {
var r = this.list.getSelectedRecords()[0]; var r = this.list.getSelectedRecords()[0];
if (!r) return;
r.set('tier', r.get('tier') + 1); r.set('tier', r.get('tier') + 1);
r.commit();
r.store.sort('tier', 'ASC'); r.store.sort('tier', 'ASC');
r.store.commitChanges();
this.list.select(r.store.indexOf(r));
}, },
onUpClick: function() { onUpClick: function() {
var r = this.list.getSelectedRecords()[0]; var r = this.list.getSelectedRecords()[0];
if (!r) return;
if (r.get('tier') == 0) return; if (r.get('tier') == 0) return;
r.set('tier', r.get('tier') - 1); r.set('tier', r.get('tier') - 1);
r.commit();
r.store.sort('tier', 'ASC'); r.store.sort('tier', 'ASC');
r.store.commitChanges();
this.list.select(r.store.indexOf(r));
} }
}); });