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 | 28 |
1 files changed, 10 insertions, 18 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 index c83e3c0..9194125 100644 --- a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js +++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/MainController.js | |||
@@ -1,215 +1,207 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers'); | 24 | Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers'); |
27 | 25 | ||
28 | Clipperz.PM.UI.Web.Controllers.MainController = function(args) { | 26 | Clipperz.PM.UI.Web.Controllers.MainController = function(args) { |
29 | this._args = args; | 27 | this._args = args; |
30 | 28 | ||
31 | //controllers | 29 | //controllers |
32 | this._loginController =null; | 30 | this._loginController =null; |
33 | this._appController =null; | 31 | this._appController =null; |
34 | 32 | ||
35 | //components | 33 | //components |
36 | this._headerComponent = null; | 34 | this._headerComponent = null; |
37 | this._pageComponent =null; | 35 | this._pageComponent =null; |
38 | this._footerComponent = null; | 36 | this._footerComponent = null; |
39 | 37 | ||
40 | this._passphraseDelegateLock = new MochiKit.Async.DeferredLock(); | 38 | this._passphraseDelegateLock = new MochiKit.Async.DeferredLock(); |
41 | this._passphraseDelegateLock.acquire(); | 39 | this._passphraseDelegateLock.acquire(); |
42 | //Clipperz.log('MainController init _passphraseDelegateLock', this._passphraseDelegateLock); | 40 | //Clipperz.log('MainController init _passphraseDelegateLock', this._passphraseDelegateLock); |
43 | this._passphraseDelegate = null; | 41 | this._passphraseDelegate = null; |
44 | 42 | ||
45 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestSent', this, 'handleRemoteRequestSent'); | 43 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestSent', this, 'handleRemoteRequestSent'); |
46 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestReceived',this, 'handleRemoteRequestReceived'); | 44 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'remoteRequestReceived',this, 'handleRemoteRequestReceived'); |
47 | 45 | ||
48 | return this; | 46 | return this; |
49 | } | 47 | } |
50 | 48 | ||
51 | MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.MainController.prototype, { | 49 | MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.MainController.prototype, { |
52 | 50 | ||
53 | 'toString': function() { | 51 | 'toString': function() { |
54 | return "Clipperz.PM.UI.Web.Controllers.MainController"; | 52 | return "Clipperz.PM.UI.Web.Controllers.MainController"; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | 'args': function () { | 55 | 'args': function () { |
58 | return this._args; | 56 | return this._args; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | //----------------------------------------------------------------------------- | 59 | //----------------------------------------------------------------------------- |
62 | 60 | ||
63 | 'headerComponent': function() { | 61 | 'headerComponent': function() { |
64 | if (this._headerComponent == null) { | 62 | if (this._headerComponent == null) { |
65 | this._headerComponent = new Clipperz.PM.UI.Web.Components.PageHeader(); | 63 | this._headerComponent = new Clipperz.PM.UI.Web.Components.PageHeader(); |
66 | } | 64 | } |
67 | 65 | ||
68 | return this._headerComponent; | 66 | return this._headerComponent; |
69 | }, | 67 | }, |
70 | 68 | ||
71 | 'footerComponent': function() { | 69 | 'footerComponent': function() { |
72 | if (this._footerComponent == null) { | 70 | if (this._footerComponent == null) { |
73 | this._footerComponent = new Clipperz.PM.UI.Web.Components.PageFooter(); | 71 | this._footerComponent = new Clipperz.PM.UI.Web.Components.PageFooter(); |
74 | } | 72 | } |
75 | 73 | ||
76 | return this._footerComponent; | 74 | return this._footerComponent; |
77 | }, | 75 | }, |
78 | 76 | ||
79 | //----------------------------------------------------------------------------- | 77 | //----------------------------------------------------------------------------- |
80 | 78 | ||
81 | 'pageComponent': function() { | 79 | 'pageComponent': function() { |
82 | if (this._pageComponent == null) { | 80 | if (this._pageComponent == null) { |
83 | this._pageComponent = new Clipperz.PM.UI.Web.Components.Page({element:MochiKit.DOM.getElement('mainDiv')}); | 81 | this._pageComponent = new Clipperz.PM.UI.Web.Components.Page({element:MochiKit.DOM.getElement('mainDiv')}); |
84 | } | 82 | } |
85 | 83 | ||
86 | return this._pageComponent; | 84 | return this._pageComponent; |
87 | }, | 85 | }, |
88 | 86 | ||
89 | //----------------------------------------------------------------------------- | 87 | //----------------------------------------------------------------------------- |
90 | 88 | ||
91 | 'loginController': function() { | 89 | 'loginController': function() { |
92 | if (this._loginController == null) { | 90 | if (this._loginController == null) { |
93 | this._loginController = new Clipperz.PM.UI.Web.Controllers.LoginController(this.args()); | 91 | this._loginController = new Clipperz.PM.UI.Web.Controllers.LoginController(this.args()); |
94 | 92 | ||
95 | MochiKit.Signal.connect(this._loginController, 'userLoggedIn', this, 'loginControllerUserLoggedInCallback'); | 93 | MochiKit.Signal.connect(this._loginController, 'userLoggedIn', this, 'loginControllerUserLoggedInCallback'); |
96 | } | 94 | } |
97 | 95 | ||
98 | return this._loginController; | 96 | return this._loginController; |
99 | }, | 97 | }, |
100 | 98 | ||
101 | 'appController': function() { | 99 | 'appController': function() { |
102 | if (this._appController == null) { | 100 | if (this._appController == null) { |
103 | this._appController = new Clipperz.PM.UI.Web.Controllers.AppController(); | 101 | this._appController = new Clipperz.PM.UI.Web.Controllers.AppController(); |
104 | 102 | ||
105 | MochiKit.Signal.connect(this._appController, 'logout', this, 'handleLogout'); | 103 | MochiKit.Signal.connect(this._appController, 'logout', this, 'handleLogout'); |
106 | } | 104 | } |
107 | 105 | ||
108 | return this._appController; | 106 | return this._appController; |
109 | }, | 107 | }, |
110 | 108 | ||
111 | //----------------------------------------------------------------------------- | 109 | //----------------------------------------------------------------------------- |
112 | 110 | ||
113 | 'run': function(shoudShowRegistrationForm) { | 111 | 'run': function(shoudShowRegistrationForm) { |
114 | this.pageComponent().slotNamed('header').setContent(this.headerComponent()); | 112 | this.pageComponent().slotNamed('header').setContent(this.headerComponent()); |
115 | this.pageComponent().slotNamed('footer').setContent(this.footerComponent()); | 113 | this.pageComponent().slotNamed('footer').setContent(this.footerComponent()); |
116 | 114 | ||
117 | this.pageComponent().render(); | 115 | this.pageComponent().render(); |
118 | 116 | ||
119 | this.loginController().run({slot:this.pageComponent().slotNamed('body')}); | 117 | this.loginController().run({slot:this.pageComponent().slotNamed('body')}); |
120 | 118 | ||
121 | if (shoudShowRegistrationForm) { | 119 | if (shoudShowRegistrationForm) { |
122 | MochiKit.Signal.signal(this.loginController().loginPage(), 'createNewAccountClick'); | 120 | MochiKit.Signal.signal(this.loginController().loginPage(), 'createNewAccountClick'); |
123 | // this.loginController().handleCreateNewAccountClick(); | 121 | // this.loginController().handleCreateNewAccountClick(); |
124 | } | 122 | } |
125 | }, | 123 | }, |
126 | 124 | ||
127 | //----------------------------------------------------------------------------- | 125 | //----------------------------------------------------------------------------- |
128 | 126 | ||
129 | 'getPassphrase': function () { | 127 | 'getPassphrase': function () { |
130 | var deferredResult; | 128 | var deferredResult; |
131 | 129 | ||
132 | deferredResult = new Clipperz.Async.Deferred("MainController.getPassphrase", {trace:false}); | 130 | deferredResult = new Clipperz.Async.Deferred("MainController.getPassphrase", {trace:false}); |
133 | 131 | ||
134 | deferredResult.acquireLock(this._passphraseDelegateLock); | 132 | deferredResult.acquireLock(this._passphraseDelegateLock); |
135 | deferredResult.addMethod(this, 'invokePassphraseDelegate'); | 133 | deferredResult.addMethod(this, 'invokePassphraseDelegate'); |
136 | deferredResult.releaseLock(this._passphraseDelegateLock); | 134 | deferredResult.releaseLock(this._passphraseDelegateLock); |
137 | deferredResult.callback(); | 135 | deferredResult.callback(); |
138 | 136 | ||
139 | return deferredResult; | 137 | return deferredResult; |
140 | }, | 138 | }, |
141 | 139 | ||
142 | //......................................................................... | 140 | //......................................................................... |
143 | 141 | ||
144 | 'invokePassphraseDelegate': function () { | 142 | 'invokePassphraseDelegate': function () { |
145 | return this._passphraseDelegate(); | 143 | return this._passphraseDelegate(); |
146 | }, | 144 | }, |
147 | 145 | ||
148 | 'passphraseDelegateLock': function () { | 146 | 'passphraseDelegateLock': function () { |
149 | return this._passphraseDelegateLock; | 147 | return this._passphraseDelegateLock; |
150 | }, | 148 | }, |
151 | 149 | ||
152 | //......................................................................... | 150 | //......................................................................... |
153 | 151 | ||
154 | 'setPassphraseDelegate': function (aDelegate) { | 152 | 'setPassphraseDelegate': function (aDelegate) { |
155 | var shouldReleaseLock; | 153 | var shouldReleaseLock; |
156 | 154 | ||
157 | shouldReleaseLock = (this._passphraseDelegate == null); | 155 | shouldReleaseLock = (this._passphraseDelegate == null); |
158 | 156 | ||
159 | this._passphraseDelegate = aDelegate; | 157 | this._passphraseDelegate = aDelegate; |
160 | 158 | ||
161 | if (shouldReleaseLock) { | 159 | if (shouldReleaseLock) { |
162 | this._passphraseDelegateLock.release(); | 160 | this._passphraseDelegateLock.release(); |
163 | } | 161 | } |
164 | }, | 162 | }, |
165 | 163 | ||
166 | //......................................................................... | 164 | //......................................................................... |
167 | 165 | ||
168 | 'removePassphraseDelegate': function (aDelegate) { | 166 | 'removePassphraseDelegate': function (aDelegate) { |
169 | if (this._passphraseDelegate == aDelegate) { | 167 | if (this._passphraseDelegate == aDelegate) { |
170 | this._passphraseDelegate = null; | 168 | this._passphraseDelegate = null; |
171 | this._passphraseDelegateLock.acquire(); | 169 | this._passphraseDelegateLock.acquire(); |
172 | } | 170 | } |
173 | }, | 171 | }, |
174 | 172 | ||
175 | //------------------------------------------------------------------------- | 173 | //------------------------------------------------------------------------- |
176 | 174 | ||
177 | 'loginControllerUserLoggedInCallback': function(anEvent) { | 175 | 'loginControllerUserLoggedInCallback': function(anEvent) { |
178 | //Clipperz.log(">>> loginControllerUserLoggedInCallback", anEvent); | ||
179 | // this.setUser(anEvent.parameters()['user']); | ||
180 | //console.log("--- loginControllerUserLoggedInCallback - 1"); | ||
181 | |||
182 | //console.log("--- loginControllerUserLoggedInCallback - 2"); | ||
183 | this.headerComponent().switchToLoggedMode(); | 176 | this.headerComponent().switchToLoggedMode(); |
184 | this.appController().run({slot:this.pageComponent().slotNamed('body'), user:anEvent['user']}); | 177 | this.appController().run({slot:this.pageComponent().slotNamed('body'), user:anEvent['user']}); |
185 | //Clipperz.log("<<< loginControllerUserLoggedInCallback"); | ||
186 | }, | 178 | }, |
187 | 179 | ||
188 | //----------------------------------------------------------------------------- | 180 | //----------------------------------------------------------------------------- |
189 | 181 | ||
190 | 'handleRemoteRequestSent': function () { | 182 | 'handleRemoteRequestSent': function () { |
191 | //Clipperz.log("REMOTE REQUEST sent >>>"); | 183 | //Clipperz.log("REMOTE REQUEST sent >>>"); |
192 | }, | 184 | }, |
193 | 185 | ||
194 | 'handleRemoteRequestReceived': function () { | 186 | 'handleRemoteRequestReceived': function () { |
195 | //Clipperz.log("REMOTE REQUEST received <<<"); | 187 | //Clipperz.log("REMOTE REQUEST received <<<"); |
196 | }, | 188 | }, |
197 | 189 | ||
198 | //----------------------------------------------------------------------------- | 190 | //----------------------------------------------------------------------------- |
199 | 191 | ||
200 | 'handleLogout': function(anEvent) { | 192 | 'handleLogout': function(anEvent) { |
201 | this.exit('logout.html'); | 193 | this.exit('logout.html'); |
202 | }, | 194 | }, |
203 | 195 | ||
204 | //----------------------------------------------------------------------------- | 196 | //----------------------------------------------------------------------------- |
205 | 197 | ||
206 | 'exit': function(aPageName) { | 198 | 'exit': function(aPageName) { |
207 | //Clipperz.log("### exit " + aPageName); | 199 | //Clipperz.log("### exit " + aPageName); |
208 | MochiKit.Async.wait(0).addCallback(function() { | 200 | MochiKit.Async.wait(0).addCallback(function() { |
209 | window.location.href = "./" + aPageName + "?ln=" + Clipperz.PM.Strings.selectedLanguage; | 201 | window.location.href = "./" + aPageName + "?ln=" + Clipperz.PM.Strings.selectedLanguage; |
210 | }); | 202 | }); |
211 | }, | 203 | }, |
212 | 204 | ||
213 | //----------------------------------------------------------------------------- | 205 | //----------------------------------------------------------------------------- |
214 | __syntaxFix__: "syntax fix" | 206 | __syntaxFix__: "syntax fix" |
215 | }); | 207 | }); |