]>
Commit | Line | Data |
---|---|---|
aff192e6 DM |
1 | Ext.define('PVE.window.LoginWindow', { |
2 | extend: 'Ext.window.Window', | |
3 | requires: ['PVE.form.RealmComboBox'], | |
4 | ||
5 | // private | |
6 | onLogon: function() { | |
7 | var me = this; | |
8 | ||
9 | var form = me.getComponent(0).getForm(); | |
10 | ||
11 | if(form.isValid()){ | |
12 | me.el.mask('Please wait...', 'x-mask-loading'); | |
13 | ||
14 | form.submit({ | |
15 | failure: function(f, resp){ | |
16 | me.el.unmask(); | |
17 | Ext.MessageBox.alert('Failure', "Login failed. Please try again", function() { | |
18 | var uf = form.findField('username'); | |
1d95a6b5 | 19 | uf.focus(true, true); |
aff192e6 DM |
20 | }); |
21 | }, | |
22 | success: function(f, resp){ | |
23 | me.el.unmask(); | |
24 | ||
25 | var handler = me.handler || Ext.emptyFn; | |
26 | handler.call(me, resp.result.data); | |
27 | me.close(); | |
28 | } | |
29 | }); | |
30 | } | |
31 | }, | |
32 | ||
33 | initComponent: function() { | |
34 | var me = this; | |
35 | ||
36 | Ext.apply(me, { | |
37 | width: 400, | |
38 | modal: true, | |
39 | border: false, | |
40 | draggable: true, | |
41 | closable: false, | |
42 | resizable: false, | |
43 | layout: 'auto', | |
2198a479 | 44 | title: gettext('Proxmox VE Login'), |
aff192e6 DM |
45 | |
46 | items: [{ | |
47 | xtype: 'form', | |
48 | frame: true, | |
49 | url: '/api2/extjs/access/ticket', | |
50 | ||
51 | fieldDefaults: { | |
1d95a6b5 | 52 | labelAlign: 'right' |
aff192e6 DM |
53 | }, |
54 | ||
55 | defaults: { | |
56 | anchor: '-5', | |
57 | allowBlank: false | |
58 | }, | |
59 | ||
60 | items: [ | |
61 | { | |
62 | xtype: 'textfield', | |
2198a479 | 63 | fieldLabel: gettext('User name'), |
aff192e6 | 64 | name: 'username', |
2198a479 | 65 | blankText: gettext("Enter your user name"), |
aff192e6 | 66 | listeners: { |
1d95a6b5 DM |
67 | afterrender: function(f) { |
68 | // Note: only works if we pass delay 1000 | |
69 | f.focus(true, 1000); | |
aff192e6 DM |
70 | }, |
71 | specialkey: function(f, e) { | |
72 | if (e.getKey() === e.ENTER) { | |
73 | var pf = me.query('textfield[name="password"]')[0]; | |
74 | if (pf.getValue()) { | |
75 | me.onLogon(); | |
76 | } else { | |
77 | pf.focus(false); | |
78 | } | |
79 | } | |
80 | } | |
81 | } | |
82 | }, | |
83 | { | |
84 | xtype: 'textfield', | |
85 | inputType: 'password', | |
2198a479 | 86 | fieldLabel: gettext('Password'), |
aff192e6 | 87 | name: 'password', |
2198a479 | 88 | blankText: gettext("Enter your password"), |
aff192e6 DM |
89 | listeners: { |
90 | specialkey: function(field, e) { | |
91 | if (e.getKey() === e.ENTER) { | |
92 | me.onLogon(); | |
93 | } | |
94 | } | |
95 | } | |
96 | }, | |
97 | { | |
98 | xtype: 'pveRealmComboBox', | |
99 | name: 'realm' | |
2198a479 DM |
100 | }, |
101 | { | |
102 | xtype: 'pveLanguageSelector', | |
103 | fieldLabel: gettext('Language'), | |
104 | value: Ext.util.Cookies.get('PVELangCookie') || 'en', | |
105 | name: 'lang', | |
106 | submitValue: false, | |
107 | listeners: { | |
108 | change: function(t, value) { | |
109 | var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10); | |
110 | Ext.util.Cookies.set('PVELangCookie', value, dt); | |
111 | window.location.reload(); | |
112 | } | |
113 | } | |
aff192e6 DM |
114 | } |
115 | ], | |
116 | buttons: [ | |
117 | { | |
2198a479 | 118 | text: gettext('Login'), |
aff192e6 DM |
119 | handler: function(){ |
120 | me.onLogon(); | |
121 | } | |
122 | } | |
123 | ] | |
124 | }] | |
125 | }); | |
126 | ||
127 | me.callParent(); | |
128 | } | |
129 | }); |