Author: damoxc

Revision: 5775

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

Diff:
Modified: trunk/deluge/ui/web/js/Deluge.ConnectionManager.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.ConnectionManager.js  2009-09-24 08:37:20 UTC 
(rev 5774)
+++ trunk/deluge/ui/web/js/Deluge.ConnectionManager.js  2009-09-24 08:41:00 UTC 
(rev 5775)
@@ -324,6 +324,21 @@
                        record.set('status', host[3])
                        record.set('version', host[4])
                        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() {
@@ -371,31 +386,41 @@
        
                onSelect: function(selModel, rowIndex, record) {
                        this.selectedRow = rowIndex;
-                       var button = this.buttons[1];
-                       if (record.get('status') == _('Connected')) {
-                               button.setText(_('Disconnect'));
-                       } else {
-                               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');
-                       }
+                       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'));
+                       } 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 {
+                               button.setText(_('Connect'));
+                       }
                },
        
                onShow: function() {
+                       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');
+                       }
                        this.loadHosts();
                        this.running = window.setInterval(this.update, 2000, 
this);
                },
@@ -403,21 +428,27 @@
                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]) {
-                                               Ext.MessageBox.show({
-                                                       title: _('Error'),
-                                                       msg: result[1],
-                                                       buttons: 
Ext.MessageBox.OK,
-                                                       modal: false,
-                                                       icon: 
Ext.MessageBox.ERROR,
-                                                       iconCls: 
'x-deluge-icon-error'
-                                               });
+                       
+                       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, {
+                                       success: function(result) {
+                                               if (!result[0]) {
+                                                       Ext.MessageBox.show({
+                                                               title: 
_('Error'),
+                                                               msg: result[1],
+                                                               buttons: 
Ext.MessageBox.OK,
+                                                               modal: false,
+                                                               icon: 
Ext.MessageBox.ERROR,
+                                                               iconCls: 
'x-deluge-icon-error'
+                                                       });
+                                               }
                                        }
-                               }
-                       });
+                               });
+                       }
                }
        });
 Deluge.ConnectionManager = new Ext.deluge.ConnectionManager();



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to