Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js new file mode 100644 index 0000000..aa0d6ad --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js | |||
@@ -0,0 +1,218 @@ | |||
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 | Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers'); | ||
30 | |||
31 | Clipperz.PM.UI.Web.Controllers.MainController = function(args) { | ||
32 | this._args = args; | ||
33 | |||
34 | //controllers | ||
35 | this._loginController =null; | ||
36 | this._appController =null; | ||
37 | |||
38 | //components | ||
39 | this._headerComponent = null; | ||
40 | this._pageComponent =null; | ||
41 | this._footerComponent = null; | ||
42 | |||
43 | this._passphraseDelegateLock = new MochiKit.Async.DeferredLock(); | ||
44 | this._passphraseDelegateLock.acquire(); | ||
45 | //Clipperz.log('MainController init _passphraseDelegateLock', this._passphraseDelegateLock); | ||
46 | this._passphraseDelegate = null; | ||
47 | |||
48 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestSent', this, 'handleRemoteRequestSent'); | ||
49 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestReceived',this, 'handleRemoteRequestReceived'); | ||
50 | |||
51 | return this; | ||
52 | } | ||
53 | |||
54 | MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.MainController.prototype, { | ||
55 | |||
56 | 'toString': function() { | ||
57 | return "Clipperz.PM.UI.Web.Controllers.MainController"; | ||
58 | }, | ||
59 | |||
60 | 'args': function () { | ||
61 | return this._args; | ||
62 | }, | ||
63 | |||
64 | //----------------------------------------------------------------------------- | ||
65 | |||
66 | 'headerComponent': function() { | ||
67 | if (this._headerComponent == null) { | ||
68 | this._headerComponent = new Clipperz.PM.UI.Web.Components.PageHeader(); | ||
69 | } | ||
70 | |||
71 | return this._headerComponent; | ||
72 | }, | ||
73 | |||
74 | 'footerComponent': function() { | ||
75 | if (this._footerComponent == null) { | ||
76 | this._footerComponent = new Clipperz.PM.UI.Web.Components.PageFooter(); | ||
77 | } | ||
78 | |||
79 | return this._footerComponent; | ||
80 | }, | ||
81 | |||
82 | //----------------------------------------------------------------------------- | ||
83 | |||
84 | 'pageComponent': function() { | ||
85 | if (this._pageComponent == null) { | ||
86 | this._pageComponent = new Clipperz.PM.UI.Web.Components.Page({element:MochiKit.DOM.getElement('mainDiv')}); | ||
87 | } | ||
88 | |||
89 | return this._pageComponent; | ||
90 | }, | ||
91 | |||
92 | //----------------------------------------------------------------------------- | ||
93 | |||
94 | 'loginController': function() { | ||
95 | if (this._loginController == null) { | ||
96 | this._loginController = new Clipperz.PM.UI.Web.Controllers.LoginController(this.args()); | ||
97 | |||
98 | MochiKit.Signal.connect(this._loginController, 'userLoggedIn', this, 'loginControllerUserLoggedInCallback'); | ||
99 | } | ||
100 | |||
101 | return this._loginController; | ||
102 | }, | ||
103 | |||
104 | 'appController': function() { | ||
105 | if (this._appController == null) { | ||
106 | this._appController = new Clipperz.PM.UI.Web.Controllers.AppController(); | ||
107 | |||
108 | MochiKit.Signal.connect(this._appController, 'logout', this, 'handleLogout'); | ||
109 | } | ||
110 | |||
111 | return this._appController; | ||
112 | }, | ||
113 | |||
114 | //----------------------------------------------------------------------------- | ||
115 | |||
116 | 'run': function(shoudShowRegistrationForm) { | ||
117 | this.pageComponent().slotNamed('header').setContent(this.headerComponent()); | ||
118 | this.pageComponent().slotNamed('footer').setContent(this.footerComponent()); | ||
119 | |||
120 | this.pageComponent().render(); | ||
121 | |||
122 | this.loginController().run({slot:this.pageComponent().slotNamed('body')}); | ||
123 | |||
124 | if (shoudShowRegistrationForm) { | ||
125 | MochiKit.Signal.signal(this.loginController().loginPage(), 'createNewAccountClick'); | ||
126 | // this.loginController().handleCreateNewAccountClick(); | ||
127 | } | ||
128 | }, | ||
129 | |||
130 | //----------------------------------------------------------------------------- | ||
131 | |||
132 | 'getPassphrase': function () { | ||
133 | var deferredResult; | ||
134 | |||
135 | deferredResult = new Clipperz.Async.Deferred("MainController.getPassphrase", {trace:false}); | ||
136 | |||
137 | deferredResult.acquireLock(this._passphraseDelegateLock); | ||
138 | deferredResult.addMethod(this, 'invokePassphraseDelegate'); | ||
139 | deferredResult.releaseLock(this._passphraseDelegateLock); | ||
140 | deferredResult.callback(); | ||
141 | |||
142 | return deferredResult; | ||
143 | }, | ||
144 | |||
145 | //......................................................................... | ||
146 | |||
147 | 'invokePassphraseDelegate': function () { | ||
148 | return this._passphraseDelegate(); | ||
149 | }, | ||
150 | |||
151 | 'passphraseDelegateLock': function () { | ||
152 | return this._passphraseDelegateLock; | ||
153 | }, | ||
154 | |||
155 | //......................................................................... | ||
156 | |||
157 | 'setPassphraseDelegate': function (aDelegate) { | ||
158 | var shouldReleaseLock; | ||
159 | |||
160 | shouldReleaseLock = (this._passphraseDelegate == null); | ||
161 | |||
162 | this._passphraseDelegate = aDelegate; | ||
163 | |||
164 | if (shouldReleaseLock) { | ||
165 | this._passphraseDelegateLock.release(); | ||
166 | } | ||
167 | }, | ||
168 | |||
169 | //......................................................................... | ||
170 | |||
171 | 'removePassphraseDelegate': function (aDelegate) { | ||
172 | if (this._passphraseDelegate == aDelegate) { | ||
173 | this._passphraseDelegate = null; | ||
174 | this._passphraseDelegateLock.acquire(); | ||
175 | } | ||
176 | }, | ||
177 | |||
178 | //------------------------------------------------------------------------- | ||
179 | |||
180 | 'loginControllerUserLoggedInCallback': function(anEvent) { | ||
181 | //Clipperz.log(">>> loginControllerUserLoggedInCallback", anEvent); | ||
182 | // this.setUser(anEvent.parameters()['user']); | ||
183 | //console.log("--- loginControllerUserLoggedInCallback - 1"); | ||
184 | |||
185 | //console.log("--- loginControllerUserLoggedInCallback - 2"); | ||
186 | this.headerComponent().switchToLoggedMode(); | ||
187 | this.appController().run({slot:this.pageComponent().slotNamed('body'), user:anEvent['user']}); | ||
188 | //Clipperz.log("<<< loginControllerUserLoggedInCallback"); | ||
189 | }, | ||
190 | |||
191 | //----------------------------------------------------------------------------- | ||
192 | |||
193 | 'handleRemoteRequestSent': function () { | ||
194 | //Clipperz.log("REMOTE REQUEST sent >>>"); | ||
195 | }, | ||
196 | |||
197 | 'handleRemoteRequestReceived': function () { | ||
198 | //Clipperz.log("REMOTE REQUEST received <<<"); | ||
199 | }, | ||
200 | |||
201 | //----------------------------------------------------------------------------- | ||
202 | |||
203 | 'handleLogout': function(anEvent) { | ||
204 | this.exit('logout.html'); | ||
205 | }, | ||
206 | |||
207 | //----------------------------------------------------------------------------- | ||
208 | |||
209 | 'exit': function(aPageName) { | ||
210 | //Clipperz.log("### exit " + aPageName); | ||
211 | MochiKit.Async.wait(0).addCallback(function() { | ||
212 | window.location.href = "./" + aPageName + "?ln=" + Clipperz.PM.Strings.selectedLanguage; | ||
213 | }); | ||
214 | }, | ||
215 | |||
216 | //----------------------------------------------------------------------------- | ||
217 | __syntaxFix__: "syntax fix" | ||
218 | }); | ||