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

@ -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]) {