From 68b4af839f13d287c781a86cde53cf504004d8a8 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Wed, 23 Sep 2009 19:10:44 +0000 Subject: [PATCH] disable the remove button and the stop daemon button when no host is selected --- deluge/ui/web/js/Deluge.ConnectionManager.js | 123 +++++++++++-------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/deluge/ui/web/js/Deluge.ConnectionManager.js b/deluge/ui/web/js/Deluge.ConnectionManager.js index 137fb07c3..7133f2f5e 100644 --- a/deluge/ui/web/js/Deluge.ConnectionManager.js +++ b/deluge/ui/web/js/Deluge.ConnectionManager.js @@ -1,6 +1,6 @@ /* 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: (C) Damien Churchill 2009 @@ -20,15 +20,15 @@ Copyright: 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - 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 - 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 - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the OpenSSL + library. + 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 + 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 + this exception statement from your version. If you delete this exception + statement from all source files in the program, then also delete it here. */ @@ -36,9 +36,9 @@ Copyright: var hostRenderer = function(value, p, r) { return value + ':' + r.data['port'] } - + Ext.deluge.AddConnectionWindow = Ext.extend(Ext.Window, { - + constructor: function(config) { config = Ext.apply({ layout: 'fit', @@ -54,17 +54,17 @@ Copyright: }, config); Ext.deluge.AddConnectionWindow.superclass.constructor.call(this, config); }, - + initComponent: function() { Ext.deluge.AddConnectionWindow.superclass.initComponent.call(this); - + this.addEvents('hostadded'); - + this.addButton(_('Close'), this.hide, this); this.addButton(_('Add'), this.onAdd, this); - + this.on('hide', this.onHide, this); - + this.form = this.add({ xtype: 'form', defaultType: 'textfield', @@ -72,7 +72,7 @@ Copyright: baseCls: 'x-plain', labelWidth: 55 }); - + this.hostField = this.form.add({ fieldLabel: _('Host'), id: 'host', @@ -80,7 +80,7 @@ Copyright: anchor: '100%', value: '' }); - + this.portField = this.form.add({ fieldLabel: _('Port'), id: 'port', @@ -91,7 +91,7 @@ Copyright: value: '58846', anchor: '50%' }); - + this.usernameField = this.form.add({ fieldLabel: _('Username'), id: 'username', @@ -99,7 +99,7 @@ Copyright: anchor: '100%', value: '' }); - + this.passwordField = this.form.add({ fieldLabel: _('Password'), anchor: '100%', @@ -109,13 +109,13 @@ Copyright: value: '' }); }, - + onAdd: function() { var host = this.hostField.getValue(); var port = this.portField.getValue(); var username = this.usernameField.getValue(); var password = this.passwordField.getValue(); - + Deluge.Client.web.add_host(host, port, username, password, { success: function(result) { if (!result[0]) { @@ -135,14 +135,14 @@ Copyright: scope: this }); }, - + onHide: function() { this.form.getForm().reset(); } }); Ext.deluge.ConnectionManager = Ext.extend(Ext.Window, { - + layout: 'fit', width: 300, height: 220, @@ -153,7 +153,7 @@ Copyright: plain: true, title: _('Connection Manager'), iconCls: 'x-deluge-connect-window-icon', - + initComponent: function() { Ext.deluge.ConnectionManager.superclass.initComponent.call(this); this.on({ @@ -162,10 +162,10 @@ Copyright: }); Deluge.Events.on('login', this.onLogin, this); Deluge.Events.on('logout', this.onLogout, this); - + this.addButton(_('Close'), this.onClose, this); this.addButton(_('Connect'), this.onConnect, this); - + this.grid = this.add({ xtype: 'grid', store: new Ext.data.SimpleStore({ @@ -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,45 +210,47 @@ 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 } ] }) }); }, - + disconnect: function() { Deluge.Events.fire('disconnect'); }, - + loadHosts: function() { Deluge.Client.web.get_hosts({ success: this.onGetHosts, scope: this }); }, - + update: function(self) { self.grid.getStore().each(function(r) { Deluge.Client.web.get_host_status(r.id, { @@ -256,7 +259,7 @@ Copyright: }); }, this); }, - + onAdd: function(button, e) { if (!this.addWindow) { this.addWindow = new Ext.deluge.AddConnectionWindow(); @@ -264,20 +267,20 @@ Copyright: } this.addWindow.show(); }, - + onHostAdded: function() { this.update(this); }, - + onClose: function(e) { if (this.running) window.clearInterval(this.running); this.hide(); }, - + onConnect: function(e) { var selected = this.grid.getSelectionModel().getSelected(); if (!selected) return; - + if (selected.get('status') == _('Connected')) { Deluge.Client.web.disconnect({ success: function(result) { @@ -300,7 +303,7 @@ Copyright: this.hide(); } }, - + onGetHosts: function(hosts) { this.grid.getStore().loadData(hosts); Ext.each(hosts, function(host) { @@ -310,14 +313,14 @@ Copyright: }); }, this); }, - + onGetHostStatus: function(host) { var record = this.grid.getStore().getById(host[0]); record.set('status', host[3]) record.set('version', host[4]) record.commit(); }, - + onLogin: function() { Deluge.Client.web.connected({ success: function(connected) { @@ -330,16 +333,18 @@ Copyright: scope: this }); }, - + onLogout: function() { this.disconnect(); if (!this.hidden && this.rendered) { this.hide(); } }, - + onRemove: function(button) { var connection = this.grid.getSelectionModel().getSelected(); + if (!connection) return; + Deluge.Client.web.remove_host(connection.id, { success: function(result) { if (!result) { @@ -358,7 +363,7 @@ Copyright: scope: this }); }, - + onSelect: function(selModel, rowIndex, record) { this.selectedRow = rowIndex; var button = this.buttons[1]; @@ -368,14 +373,32 @@ Copyright: button.setText(_('Connect')); } }, - + + 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); }, - + 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(); })();