give a bit more love to the connection manager, updating buttons when the host status is updated as well

This commit is contained in:
Damien Churchill 2009-09-24 08:41:00 +00:00
commit 9df5269fee

View file

@ -324,6 +324,21 @@ Copyright:
record.set('status', host[3]) record.set('status', host[3])
record.set('version', host[4]) record.set('version', host[4])
record.commit(); record.commit();
if (this.grid.getSelectionModel().getSelected() == record) {
var status = record.get('status');
if (status == _('Offline')) {
if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') {
this.stopHostButton.enable();
this.stopHostButton.setText(_('Start Daemon'));
} else {
this.stopHostButton.disable();
}
} else {
this.stopHostButton.enable();
this.stopHostButton.setText(_('Stop Daemon'));
}
}
}, },
onLogin: function() { onLogin: function() {
@ -371,31 +386,41 @@ Copyright:
onSelect: function(selModel, rowIndex, record) { onSelect: function(selModel, rowIndex, record) {
this.selectedRow = rowIndex; this.selectedRow = rowIndex;
var button = this.buttons[1]; },
if (record.get('status') == _('Connected')) {
onSelectionChanged: function(selModel) {
var record = selModel.getSelected();
if (selModel.hasSelection()) {
this.removeHostButton.enable();
this.stopHostButton.enable();
this.stopHostButton.setText(_('Stop Daemon'));
} else {
this.removeHostButton.disable();
this.stopHostButton.disable();
}
var button = this.buttons[1], status = record.get('status');
if (status == _('Connected')) {
button.setText(_('Disconnect')); button.setText(_('Disconnect'));
} else if (status == _('Offline')) {
if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') {
this.stopHostButton.setText(_('Start Daemon'));
} else {
this.stopHostButton.disable();
}
} else { } else {
button.setText(_('Connect')); button.setText(_('Connect'));
} }
}, },
onSelectionChanged: function(selModel) { onShow: function() {
if (!this.addHostButton) { if (!this.addHostButton) {
var bbar = this.grid.getBottomToolbar(); var bbar = this.grid.getBottomToolbar();
this.addHostButton = bbar.items.get('cm-add'); this.addHostButton = bbar.items.get('cm-add');
this.removeHostButton = bbar.items.get('cm-remove'); this.removeHostButton = bbar.items.get('cm-remove');
this.stopHostButton = bbar.items.get('cm-stop'); 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.loadHosts();
this.running = window.setInterval(this.update, 2000, this); this.running = window.setInterval(this.update, 2000, this);
}, },
@ -404,6 +429,11 @@ Copyright:
var connection = this.grid.getSelectionModel().getSelected(); var connection = this.grid.getSelectionModel().getSelected();
if (!connection) return; if (!connection) return;
if (connection.get('status') == 'Offline') {
// This means we need to start the daemon
Deluge.Client.web.start_daemon(connection.get('port'));
} else {
// This means we need to stop the daemon
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]) {
@ -419,6 +449,7 @@ Copyright:
} }
}); });
} }
}
}); });
Deluge.ConnectionManager = new Ext.deluge.ConnectionManager(); Deluge.ConnectionManager = new Ext.deluge.ConnectionManager();
})(); })();