[#2707|WebUI] Ensure var test for getSelectedRecords value

* Fixes potential for TypeError undefined in browser console.
This commit is contained in:
Calum Lind 2017-06-17 03:31:59 +01:00
parent 6e66452cf3
commit 2c66a4c29e
4 changed files with 14 additions and 5 deletions

View File

@ -268,7 +268,9 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
record.set('status', host[1]) record.set('status', host[1])
record.set('version', host[2]) record.set('version', host[2])
record.commit(); record.commit();
if (this.list.getSelectedRecords()[0] == record) this.updateButtons(record); var selected = this.list.getSelectedRecords()[0]
if (!selected) return;
if (selected == record) this.updateButtons(record);
}, },
// private // private

View File

@ -134,7 +134,9 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
}, },
onEditClick: function() { onEditClick: function() {
this.editWindow.show(this.list.getSelectedRecords()[0]); var selected = this.list.getSelectedRecords()[0];
if (!selected) return;
this.editWindow.show(selected);
}, },
onHide: function() { onHide: function() {
@ -164,7 +166,9 @@ Deluge.EditTrackersWindow = Ext.extend(Ext.Window, {
onRemoveClick: function() { onRemoveClick: function() {
// Remove from the grid // Remove from the grid
this.list.getStore().remove(this.list.getSelectedRecords()[0]); var selected = this.list.getSelectedRecords()[0];
if (!selected) return;
this.list.getStore().remove(selected);
}, },
onRequestComplete: function(status) { onRequestComplete: function(status) {

View File

@ -77,6 +77,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
if (!this.list.getSelectionCount()) return; if (!this.list.getSelectionCount()) return;
var state = this.list.getSelectedRecords()[0]; var state = this.list.getSelectedRecords()[0];
if (!state) return;
if (state.id == 'All') return; if (state.id == 'All') return;
return state.id; return state.id;
}, },
@ -137,9 +138,10 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
store.each(function(record) { store.each(function(record) {
if (filters[record.id]) return; if (filters[record.id]) return;
var r = this.list.getSelectedRecords()[0];
store.remove(record); store.remove(record);
if (r.id == record.id) { var selected = this.list.getSelectedRecords()[0];
if (!selected) return;
if (selected.id == record.id) {
this.list.select(0); this.list.select(0);
} }
}, this); }, this);

View File

@ -188,6 +188,7 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, {
onRemove: function() { onRemove: function() {
if (!this.list.getSelectionCount()) return; if (!this.list.getSelectionCount()) return;
var torrent = this.list.getSelectedRecords()[0]; var torrent = this.list.getSelectedRecords()[0];
if (!torrent) return;
this.list.getStore().remove(torrent); this.list.getStore().remove(torrent);
this.optionsPanel.clear(); this.optionsPanel.clear();