disable the remove button and the stop daemon button when no host is selected

This commit is contained in:
Damien Churchill 2009-09-23 19:10:44 +00:00
commit 68b4af839f

View file

@ -1,6 +1,6 @@
/* /*
Script: deluge-connections.js Script: deluge-connections.js
Contains all objects and functions related to the connection manager. Contains all objects and functions related to the connection manager.
Copyright: Copyright:
(C) Damien Churchill 2009 <damoxc@gmail.com> (C) Damien Churchill 2009 <damoxc@gmail.com>
@ -20,15 +20,15 @@ Copyright:
51 Franklin Street, Fifth Floor 51 Franklin Street, Fifth Floor
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
In addition, as a special exception, the copyright holders give In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the OpenSSL permission to link the code of portions of this program with the OpenSSL
library. library.
You must obey the GNU General Public License in all respects for all of You must obey the GNU General Public License in all respects for all of
the code used other than OpenSSL. If you modify file(s) with this the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s), exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version. If you delete this exception this exception statement from your version. If you delete this exception
statement from all source files in the program, then also delete it here. statement from all source files in the program, then also delete it here.
*/ */
@ -201,7 +201,8 @@ Copyright:
selModel: new Ext.grid.RowSelectionModel({ selModel: new Ext.grid.RowSelectionModel({
singleSelect: true, singleSelect: true,
listeners: { listeners: {
'rowselect': {fn: this.onSelect, scope: this} 'rowselect': {fn: this.onSelect, scope: this},
'selectionchange': {fn: this.onSelectionChanged, scope: this}
} }
}), }),
autoExpandColumn: 'host', autoExpandColumn: 'host',
@ -209,27 +210,29 @@ Copyright:
autoScroll:true, autoScroll:true,
margins: '0 0 0 0', margins: '0 0 0 0',
bbar: new Ext.Toolbar({ bbar: new Ext.Toolbar({
items: [ buttons: [
{ {
id: 'add', id: 'cm-add',
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
text: _('Add'), text: _('Add'),
icon: '/icons/add.png', icon: '/icons/add.png',
handler: this.onAdd, handler: this.onAdd,
scope: this scope: this
}, { }, {
id: 'remove', id: 'cm-remove',
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
text: _('Remove'), text: _('Remove'),
icon: '/icons/remove.png', icon: '/icons/remove.png',
handler: this.onRemove, handler: this.onRemove,
disabled: true,
scope: this scope: this
}, '->', { }, '->', {
id: 'stop', id: 'cm-stop',
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
text: _('Stop Daemon'), text: _('Stop Daemon'),
icon: '/icons/error.png', icon: '/icons/error.png',
handler: this.onStop, handler: this.onStop,
disabled: true,
scope: this scope: this
} }
] ]
@ -340,6 +343,8 @@ Copyright:
onRemove: function(button) { onRemove: function(button) {
var connection = this.grid.getSelectionModel().getSelected(); var connection = this.grid.getSelectionModel().getSelected();
if (!connection) return;
Deluge.Client.web.remove_host(connection.id, { Deluge.Client.web.remove_host(connection.id, {
success: function(result) { success: function(result) {
if (!result) { if (!result) {
@ -369,6 +374,22 @@ Copyright:
} }
}, },
onSelectionChanged: function(selModel) {
if (!this.addHostButton) {
var bbar = this.grid.getBottomToolbar();
this.addHostButton = bbar.items.get('cm-add');
this.removeHostButton = bbar.items.get('cm-remove');
this.stopHostButton = bbar.items.get('cm-stop');
}
if (selModel.hasSelection()) {
this.removeHostButton.enable();
this.stopHostButton.enable();
} else {
this.removeHostButton.disable();
this.stopHostButton.disable();
}
},
onShow: function() { onShow: function() {
this.loadHosts(); this.loadHosts();
this.running = window.setInterval(this.update, 2000, this); this.running = window.setInterval(this.update, 2000, this);
@ -376,6 +397,8 @@ Copyright:
onStop: function(button, e) { onStop: function(button, e) {
var connection = this.grid.getSelectionModel().getSelected(); var connection = this.grid.getSelectionModel().getSelected();
if (!connection) return;
Deluge.Client.web.stop_daemon(connection.id, { Deluge.Client.web.stop_daemon(connection.id, {
success: function(result) { success: function(result) {
if (!result[0]) { if (!result[0]) {
@ -392,5 +415,5 @@ Copyright:
}); });
} }
}); });
Deluge.ConnectionManager = new Ext.deluge.ConnectionManager(); Deluge.ConnectionManager = new Ext.deluge.ConnectionManager();
})(); })();