summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js189
1 files changed, 189 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js b/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js
new file mode 100644
index 0000000..d708464
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js
@@ -0,0 +1,189 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; }
32if (typeof(Clipperz.PM.Components.Compact) == 'undefined') { Clipperz.PM.Components.Compact = {}; }
33
34Clipperz.PM.Components.Compact.LoginForm = function(anElement, args) {
35
36 Clipperz.PM.Components.Compact.LoginForm.superclass.constructor.call(this, anElement, args);
37
38 this.render();
39 Clipperz.NotificationCenter.register(null, 'updatedProgressState', this, 'userNotificationHandler')
40
41 return this;
42};
43
44YAHOO.extendX(Clipperz.PM.Components.Compact.LoginForm, Clipperz.PM.Components.BaseComponent, {
45
46 'toString': function() {
47 return "Clipperz.PM.Components.Compact.LoginForm";
48 },
49
50 //-----------------------------------------------------
51
52 'render': function() {
53 var result;
54 varlayout;
55
56 MochiKit.Signal.disconnectAllTo(this);
57 this.element().update("");
58
59 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', id:this.getId('baseDiv'), cls:'LoginPanel', children:[
60 {tag:'div', id:'compactHeader'},
61 {tag:'div', id:'compactBody', children:[
62 {tag:'form', id:this.getId('loginForm_form'), children:[
63 {tag:'dl', children:[
64 {tag:'dt', htmlString:Clipperz.PM.Strings['loginFormUsernameLabel']},
65 {tag:'dd', children:[
66 {tag:'input', id:this.getId('login_username'), type:'text', size:'30', name:'username'}
67 ]},
68 {tag:'dt', htmlString:Clipperz.PM.Strings['loginFormPassphraseLabel']},
69 {tag:'dd', children:[
70 {tag:'input', id:this.getId('login_passphrase'), type:'password', size:'30', name:'passphrase'}
71 ]}
72 ]},
73 {tag:'div', id:this.getId('login_submit')}
74 ]},
75 {tag:'h4', id:this.getId('message')}
76 ]}
77 ]});
78
79 new Clipperz.PM.Components.Compact.CompactHeader(YAHOO.ext.Element.get('compactHeader'));
80
81 MochiKit.Signal.connect(this.getId('loginForm_form'), 'onsubmit', this, 'stopFormSubmit');
82 new YAHOO.ext.Button(this.getId('login_submit'), {text:Clipperz.PM.Strings['loginFormButtonLabel'], handler:this.doLogin, scope:this, minWidth:0});
83 this.getElement('login_submit').swallowEvent('click', true);
84
85 MochiKit.Signal.connect(this.getId('loginForm_form'), 'onkeydown', this, 'onkeydown');
86
87 new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('login_passphrase'));
88 this.getElement('login_username').focus();
89
90 return result;
91 },
92
93 //-----------------------------------------------------
94
95 'doLogin': function(e) {
96//MochiKit.Logging.logDebug(">>> compact.LoginForm.doLogin");
97 if (this.checkLoginForm()) {
98 this.doLoginWithUsernameAndPassphrase(this.getDom('login_username').value, this.getDom('login_passphrase').value);
99 }
100//MochiKit.Logging.logDebug("<<< compact.LoginForm.doLogin");
101 },
102
103 //.........................................................................
104
105 'doLoginWithUsernameAndPassphrase': function(anUsername, aPassphrase) {
106 var deferredResult;
107 var user;
108
109//MochiKit.Logging.logDebug(">>> compact.LoginForm.doLoginWithUsernameAndPassphrase");
110 user = new Clipperz.PM.DataModel.User({username:anUsername, passphrase:aPassphrase});
111
112 deferredResult = new MochiKit.Async.Deferred();
113 deferredResult.addCallback(MochiKit.Base.method(user, 'connect'));
114 deferredResult.addCallback(MochiKit.Base.method(user, 'loadPreferences'));
115 deferredResult.addCallback(MochiKit.Base.method(user, 'loadRecords'));
116 deferredResult.addCallback(MochiKit.Base.method(user, 'loadDirectLogins'));
117 deferredResult.addErrback(MochiKit.Base.bind(function() {
118 this.getElement('loginForm_form').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show();
119 this.getElement('message').update(Clipperz.PM.Strings['loginMessagePanelFailureText']);
120 this.getDom('login_passphrase').value = "";
121 this.getElement('login_passphrase').focus();
122 }, this))
123//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("compact.LoginForm.doLogin - 6: " + res); return res;});
124 deferredResult.callback("token");
125//MochiKit.Logging.logDebug("<<< compact.LoginForm.doLoginWithUsernameAndPassphrase");
126
127 return deferredResult;
128 },
129
130 //.........................................................................
131
132 'checkLoginForm': function() {
133 var result;
134 var username
135 varpassphrase;
136
137//MochiKit.Logging.logDebug(">>> checkLoginForm");
138 username = this.getDom('login_username').value;
139 passphrase = this.getDom('login_passphrase').value;
140
141 if ((username != "") && (passphrase != "")) {
142 result = true;
143 } else {
144 if (username == "") {
145 this.getElement('login_username').focus();
146 } else if (passphrase == "") {
147 this.getElement('login_passphrase').focus();
148 }
149
150 result = false;
151 }
152//MochiKit.Logging.logDebug("<<< checkLoginForm - " + result);
153
154 return result;
155 },
156
157 //-------------------------------------------------------------------------
158
159 'stopFormSubmit': function(anEvent) {
160 anEvent.stop();
161 },
162
163 //-------------------------------------------------------------------------
164
165 'onkeydown': function(anEvent) {
166//MochiKit.Logging.logDebug(">>> onkeydown - " + anEvent.src().id);
167 if (anEvent.key().code == 13) {
168 this.doLogin();
169 anEvent.stop();
170 }
171 },
172
173 //-----------------------------------------------------
174
175 'userNotificationHandler': function(anEvent) {
176//MochiKit.Logging.logDebug(">>> compact.LoginForm.userNotificationHandler");
177//MochiKit.Logging.logDebug("userNotificationHandler - event: " + anEvent.event());
178 this.getElement('loginForm_form').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide();
179 if (this.getDom('message') != null) {
180 this.getElement('message').update(Clipperz.PM.Strings.messagePanelConfigurations[anEvent.parameters()]()['text']);
181 }
182//MochiKit.Logging.logDebug("<<< compact.LoginForm.userNotificationHandler");
183 },
184
185 //-----------------------------------------------------
186 __syntaxFix__: '__syntaxFix__'
187});
188
189