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({
singleSelect: true,
listeners: {
'rowselect': {fn: this.onSelect, scope: this}
'rowselect': {fn: this.onSelect, scope: this},
'selectionchange': {fn: this.onSelectionChanged, scope: this}
}
}),
autoExpandColumn: 'host',
@ -209,27 +210,29 @@ Copyright:
autoScroll:true,
margins: '0 0 0 0',
bbar: new Ext.Toolbar({
items: [
buttons: [
{
id: 'add',
id: 'cm-add',
cls: 'x-btn-text-icon',
text: _('Add'),
icon: '/icons/add.png',
handler: this.onAdd,
scope: this
}, {
id: 'remove',
id: 'cm-remove',
cls: 'x-btn-text-icon',
text: _('Remove'),
icon: '/icons/remove.png',
handler: this.onRemove,
disabled: true,
scope: this
}, '->', {
id: 'stop',
id: 'cm-stop',
cls: 'x-btn-text-icon',
text: _('Stop Daemon'),
icon: '/icons/error.png',
handler: this.onStop,
disabled: true,
scope: this
}
]
@ -340,6 +343,8 @@ Copyright:
onRemove: function(button) {
var connection = this.grid.getSelectionModel().getSelected();
if (!connection) return;
Deluge.Client.web.remove_host(connection.id, {
success: function(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() {
this.loadHosts();
this.running = window.setInterval(this.update, 2000, this);
@ -376,6 +397,8 @@ Copyright:
onStop: function(button, e) {
var connection = this.grid.getSelectionModel().getSelected();
if (!connection) return;
Deluge.Client.web.stop_daemon(connection.id, {
success: function(result) {
if (!result[0]) {
@ -392,5 +415,5 @@ Copyright:
});
}
});
Deluge.ConnectionManager = new Ext.deluge.ConnectionManager();
Deluge.ConnectionManager = new Ext.deluge.ConnectionManager();
})();