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,13 +21,70 @@ Copyright:
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
Deluge.Login = { (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() { onLogin: function() {
var passwordField = Deluge.Login.Form.items.get('password'); var passwordField = this.loginForm.items.get('password');
Deluge.Client.web.login(passwordField.getValue(), { Deluge.Client.web.login(passwordField.getValue(), {
onSuccess: function(result) { onSuccess: function(result) {
if (result == true) { if (result == true) {
Deluge.Login.Window.hide(); this.hide();
Deluge.Connections.loginShow(); Deluge.Connections.loginShow();
passwordField.setRawValue(''); passwordField.setRawValue('');
Deluge.Events.fire('login') Deluge.Events.fire('login')
@ -41,59 +98,19 @@ Deluge.Login = {
iconCls: 'x-deluge-icon-warning' iconCls: 'x-deluge-icon-warning'
}); });
} }
} }.bindWithEvent(this)
}); });
}, },
onLogout: function() { onLogout: function() {
Deluge.Login.Window.show(); this.show();
}, },
onKey: function(field, e) { onShow: function() {
if (e.getKey() == 13) Deluge.Login.onLogin(); var passwordField = this.loginForm.items.get('password');
}, passwordField.focus(false, 150);
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({ Deluge.Login = new LoginWindow();
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}}
});

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() {