summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js329
1 files changed, 329 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js
new file mode 100644
index 0000000..05563bf
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/AppController.js
@@ -0,0 +1,329 @@
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
29Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers');
30
31Clipperz.PM.UI.Web.Controllers.AppController = function(args) {
32
33 this._user = null;
34 this._tabSlotNames = {
35 //tabName: slotName
36 'cards': 'cardGrid',
37 // 'directLogins':'directLoginGrid',
38 'account': 'accountPanel',
39 'data': 'dataPanel',
40 'tools': 'toolsPanel'
41 };
42
43 //controllers
44 this._cardsController= null;
45 //this._directLoginsController = null;
46 this._filterController = null; //new Clipperz.PM.UI.Web.Controllers.FilterController();
47
48 //components
49 this._appPage = null;
50 this._userInfoBox = null;
51 this._tabSidePanel = null;
52
53 // MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'editCard', this, 'handleEditCard');
54 // MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'deleteCard',this, 'handleDeleteCard');
55
56 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'userDataSuccessfullySaved',this, 'userDataSuccessfullySavedHandler');
57
58 return this;
59}
60
61MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.AppController.prototype, {
62
63 'toString': function() {
64 return "Clipperz.PM.UI.Web.Controllers.AppController";
65 },
66
67 //-----------------------------------------------------------------------------
68
69 'setUser': function(anUser) {
70 this._user = anUser;
71 },
72
73 'user': function() {
74 return this._user;
75 },
76
77 //-----------------------------------------------------------------------------
78 /*
79 'tabSlotNames': function() {
80 return this._tabSlotNames;
81 },
82*/
83 'slotNameForTab': function(aTabName) {
84 return this._tabSlotNames[aTabName];
85 },
86
87 'hideAllAppPageTabSlots': function() {
88 var aTabName;
89
90 for (aTabName in this._tabSlotNames) {
91 this.appPage().hideSlot(this.slotNameForTab(aTabName));
92 }
93 },
94
95 //-----------------------------------------------------------------------------
96
97 'appPage': function() {
98 if (this._appPage == null) {
99 this._appPage = new Clipperz.PM.UI.Web.Components.AppPage();
100 }
101
102 return this._appPage;
103 },
104
105 //-----------------------------------------------------------------------------
106
107 'tabSidePanel': function() {
108 if (this._tabSidePanel == null) {
109 this._tabSidePanel = new Clipperz.PM.UI.Web.Components.TabSidePanel();
110 }
111
112 return this._tabSidePanel;
113 },
114
115 //-----------------------------------------------------------------------------
116
117 'userInfoBox': function() {
118 if (this._userInfoBox == null) {
119 this._userInfoBox = new Clipperz.PM.UI.Web.Components.UserInfoBox();
120
121 MochiKit.Signal.connect(this._userInfoBox, 'logout',this, 'handleLogout');
122 MochiKit.Signal.connect(this._userInfoBox, 'lock', this, 'handleLock');
123 MochiKit.Signal.connect(this._userInfoBox, 'unlock',this, 'handleUnlock');
124 }
125
126 return this._userInfoBox;
127 },
128
129 //-----------------------------------------------------------------------------
130
131 'accountPanel': function () {
132 if (this._accountPanel == null) {
133 this._accountPanel = new Clipperz.PM.UI.Web.Components.AccountPanel(/*{selected:'Preferences'}*/);
134 }
135
136 return this._accountPanel;
137 },
138
139 //.........................................................................
140
141 'dataPanel': function () {
142 if (this._dataPanel == null) {
143 this._dataPanel = new Clipperz.PM.UI.Web.Components.DataPanel();
144 }
145
146 return this._dataPanel;
147 },
148
149 //.........................................................................
150
151 'toolsPanel': function () {
152 if (this._toolsPanel == null) {
153 this._toolsPanel = new Clipperz.PM.UI.Web.Components.ToolsPanel();
154 }
155
156 return this._toolsPanel;
157 },
158
159 //-----------------------------------------------------------------------------
160
161 'filterController': function () {
162 if (this._filterController == null) {
163 this._filterController = new Clipperz.PM.UI.Web.Controllers.FilterController();
164 }
165
166 return this._filterController;
167 },
168
169 'cardsController': function() {
170 if (this._cardsController == null) {
171 this._cardsController = new Clipperz.PM.UI.Web.Controllers.CardsController({'filterController':this._filterController});
172 }
173
174 return this._cardsController;
175 },
176
177 //-----------------------------------------------------------------------------
178/*
179 'directLoginsController': function() {
180//Clipperz.log(">>> AppController.directLoginsController");
181 if (this._directLoginsController == null) {
182 this._directLoginsController = new Clipperz.PM.UI.Web.Controllers.DirectLoginsController({'filterController':this._filterController});
183 }
184//Clipperz.log("<<< AppController.directLoginsController");
185
186 return this._directLoginsController;
187 },
188*/
189 //-----------------------------------------------------------------------------
190
191 'populateUserInfo': function() {
192 var deferredResult;
193
194 deferredResult = new Clipperz.Async.Deferred("AppController.populateUserInfo", {trace:false});
195 deferredResult.collectResults({
196 'username':MochiKit.Base.methodcaller('displayName'),
197 'cardsNumber':[
198 MochiKit.Base.methodcaller('getRecords'),
199 function (someResults) { return someResults.length; }
200 ],
201 'directLoginsNumber': [
202 MochiKit.Base.methodcaller('getDirectLogins'),
203 function (someResults) { return someResults.length; }
204 ]
205 })
206 deferredResult.addMethod(this.userInfoBox(), 'updateUserDetails');
207 deferredResult.callback(this.user());
208
209 return deferredResult;
210 },
211
212 //-----------------------------------------------------------------------------
213
214 'run': function(args) {
215 var deferredResult;
216 varslot;
217 varpage;
218 var user;
219
220 slot = args.slot;
221 user = args.user;
222
223 this.setUser(user);
224
225 slot.setContent(this.appPage());
226
227 this.appPage().slotNamed('userInfoBox').setContent(this.userInfoBox());
228 this.appPage().slotNamed('tabSidePanel').setContent(this.tabSidePanel());
229
230 this.appPage().slotNamed('accountPanel').setContent(this.accountPanel());
231 this.appPage().slotNamed('dataPanel').setContent(this.dataPanel());
232 this.appPage().slotNamed('toolsPanel').setContent(this.toolsPanel());
233
234 this.hideAllAppPageTabSlots();
235 this.appPage().showSlot(this.slotNameForTab('cards'));
236
237 MochiKit.Signal.connect(this.tabSidePanel(), 'tabSelected',this, 'handleTabSelected');
238 MochiKit.Signal.connect(this.tabSidePanel(), 'addCard', this, 'handleAddCard');
239 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'addCard', this, 'handleAddCard');
240
241 deferredResult = new Clipperz.Async.Deferred("AppController.run", {trace:false});
242
243 deferredResult.addMethod(this.cardsController(), 'run', {slot:this.appPage().slotNamed('cardGrid'), user:user});
244 // deferredResult.addMethod(this.directLoginsController(), 'run', {slot:this.appPage().slotNamed('directLoginGrid'), user:user});
245 deferredResult.addMethod(this, 'populateUserInfo');
246
247 deferredResult.addCallback(MochiKit.Visual.ScrollTo, 'miscLinks', {duration:0});
248 deferredResult.addCallback(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'CARDS_CONTROLLER_DID_RUN');
249 deferredResult.addMethod(this.tabSidePanel(), 'selectTab', 'cards');
250 deferredResult.callback();
251 },
252
253 //-----------------------------------------------------------------------------
254
255 'handleTabSelected': function (selectedTabName) {
256 var aTabName;
257 var aSlotName;
258
259//Clipperz.log(">>> AppController.handleTabSelected", selectedTabName);
260 this.hideAllAppPageTabSlots();
261 this.appPage().showSlot(this.slotNameForTab(selectedTabName));
262
263 switch (selectedTabName) {
264 case 'cards':
265 this.cardsController().focus();
266 break;
267 // case 'directLogins':
268 // this.directLoginsController().focus();
269 // break;
270 case 'data':
271 break;
272 case 'account':
273 break;
274 case 'tools':
275 break;
276 }
277//Clipperz.log("<-- AppController.handleTabSelected", aTabName);
278 },
279
280 //=============================================================================
281
282 'handleAddCard': function (aSourceElement) {
283//Clipperz.log("=== AppController.addCard", aSourceElement);
284 this.cardsController().addCard(aSourceElement);
285 },
286
287 //=============================================================================
288
289 'userDataSuccessfullySavedHandler': function (anEvent) {
290 this.populateUserInfo();
291 },
292
293 //=============================================================================
294
295 'handleLogout': function(anEvent) {
296 var deferredResult;
297
298 deferredResult = new Clipperz.Async.Deferred("AppController.handleLogout", {trace:false});
299 deferredResult.addMethod(this.user(), 'logout');
300 deferredResult.addCallback(MochiKit.Signal.signal, this, 'logout');
301 deferredResult.callback();
302
303 return deferredResult;
304 },
305
306 //-----------------------------------------------------------------------------
307
308 'handleLock': function (anEvent) {
309 return Clipperz.Async.callbacks("AppController.handleLock", [
310 MochiKit.Base.method(this.cardsController(), 'deleteAllCleanTextData'),
311 MochiKit.Base.method(this.user(), 'lock')
312 ], {trace:false});
313 },
314
315 //.............................................................................
316
317 'handleUnlock': function (anEvent) {
318 return Clipperz.Async.callbacks("AppController.handleUnock", [
319 MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'initProgress'),
320 MochiKit.Base.method(this.user(), 'login'),
321 MochiKit.Base.method(this.cardsController(), 'focus'),
322 MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'progressDone'),
323 MochiKit.Base.method(this.userInfoBox(), 'unlock')
324 ], {trace:false});
325 },
326
327 //=============================================================================
328 __syntaxFix__: "syntax fix"
329});