author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js | 312 |
1 files changed, 312 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js new file mode 100644 index 0000000..492f815 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js | |||
@@ -0,0 +1,312 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer 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 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } | ||
32 | if (typeof(Clipperz.PM.Components.Compact) == 'undefined') { Clipperz.PM.Components.Compact = {}; } | ||
33 | |||
34 | Clipperz.PM.Components.Compact.CompactInterface = function(anElement, args) { | ||
35 | |||
36 | Clipperz.PM.Components.Compact.CompactInterface.superclass.constructor.call(this, anElement, args); | ||
37 | |||
38 | this._directLoginItemTemplate = null; | ||
39 | this._user = args.user; | ||
40 | this._autoLockTimer = null; | ||
41 | |||
42 | Clipperz.NotificationCenter.register(null, 'updatedProgressState', this, 'userNotificationHandler') | ||
43 | Clipperz.NotificationCenter.register(null, 'directLoginAdded', this, 'directLoginAddedHandler'); | ||
44 | |||
45 | this.render(); | ||
46 | |||
47 | return this; | ||
48 | }; | ||
49 | |||
50 | YAHOO.extendX(Clipperz.PM.Components.Compact.CompactInterface, Clipperz.PM.Components.BaseComponent, { | ||
51 | |||
52 | 'toString': function() { | ||
53 | return "Clipperz.PM.Components.Compact.CompactInterface"; | ||
54 | }, | ||
55 | |||
56 | //----------------------------------------------------- | ||
57 | |||
58 | 'render': function() { | ||
59 | var result; | ||
60 | varlayout; | ||
61 | var registerButton; | ||
62 | |||
63 | //MochiKit.Logging.logDebug(">>> CompactInterface.render"); | ||
64 | this.element().update(""); | ||
65 | |||
66 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', children:[ | ||
67 | {tag:'div', id:this.getId('cantentPanel'), children:[ | ||
68 | {tag:'h4', id:this.getId('message')}, | ||
69 | {tag:'ul', id:'directLogins', children:[]} | ||
70 | ]}, | ||
71 | {tag:'div', id:this.getId('lockPanel'), cls:'lockPanel', children:[ | ||
72 | {tag:'div', htmlString:Clipperz.PM.Strings['lockDescription']}, | ||
73 | {tag:'form', id:'lockDialogForm', children:[ | ||
74 | {tag:'input', type:'password', id:this.getId('lockPassphrase')} | ||
75 | ]}, | ||
76 | {tag:'div', id:this.getId('unlock')} | ||
77 | ]} | ||
78 | ]}); | ||
79 | |||
80 | this.getElement('lockPanel').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); | ||
81 | |||
82 | YAHOO.ext.Element.get('lockBlock').show(); | ||
83 | MochiKit.Signal.connect(YAHOO.ext.Element.get('lock').dom, 'onclick', this, 'doLockEventHandler'); | ||
84 | new YAHOO.ext.Button(this.getId('unlock'), {text:Clipperz.PM.Strings['unlockButtonLabel'], handler:this.doUnlockEventHandler, scope:this, minWidth:0}); | ||
85 | this.getElement('unlock').swallowEvent('click', true); | ||
86 | new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('lockPassphrase')); | ||
87 | MochiKit.Signal.connect('lockDialogForm', 'onsubmit', this, 'doUnlockEventHandler'); | ||
88 | |||
89 | this.getElement('cantentPanel').setVisibilityMode(YAHOO.ext.Element.DISPLAY); | ||
90 | //MochiKit.Logging.logDebug("<<< CompactInterface.render"); | ||
91 | |||
92 | return result; | ||
93 | }, | ||
94 | |||
95 | //----------------------------------------------------- | ||
96 | |||
97 | 'directLoginAddedHandler': function(anEvent) { | ||
98 | this.redrawDirectLoginItems(); | ||
99 | }, | ||
100 | |||
101 | //----------------------------------------------------- | ||
102 | |||
103 | 'compareDirectLogins': function(a, b) { | ||
104 | return MochiKit.Base.compare(a.label().toLowerCase(), b.label().toLowerCase()); | ||
105 | }, | ||
106 | |||
107 | //----------------------------------------------------- | ||
108 | |||
109 | 'redrawDirectLoginItems': function() { | ||
110 | var template; | ||
111 | var allDirectLogins; | ||
112 | |||
113 | this.getElement('message').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); | ||
114 | //MochiKit.Logging.logDebug(">>> CompactInterface.redrawDirectLoginItems"); | ||
115 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 0"); | ||
116 | MochiKit.Iter.forEach(YAHOO.ext.Element.get('directLogins').getChildrenByTagName('li'), function(aDirectLoginElement) { | ||
117 | MochiKit.Signal.disconnectAll(aDirectLoginElement.dom); | ||
118 | //MochiKit.Logging.logDebug("disconnecting IMG " + aDirectLoginElement.getChildrenByTagName('img')[0].dom.src); | ||
119 | MochiKit.Signal.disconnectAll(aDirectLoginElement.getChildrenByTagName('img')[0].dom); | ||
120 | }) | ||
121 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 1"); | ||
122 | YAHOO.ext.Element.get('directLogins').update(""); | ||
123 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 2"); | ||
124 | allDirectLogins = MochiKit.Base.values(this.user().directLoginReferences()); | ||
125 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 3"); | ||
126 | allDirectLogins.sort(this.compareDirectLogins); | ||
127 | |||
128 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 4"); | ||
129 | template = this.directLoginItemTemplate(); | ||
130 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 5"); | ||
131 | MochiKit.Iter.forEach(allDirectLogins, MochiKit.Base.bind(function(aDirectLogin) { | ||
132 | vardirectLoginElement; | ||
133 | varfaviconImageElementID; | ||
134 | |||
135 | faviconImageElementID = aDirectLogin.reference() + "_faviconIMG"; | ||
136 | directLoginElement = template.append('directLogins', { | ||
137 | elementID:faviconImageElementID, | ||
138 | faviconUrl:aDirectLogin.fixedFavicon(), | ||
139 | directLoginTitle:aDirectLogin.label(), | ||
140 | directLoginReference:aDirectLogin.reference() | ||
141 | }, true); | ||
142 | //MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 6: " + recordElement.dom); | ||
143 | directLoginElement.addClassOnOver("hover"); | ||
144 | MochiKit.Signal.connect(directLoginElement.dom, 'onclick', this, 'handleDirectLoginClick'); | ||
145 | |||
146 | MochiKit.Signal.connect(faviconImageElementID, 'onload', this, 'handleLoadedFaviconImage'); | ||
147 | MochiKit.Signal.connect(faviconImageElementID, 'onerror', aDirectLogin, 'handleMissingFaviconImage'); | ||
148 | MochiKit.Signal.connect(faviconImageElementID, 'onabort', aDirectLogin, 'handleMissingFaviconImage'); | ||
149 | |||
150 | // YAHOO.ext.Element.get(faviconImageElementID).dom.src = aDirectLogin.fixedFavicon(); | ||
151 | }, this)); | ||
152 | |||
153 | this.resetAutoLockTimer(); | ||
154 | //MochiKit.Logging.logDebug("<<< CompactInterface.redrawDirectLoginItems"); | ||
155 | }, | ||
156 | |||
157 | //----------------------------------------------------- | ||
158 | |||
159 | 'directLoginItemTemplate': function() { | ||
160 | if (this._directLoginItemTemplate == null) { | ||
161 | this._directLoginItemTemplate = Clipperz.YUI.DomHelper.createTemplate({tag:'li', id:'{directLoginReference}', children:[ | ||
162 | {tag:'table', border:'0', cellpadding:'0', cellspacing:'0', children:[ | ||
163 | {tag:'tbody', children:[ | ||
164 | {tag:'tr', children:[ | ||
165 | {tag:'td', width:'20', align:'center', valign:'top', children:[ | ||
166 | {tag:'img', id:'{elementID}', src:'{faviconUrl}'} | ||
167 | ]}, | ||
168 | {tag:'td', valign:'top', children:[ | ||
169 | {tag:'a', cls:'directLoginItemTitle', html:'{directLoginTitle}'} | ||
170 | ]} | ||
171 | ]} | ||
172 | ]} | ||
173 | ]} | ||
174 | ]}); | ||
175 | this._directLoginItemTemplate.compile(); | ||
176 | } | ||
177 | |||
178 | return this._directLoginItemTemplate; | ||
179 | }, | ||
180 | |||
181 | //------------------------------------------------------------------------- | ||
182 | |||
183 | 'handleDirectLoginClick': function(anEvent) { | ||
184 | vardirectLoginReference; | ||
185 | //MochiKit.Logging.logDebug(">>> MainPanel.handleDirectLoginClick !!!"); | ||
186 | |||
187 | directLoginReference = this.user().directLoginReferences()[anEvent.src().id]; | ||
188 | this.openDirectLogin(directLoginReference); | ||
189 | this.resetAutoLockTimer(); | ||
190 | //MochiKit.Logging.logDebug("<<< MainPanel.handleDirectLoginClick"); | ||
191 | }, | ||
192 | |||
193 | //----------------------------------------------------- | ||
194 | |||
195 | 'openDirectLogin': function(aDirectLoginReference) { | ||
196 | vardeferredResult; | ||
197 | varnewWindow; | ||
198 | |||
199 | //MochiKit.Logging.logDebug(">>> MainPanel.openDirectLogin - " + aDirectLoginReference.label()); | ||
200 | deferredResult = new MochiKit.Async.Deferred(); | ||
201 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("MainPanel.openDirectLogin - 1: " + res); return res;}); | ||
202 | deferredResult.addCallback(MochiKit.Base.method(aDirectLoginReference, 'setupJumpPageWindow')); | ||
203 | deferredResult.addCallback(MochiKit.Base.method(aDirectLoginReference, 'deferredDirectLogin')); | ||
204 | deferredResult.addCallback(function(aDirectLogin) { | ||
205 | aDirectLogin.runDirectLogin(newWindow); | ||
206 | }); | ||
207 | |||
208 | newWindow = window.open(Clipperz.PM.Strings['directLoginJumpPageUrl'], ""); | ||
209 | // MochiKit.Signal.connect(newWindow, 'onload', MochiKit.Base.method(deferredResult, 'callback', newWindow)) | ||
210 | // MochiKit.Signal.connect(newWindow, 'onload', MochiKit.Base.partial(alert, "done")); | ||
211 | deferredResult.callback(newWindow); | ||
212 | //MochiKit.Logging.logDebug("<<< MainPanel.openDirectLogin"); | ||
213 | }, | ||
214 | |||
215 | //------------------------------------------------------------------------- | ||
216 | |||
217 | 'handleLoadedFaviconImage': function(anEvent) { | ||
218 | //MochiKit.Logging.logDebug(">>> MainPanel.handleLoadedFaviconImage"); | ||
219 | MochiKit.Signal.disconnectAll(anEvent.src()) | ||
220 | //MochiKit.Logging.logDebug("<<< MainPanel.handleLoadedFaviconImage"); | ||
221 | }, | ||
222 | |||
223 | //------------------------------------------------------------------------- | ||
224 | |||
225 | 'doLockEventHandler': function(anEvent) { | ||
226 | anEvent.stop(); | ||
227 | this.lock(); | ||
228 | }, | ||
229 | |||
230 | 'doUnlockEventHandler': function(anEvent) { | ||
231 | if (typeof(anEvent.stop) != 'undefined') { | ||
232 | anEvent.stop(); | ||
233 | } | ||
234 | this.unlock(); | ||
235 | }, | ||
236 | |||
237 | //------------------------------------------------------------------------- | ||
238 | |||
239 | 'autolock': function() { | ||
240 | varshouldAutoLock; | ||
241 | |||
242 | shouldAutoLock = YAHOO.ext.Element.get('autolock').dom.checked; | ||
243 | |||
244 | if (shouldAutoLock) { | ||
245 | this.lock(); | ||
246 | } else { | ||
247 | this.resetAutoLockTimer(); | ||
248 | } | ||
249 | }, | ||
250 | |||
251 | 'lock': function() { | ||
252 | //MochiKit.Logging.logDebug(">>> lock"); | ||
253 | this.getDom('lockPassphrase').value = ""; | ||
254 | this.getElement('lockPanel').show(); | ||
255 | this.getElement('cantentPanel').hide(); | ||
256 | YAHOO.ext.Element.get('lockBlock').hide(); | ||
257 | //this.getElement('lockPassphrase').focus(); | ||
258 | //MochiKit.Logging.logDebug("<<< lock"); | ||
259 | }, | ||
260 | |||
261 | 'unlock': function(anEvent) { | ||
262 | //MochiKit.Logging.logDebug(">>> unlock"); | ||
263 | if (this.getDom('lockPassphrase').value == this.user().passphrase()) { | ||
264 | this.getElement('lockPanel').hide(); | ||
265 | this.getElement('cantentPanel').show(); | ||
266 | YAHOO.ext.Element.get('lockBlock').show(); | ||
267 | this.resetAutoLockTimer(); | ||
268 | } else { | ||
269 | this.getDom('lockPassphrase').value = ""; | ||
270 | this.getElement('lockPassphrase').focus(); | ||
271 | } | ||
272 | //MochiKit.Logging.logDebug("<<< unlock"); | ||
273 | }, | ||
274 | |||
275 | //------------------------------------------------------------------------- | ||
276 | |||
277 | 'user': function() { | ||
278 | return this._user; | ||
279 | }, | ||
280 | |||
281 | //----------------------------------------------------- | ||
282 | |||
283 | 'autoLockTimer': function() { | ||
284 | if (this._autoLockTimer == null) { | ||
285 | //MochiKit.Logging.logDebug("--- timer started - 1"); | ||
286 | this._autoLockTimer = MochiKit.Async.callLater(60, MochiKit.Base.method(this, 'autolock')); | ||
287 | //MochiKit.Logging.logDebug("--- timer started - 2"); | ||
288 | } | ||
289 | |||
290 | return this._autoLockTimer; | ||
291 | }, | ||
292 | |||
293 | 'resetAutoLockTimer': function() { | ||
294 | //MochiKit.Logging.logDebug(">>> timer resetted"); | ||
295 | this.autoLockTimer().cancel(); | ||
296 | this._autoLockTimer = null; | ||
297 | //MochiKit.Logging.logDebug("--- timer resetted - 1"); | ||
298 | this.autoLockTimer(); | ||
299 | //MochiKit.Logging.logDebug("<<< timer resetted"); | ||
300 | }, | ||
301 | |||
302 | //----------------------------------------------------- | ||
303 | |||
304 | 'userNotificationHandler': function(anEvent) { | ||
305 | this.getElement('message').update(anEvent.parameters().text); | ||
306 | }, | ||
307 | |||
308 | //----------------------------------------------------- | ||
309 | __syntaxFix__: '__syntaxFix__' | ||
310 | }); | ||
311 | |||
312 | |||