tidy up the login window code, extend Ext.Window instead.

focus the password field upon the login window being displayed
This commit is contained in:
Damien Churchill 2009-04-14 20:09:48 +00:00
commit 2e4762a586
3 changed files with 96 additions and 79 deletions

View file

@ -50,7 +50,7 @@ Deluge.ToolBar = {
onLogout: function() { onLogout: function() {
this.Bar.items.get('logout').disable(); this.Bar.items.get('logout').disable();
Deluge.Events.fire('logout'); Deluge.Events.fire('logout');
Deluge.Login.Window.show(); Deluge.Login.show();
}, },
onConnectionManagerClick: function(item) { onConnectionManagerClick: function(item) {

View file

@ -21,79 +21,96 @@ Copyright:
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
Deluge.Login = { (function(){
onLogin: function() { var LoginWindow = function(config) {
var passwordField = Deluge.Login.Form.items.get('password'); Ext.apply(this, {
Deluge.Client.web.login(passwordField.getValue(), { layout: 'fit',
onSuccess: function(result) { width: 300,
if (result == true) { height: 120,
Deluge.Login.Window.hide(); bodyStyle: 'padding: 10px 5px;',
Deluge.Connections.loginShow(); buttonAlign: 'center',
passwordField.setRawValue(''); closeAction: 'hide',
Deluge.Events.fire('login') closable: false,
} else { modal: true,
Ext.MessageBox.show({ plain: true,
title: _('Login Failed'), resizable: false,
msg: _('You entered an incorrect password'), title: _('Login'),
buttons: Ext.MessageBox.OK, iconCls: 'x-deluge-login-window-icon'
modal: false, });
icon: Ext.MessageBox.WARNING, Ext.apply(this, config);
iconCls: 'x-deluge-icon-warning' LoginWindow.superclass.constructor.call(this);
}); };
}
}
});
},
onLogout: function() { Ext.extend(LoginWindow, Ext.Window, {
Deluge.Login.Window.show(); initComponent: function() {
}, LoginWindow.superclass.initComponent.call();
Deluge.Events.on('logout', this.onLogout);
this.on('show', this.onShow, this);
onKey: function(field, e) { this.addButton({
if (e.getKey() == 13) Deluge.Login.onLogin(); text: _('Login'),
}, handler: this.onLogin,
scope: this
});
onRender: function() { this.loginForm = this.add({
Deluge.Events.on('logout', this.onLogout); 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
}
}
}]
});
},
Deluge.Login.Form = new Ext.form.FormPanel({ onKey: function(field, e) {
defaultType: 'textfield', if (e.getKey() == 13) this.onLogin();
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({ onLogin: function() {
layout: 'fit', var passwordField = this.loginForm.items.get('password');
width: 300, Deluge.Client.web.login(passwordField.getValue(), {
height: 120, onSuccess: function(result) {
bodyStyle: 'padding: 10px 5px;', if (result == true) {
buttonAlign: 'center', this.hide();
closeAction: 'hide', Deluge.Connections.loginShow();
closable: false, passwordField.setRawValue('');
modal: true, Deluge.Events.fire('login')
plain: true, } else {
title: _('Login'), Ext.MessageBox.show({
iconCls: 'x-deluge-login-window-icon', title: _('Login Failed'),
items: Deluge.Login.Form, msg: _('You entered an incorrect password'),
buttons: [{ buttons: Ext.MessageBox.OK,
text: _('Login'), modal: false,
handler: Deluge.Login.onLogin icon: Ext.MessageBox.WARNING,
}], iconCls: 'x-deluge-icon-warning'
listeners: {'render': {fn: Deluge.Login.onRender, scope: Deluge.Login}} });
}); }
}.bindWithEvent(this)
});
},
onLogout: function() {
this.show();
},
onShow: function() {
var passwordField = this.loginForm.items.get('password');
passwordField.focus(false, 150);
}
});
Deluge.Login = new LoginWindow();
})();

View file

@ -48,7 +48,7 @@ Deluge.UI = {
items: [this.MainPanel] items: [this.MainPanel]
}); });
Deluge.Login.Window.show(); Deluge.Login.show();
Deluge.Events.on("connect", this.onConnect.bindWithEvent(this)); Deluge.Events.on("connect", this.onConnect.bindWithEvent(this));
Deluge.Events.on("disconnect", this.onDisconnect.bindWithEvent(this)); Deluge.Events.on("disconnect", this.onDisconnect.bindWithEvent(this));
@ -56,7 +56,7 @@ Deluge.UI = {
}, },
notify: function(title, message) { notify: function(title, message) {
this.roar.alert(title, message); //this.roar.alert(title, message);
}, },
update: function() { update: function() {