source: deluge/ui/web/js/Deluge.Login.js@ 1157fc

2.0.x develop extjs4-port
Last change on this file since 1157fc was 1157fc, checked in by Damien Churchill <damoc@gmail.com>, 16 years ago

commit all new-style code so it can be versioned, NB: this is in a
broken state currently.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2Script: deluge-login.js
3 Contains all objects and functions related to the login system.
4
5Copyright:
6 (C) Damien Churchill 2009 <damoxc@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, write to:
19 The Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor
21 Boston, MA 02110-1301, USA.
22*/
23
24(function(){
25 Ext.deluge.LoginWindow = Ext.extend(Ext.Window, {
26 constructor: function(config) {
27 config = Ext.apply({
28 layout: 'fit',
29 width: 300,
30 height: 120,
31 bodyStyle: 'padding: 10px 5px;',
32 buttonAlign: 'center',
33 closeAction: 'hide',
34 closable: false,
35 modal: true,
36 plain: true,
37 resizable: false,
38 title: _('Login'),
39 iconCls: 'x-deluge-login-window-icon'
40 }, config);
41 Ext.deluge.LoginWindow.superclass.constructor.call(this, config);
42 },
43
44 initComponent: function() {
45 Ext.deluge.LoginWindow.superclass.initComponent.call(this);
46 Deluge.Events.on('logout', this.onLogout, this);
47 this.on('show', this.onShow, this);
48
49 this.addButton({
50 text: _('Login'),
51 handler: this.onLogin,
52 scope: this
53 });
54
55 this.loginForm = this.add({
56 xtype: 'form',
57 defaultType: 'textfield',
58 id: 'loginForm',
59 baseCls: 'x-plain',
60 labelWidth: 55,
61 items: [{
62 fieldLabel: _('Password'),
63 id: 'password',
64 name: 'password',
65 inputType: 'password',
66 anchor: '100%',
67 listeners: {
68 'specialkey': {
69 fn: this.onKey,
70 scope: this
71 }
72 }
73 }]
74 })
75 },
76
77 onKey: function(field, e) {
78 if (e.getKey() == 13) this.onLogin();
79 },
80
81 onLogin: function() {
82 var passwordField = this.loginForm.items.get('password');
83 Deluge.Client.web.login(passwordField.getValue(), {
84 success: function(result) {
85 if (result == true) {
86 Deluge.Events.fire('login');
87 this.hide();
88 passwordField.setRawValue('');
89 } else {
90 Ext.MessageBox.show({
91 title: _('Login Failed'),
92 msg: _('You entered an incorrect password'),
93 buttons: Ext.MessageBox.OK,
94 modal: false,
95 fn: function() {
96 passwordField.focus();
97 },
98 icon: Ext.MessageBox.WARNING,
99 iconCls: 'x-deluge-icon-warning'
100 });
101 }
102 },
103 scope: this
104 });
105 },
106
107 onLogout: function() {
108 this.show();
109 },
110
111 onShow: function() {
112 var passwordField = this.loginForm.items.get('password');
113 passwordField.focus(false, 150);
114 }
115 });
116
117 Deluge.Login = new Ext.deluge.LoginWindow();
118})();
Note: See TracBrowser for help on using the repository browser.