Author: damoxc

Revision: 5058

Log:
        tidy up the login window code, extend Ext.Window instead.
focus the password field upon the login window being displayed

Diff:
Modified: trunk/deluge/ui/web/js/deluge-bars.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-bars.js       2009-04-14 09:13:07 UTC (rev 
5057)
+++ trunk/deluge/ui/web/js/deluge-bars.js       2009-04-14 20:09:48 UTC (rev 
5058)
@@ -50,7 +50,7 @@
        onLogout: function() {
                this.Bar.items.get('logout').disable();
                Deluge.Events.fire('logout');
-               Deluge.Login.Window.show();
+               Deluge.Login.show();
        },
        
        onConnectionManagerClick: function(item) {

Modified: trunk/deluge/ui/web/js/deluge-login.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-login.js      2009-04-14 09:13:07 UTC (rev 
5057)
+++ trunk/deluge/ui/web/js/deluge-login.js      2009-04-14 20:09:48 UTC (rev 
5058)
@@ -21,79 +21,96 @@
                Boston, MA  02110-1301, USA.
 */
 
-Deluge.Login = {
-    onLogin: function() {
-        var passwordField = Deluge.Login.Form.items.get('password');
-        Deluge.Client.web.login(passwordField.getValue(), {
-            onSuccess: function(result) {
-                if (result == true) {
-                    Deluge.Login.Window.hide();
-                    Deluge.Connections.loginShow();
-                    passwordField.setRawValue('');
-                    Deluge.Events.fire('login')
-                } else {
-                    Ext.MessageBox.show({
-                        title: _('Login Failed'),
-                        msg: _('You entered an incorrect password'),
-                        buttons: Ext.MessageBox.OK,
-                        modal: false,
-                        icon: Ext.MessageBox.WARNING,
-                        iconCls: 'x-deluge-icon-warning'
-                    });
-                }
-            }
-        });
-    },
-    
-    onLogout: function() {
-        Deluge.Login.Window.show();
-    },
-    
-    onKey: function(field, e) {
-        if (e.getKey() == 13) Deluge.Login.onLogin();
-    },
-    
-    onRender: function() {  
-        Deluge.Events.on('logout', this.onLogout);
-    }
-}
-
-Deluge.Login.Form = new Ext.form.FormPanel({
-    defaultType: 'textfield',
-    id: 'loginForm',
-    baseCls: 'x-plain',
-    labelWidth: 55,
-    items: [{
-        fieldLabel: _('Password'),
-        id: 'password',
-        name: 'password',
-        inputType: 'password',
-        anchor: '100%',
-        listeners: {
-            'specialkey': {
-                fn: Deluge.Login.onKey,
-                scope: Deluge.Login
-            }
-        }
-    }]
-});
-
-Deluge.Login.Window = new Ext.Window({
-    layout: 'fit',
-    width: 300,
-    height: 120,
-    bodyStyle: 'padding: 10px 5px;',
-    buttonAlign: 'center',
-    closeAction: 'hide',
-    closable: false,
-    modal: true,
-    plain: true,
-    title: _('Login'),
-    iconCls: 'x-deluge-login-window-icon',
-    items: Deluge.Login.Form,
-    buttons: [{
-        text: _('Login'),
-        handler: Deluge.Login.onLogin
-    }],
-    listeners: {'render': {fn: Deluge.Login.onRender, scope: Deluge.Login}}
-});
\ No newline at end of file
+(function(){
+       var LoginWindow = function(config) {
+               Ext.apply(this, {
+                       layout: 'fit',
+                       width: 300,
+                       height: 120,
+                       bodyStyle: 'padding: 10px 5px;',
+                       buttonAlign: 'center',
+                       closeAction: 'hide',
+                       closable: false,
+                       modal: true,
+                       plain: true,
+                       resizable: false,
+                       title: _('Login'),
+                       iconCls: 'x-deluge-login-window-icon'
+               });
+               Ext.apply(this, config);
+               LoginWindow.superclass.constructor.call(this);
+       };
+       
+       Ext.extend(LoginWindow, Ext.Window, {
+               initComponent: function() {
+                       LoginWindow.superclass.initComponent.call();
+                       Deluge.Events.on('logout', this.onLogout);
+                       this.on('show', this.onShow, this);
+                       
+                       this.addButton({
+                               text: _('Login'),
+                               handler: this.onLogin,
+                               scope: this
+                       });
+                       
+                       this.loginForm = this.add({
+                               xtype: 'form',
+                               defaultType: 'textfield',
+                               id: 'loginForm',
+                               baseCls: 'x-plain',
+                               labelWidth: 55,
+                               items: [{
+                                       fieldLabel: _('Password'),
+                                       id: 'password',
+                                       name: 'password',
+                                       inputType: 'password',
+                                       anchor: '100%',
+                                       listeners: {
+                                               'specialkey': {
+                                                       fn: this.onKey,
+                                                       scope: this
+                                               }
+                                       }
+                               }]
+                       });
+               },
+               
+               onKey: function(field, e) {
+                       if (e.getKey() == 13) this.onLogin();
+               },
+               
+               onLogin: function() {
+                       var passwordField = 
this.loginForm.items.get('password');
+                       Deluge.Client.web.login(passwordField.getValue(), {
+                               onSuccess: function(result) {
+                                       if (result == true) {
+                                               this.hide();
+                                               Deluge.Connections.loginShow();
+                                               passwordField.setRawValue('');
+                                               Deluge.Events.fire('login')
+                                       } else {
+                                               Ext.MessageBox.show({
+                                                       title: _('Login 
Failed'),
+                                                       msg: _('You entered an 
incorrect password'),
+                                                       buttons: 
Ext.MessageBox.OK,
+                                                       modal: false,
+                                                       icon: 
Ext.MessageBox.WARNING,
+                                                       iconCls: 
'x-deluge-icon-warning'
+                                               });
+                                       }
+                               }.bindWithEvent(this)
+                       });
+               },
+               
+               onLogout: function() {
+                       this.show();
+               },
+               
+               onShow: function() {
+                       var passwordField = 
this.loginForm.items.get('password');
+                       passwordField.focus(false, 150);
+               }
+       });
+       
+       Deluge.Login = new LoginWindow();
+})();
\ No newline at end of file

Modified: trunk/deluge/ui/web/js/deluge-ui.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-ui.js 2009-04-14 09:13:07 UTC (rev 5057)
+++ trunk/deluge/ui/web/js/deluge-ui.js 2009-04-14 20:09:48 UTC (rev 5058)
@@ -48,7 +48,7 @@
                        items: [this.MainPanel]
                });
 
-               Deluge.Login.Window.show();
+               Deluge.Login.show();
                
                Deluge.Events.on("connect", this.onConnect.bindWithEvent(this));
                Deluge.Events.on("disconnect", 
this.onDisconnect.bindWithEvent(this));
@@ -56,7 +56,7 @@
        },
        
        notify: function(title, message) {
-               this.roar.alert(title, message);
+               //this.roar.alert(title, message);
        },
        
        update: function() {



--~--~---------~--~----~------------~-------~--~----~
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