summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/PM/UI/MainController.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-10-02 07:59:30 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-10-02 07:59:30 (UTC)
commit1180b7b195157aaeb4f0d5380e0c886bbd06c2e2 (patch) (unidiff)
tree709e33a09d9325d382aabaf0a0828e20ebdb96db /frontend/delta/js/Clipperz/PM/UI/MainController.js
parent20bea94ab6b91c85b171dcf86baba0a64169d508 (diff)
downloadclipperz-1180b7b195157aaeb4f0d5380e0c886bbd06c2e2.zip
clipperz-1180b7b195157aaeb4f0d5380e0c886bbd06c2e2.tar.gz
clipperz-1180b7b195157aaeb4f0d5380e0c886bbd06c2e2.tar.bz2
Updated /delta
Switched from less to scss. Still no build script to update the final CSS, though. Added preliminary support for storing account data on browser's local storage for offline viewing. No public backend currently support this feature.
Diffstat (limited to 'frontend/delta/js/Clipperz/PM/UI/MainController.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/PM/UI/MainController.js130
1 files changed, 111 insertions, 19 deletions
diff --git a/frontend/delta/js/Clipperz/PM/UI/MainController.js b/frontend/delta/js/Clipperz/PM/UI/MainController.js
index da7540e..20ff041 100644
--- a/frontend/delta/js/Clipperz/PM/UI/MainController.js
+++ b/frontend/delta/js/Clipperz/PM/UI/MainController.js
@@ -13,158 +13,218 @@ refer to http://www.clipperz.com.
13 13
14* Clipperz is distributed in the hope that it will be useful, but 14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of 15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
18 18
19* 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
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/. 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21 21
22*/ 22*/
23 23
24Clipperz.Base.module('Clipperz.PM.UI'); 24Clipperz.Base.module('Clipperz.PM.UI');
25 25
26Clipperz.PM.UI.MainController = function() { 26Clipperz.PM.UI.MainController = function() {
27 var pages; 27 var pages;
28 28
29 this._proxy = null; 29 // this._proxy = null;
30 this._user = null; 30 this._user = null;
31 this._filter= ''; 31 this._filter= '';
32 32
33 //this._currentPage = 'loadingPage'; 33 //this._currentPage = 'loadingPage';
34 34
35 this._pageStack = ['loadingPage']; 35 this._pageStack = ['loadingPage'];
36 this._overlay = new Clipperz.PM.UI.Components.Overlay(); 36 this._overlay = new Clipperz.PM.UI.Components.Overlay();
37 pages = { 37 pages = {
38 'loginPage': new Clipperz.PM.UI.Components.LoginForm(), 38 'loginPage': new Clipperz.PM.UI.Components.LoginForm(),
39 'registrationPage':new Clipperz.PM.UI.Components.RegistrationWizard(), 39 'registrationPage':new Clipperz.PM.UI.Components.RegistrationWizard(),
40 'cardListPage': new Clipperz.PM.UI.Components.CardList(), 40 'cardListPage': new Clipperz.PM.UI.Components.CardList(),
41 'cardDetailPage':new Clipperz.PM.UI.Components.CardDetail({card: {}}), 41 'cardDetailPage':new Clipperz.PM.UI.Components.CardDetail({card: {}}),
42 'preferencePage':new Clipperz.PM.UI.Components.PreferencePage(),
42 'errorPage': new Clipperz.PM.UI.Components.ErrorPage({message:''}) 43 'errorPage': new Clipperz.PM.UI.Components.ErrorPage({message:''})
43 }; 44 };
44 45
45 MochiKit.Base.map(function (anId) {React.renderComponent(pages[anId], MochiKit.DOM.getElement(anId))}, MochiKit.Base.keys(pages)); 46 MochiKit.Base.map(function (anId) {React.renderComponent(pages[anId], MochiKit.DOM.getElement(anId))}, MochiKit.Base.keys(pages));
46 this._pages = pages; 47 this._pages = pages;
47 this.registerForNotificationCenterEvents(); 48 this.registerForNotificationCenterEvents();
49 MochiKit.Signal.connect(MochiKit.DOM.currentDocument(), 'onselectionchange', this, 'selectionChangeHandler');
48 50
49 return this; 51 return this;
50} 52}
51 53
52MochiKit.Base.update(Clipperz.PM.UI.MainController.prototype, { 54MochiKit.Base.update(Clipperz.PM.UI.MainController.prototype, {
53 55
54 toString: function () { 56 toString: function () {
55 return "Clipperz.PM.UI.MainController"; 57 return "Clipperz.PM.UI.MainController";
56 }, 58 },
57 59
58 //========================================================================= 60 //=========================================================================
59 61
60 overlay: function () { 62 overlay: function () {
61 return this._overlay; 63 return this._overlay;
62 }, 64 },
63 65
64 loginForm: function () { 66 loginForm: function () {
65 return this._loginForm; 67 return this._loginForm;
66 }, 68 },
67 69
68 registrationWizard: function () { 70 registrationWizard: function () {
69 return this._registrationWizard; 71 return this._registrationWizard;
70 }, 72 },
71 73
72 //========================================================================= 74 //=========================================================================
73 75
74 isOnline: function() { 76 isOnline: function() {
75 return navigator.onLine; 77 return navigator.onLine;
78 // return false;
76 }, 79 },
77 80
78 hasLocalData: function() { 81 hasLocalData: function() {
79 return false; 82 // return false;
83 return (Clipperz.PM.DataModel.devicePreferences.accountData() != null);
80 }, 84 },
81 85
82 loginMode: function () { 86 loginMode: function () {
83 //PIN is set using this command: 87 //PIN is set using this command:
84 //Clipperz.PM.PIN.setCredentialsWithPIN('1234', {'username':'joe', 'passphrase':'clipperz'}); 88 //Clipperz.PM.PIN.setCredentialsWithPIN('1234', {'username':'joe', 'passphrase':'clipperz'});
85 89
86 return Clipperz.PM.PIN.isSet() ? 'PIN' : 'CREDENTIALS'; 90 return Clipperz.PM.PIN.isSet() ? 'PIN' : 'CREDENTIALS';
87 }, 91 },
88 92
89 //========================================================================= 93 //=========================================================================
90 94
91 pages: function () { 95 pages: function () {
92 return this._pages; 96 return this._pages;
93 }, 97 },
94 98
95 pageStack: function () { 99 pageStack: function () {
96 return this._pageStack; 100 return this._pageStack;
97 }, 101 },
98 102
99 //========================================================================= 103 //=========================================================================
100 104
105 showOfflineError: function () {
106console.log("THE BROWSER IS OFFLINE");
107 },
108
101 selectInitialProxy: function () { 109 selectInitialProxy: function () {
102 if (this.isOnline()) { 110 if (this.isOnline()) {
103 this._proxy = Clipperz.PM.Proxy.defaultProxy; 111 // this._proxy = Clipperz.PM.Proxy.defaultProxy;
104 } else { 112 } else {
105 if (this.hasLocalData()) { 113 if (this.hasLocalData()) {
106 this._proxy = new Clipperz.PM.Proxy.Offline({dataStore: new Clipperz.PM.Proxy.Offline.LocalStorageDataStore(), shouldPayTolls:false}); 114 // this._proxy = new Clipperz.PM.Proxy.Offline({dataStore: new Clipperz.PM.Proxy.Offline.LocalStorageDataStore(), shouldPayTolls:false});
115 Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline({dataStore: new Clipperz.PM.Proxy.Offline.LocalStorageDataStore(), shouldPayTolls:false});
107 } else { 116 } else {
108 this.showOfflineError(); 117 this.showOfflineError();
109 } 118 }
110 } 119 }
111 }, 120 },
112 121
113 proxy: function () { 122 //proxy: function () {
114 return this._proxy; 123 // return this._proxy;
115 }, 124 //},
116 125
117 //========================================================================= 126 //=========================================================================
118 127
119 registerForNotificationCenterEvents: function () { 128 registerForNotificationCenterEvents: function () {
120 var events= ['doLogin', 'registerNewUser', 'showRegistrationForm', 'goBack', 'showRecord', 'searchCards', 'runDirectLogin']; 129 var events= [
130 'doLogin',
131 'registerNewUser',
132 'showRegistrationForm',
133 'goBack',
134 'showRecord',
135 'searchCards',
136 'showPreferences',
137 'runDirectLogin',
138 'synchronizeLocalData'
139 ];
121 var self= this; 140 var self= this;
122 141
123 MochiKit.Base.map(function (anEvent) { 142 MochiKit.Base.map(function (anEvent) {
124 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, anEvent, MochiKit.Base.method(self, anEvent)); 143 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, anEvent, MochiKit.Base.method(self, anEvent));
125 }, events); 144 }, events);
126 145
127 // MochiKit.Signal.connect(window, 'onpopstate', MochiKit.Base.method(this, 'historyGoBack')); 146 // MochiKit.Signal.connect(window, 'onpopstate', MochiKit.Base.method(this, 'historyGoBack'));
128 MochiKit.Signal.connect(window, 'onbeforeunload',MochiKit.Base.method(this, 'shouldExitApp')); 147 MochiKit.Signal.connect(window, 'onbeforeunload',MochiKit.Base.method(this, 'shouldExitApp'));
129 }, 148 },
130 149
131 //------------------------------------------------------------------------- 150 //-------------------------------------------------------------------------
132 151
152 selectionChangeHandler: function (anEvent) {
153 varselection;
154 varselectionRange;
155 varselectionNode;
156 varvalueElement;
157 //other hints: http://www.bearpanther.com/2013/05/27/easy-text-selection-in-mobile-safari/
158 //SELECTION: https://developer.mozilla.org/en-US/docs/Web/API/Selection
159 //RANGE: https://developer.mozilla.org/en-US/docs/Web/API/Range
160 //NODE TYPES: https://developer.mozilla.org/en-US/docs/Web/API/Node.nodeType
161
162 selection = MochiKit.DOM.currentWindow().getSelection();
163//console.log("-- selection", selection);
164 selectionRange = selection.getRangeAt(0);
165 selectionNode = selectionRange.startContainer.childNodes[selectionRange.startOffset];
166//console.log("-- selectionNode", selectionNode);
167
168 if (selectionNode != undefined) {
169 valueElement = MochiKit.DOM.getFirstElementByTagAndClassName('*', 'value', selectionNode);
170//console.log("-- valueElement", valueElement);
171 }
172
173 if ((valueElement != null) && (valueElement != selectionNode)) {
174 var range;
175 range = MochiKit.DOM.currentDocument().createRange();
176 range.selectNodeContents(valueElement);
177 selection.removeAllRanges();
178 selection.addRange(range);
179
180 anEvent.preventDefault();
181 anEvent.stopPropagation();
182
183//console.log("updated selection", MochiKit.DOM.currentWindow().getSelection());
184 }
185//console.log("-----------");
186 },
187
188 //-------------------------------------------------------------------------
189
133 run: function (parameters) { 190 run: function (parameters) {
134 var shouldShowRegistrationForm; 191 var shouldShowRegistrationForm;
192 varcanRegisterNewUsers;
193
194 canRegisterNewUsers = Clipperz.PM.Proxy.defaultProxy.canRegisterNewUsers();
135 195
136 this.selectInitialProxy(); 196 this.selectInitialProxy();
137 shouldShowRegistrationForm = parameters['shouldShowRegistrationForm'] && this.proxy().canRegisterNewUsers(); 197 shouldShowRegistrationForm = parameters['shouldShowRegistrationForm'] && canRegisterNewUsers;
138 this.pages()['loginPage'].setProps({'mode':this.loginMode(), 'isNewUserRegistrationAvailable': this.proxy().canRegisterNewUsers()}); 198 this.pages()['loginPage'].setProps({'mode':this.loginMode(), 'isNewUserRegistrationAvailable':canRegisterNewUsers});
139 199
140 if (shouldShowRegistrationForm) { 200 if (shouldShowRegistrationForm) {
141 this.showRegistrationForm(); 201 this.showRegistrationForm();
142 } else { 202 } else {
143 this.showLoginForm(); 203 this.showLoginForm();
144 } 204 }
145 this.overlay().done("", 0.5); 205 this.overlay().done("", 0.5);
146 }, 206 },
147 207
148 //------------------------------------------------------------------------- 208 //-------------------------------------------------------------------------
149 209
150 showLoginForm: function () { 210 showLoginForm: function () {
151 varloginFormPage; 211 varloginFormPage;
152 212
153 loginFormPage = this.pages()['loginPage']; 213 loginFormPage = this.pages()['loginPage'];
154 loginFormPage.setProps({'mode':this.loginMode(), 'isNewUserRegistrationAvailable': this.proxy().canRegisterNewUsers()}); 214 loginFormPage.setProps({'mode':this.loginMode(), 'isNewUserRegistrationAvailable':Clipperz.PM.Proxy.defaultProxy.canRegisterNewUsers()});
155 this.moveInPage(this.currentPage(), 'loginPage'); 215 this.moveInPage(this.currentPage(), 'loginPage');
156 MochiKit.Async.callLater(0.5, MochiKit.Base.method(loginFormPage, 'setInitialFocus')); 216 MochiKit.Async.callLater(0.5, MochiKit.Base.method(loginFormPage, 'setInitialFocus'));
157 }, 217 },
158 218
159 showRegistrationForm: function () { 219 showRegistrationForm: function () {
160 var currentPage; 220 var currentPage;
161 varregistrationPage; 221 varregistrationPage;
162 222
163 currentPage = this.currentPage(); 223 currentPage = this.currentPage();
164 registrationPage = this.pages()['registrationPage']; 224 registrationPage = this.pages()['registrationPage'];
165 this.setCurrentPage('loginPage'); 225 this.setCurrentPage('loginPage');
166 registrationPage.setProps({}); 226 registrationPage.setProps({});
167 this.moveInPage(currentPage, 'registrationPage'); 227 this.moveInPage(currentPage, 'registrationPage');
168 MochiKit.Async.callLater(0.5, MochiKit.Base.method(registrationPage, 'setInitialFocus')); 228 MochiKit.Async.callLater(0.5, MochiKit.Base.method(registrationPage, 'setInitialFocus'));
169 }, 229 },
170 230
@@ -189,35 +249,35 @@ MochiKit.Base.update(Clipperz.PM.UI.MainController.prototype, {
189 user = new Clipperz.PM.DataModel.User({'username':credentials.username, 'getPassphraseFunction':getPassphraseDelegate}); 249 user = new Clipperz.PM.DataModel.User({'username':credentials.username, 'getPassphraseFunction':getPassphraseDelegate});
190 250
191 deferredResult = new Clipperz.Async.Deferred('MainController.doLogin', {trace:false}); 251 deferredResult = new Clipperz.Async.Deferred('MainController.doLogin', {trace:false});
192 deferredResult.addCallback(MochiKit.Async.wait, 0.1); 252 deferredResult.addCallback(MochiKit.Async.wait, 0.1);
193 deferredResult.addMethod(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'deferredEntropyCollection'); 253 deferredResult.addMethod(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'deferredEntropyCollection');
194 deferredResult.addMethod(user, 'login'); 254 deferredResult.addMethod(user, 'login');
195 deferredResult.addMethod(Clipperz.PM.PIN, 'resetFailedAttemptCount'); 255 deferredResult.addMethod(Clipperz.PM.PIN, 'resetFailedAttemptCount');
196 deferredResult.addMethod(this, 'setUser', user); 256 deferredResult.addMethod(this, 'setUser', user);
197 257
198 // deferredResult.addMethod(this, 'setupApplication'); 258 // deferredResult.addMethod(this, 'setupApplication');
199 deferredResult.addMethod(this, 'runApplication'); 259 deferredResult.addMethod(this, 'runApplication');
200 deferredResult.addMethod(this.overlay(), 'done', "", 1); 260 deferredResult.addMethod(this.overlay(), 'done', "", 1);
201 deferredResult.addErrback(MochiKit.Base.method(this, 'genericErrorHandler', event)); 261 deferredResult.addErrback(MochiKit.Base.method(this, 'genericErrorHandler', event));
202 deferredResult.addErrback(MochiKit.Base.bind(function (anEvent, anError) { 262 deferredResult.addErrback(MochiKit.Base.bind(function (anEvent, anError) {
203 if (anError['isPermanent'] != true) { 263 if (anError['isPermanent'] != true) {
204 this.pages()['loginPage'].setProps({disabled:false, 'mode':this.loginMode()}); 264 this.pages()['loginPage'].setProps({disabled:false, 'mode':this.loginMode()});
205 this.pages()['loginPage'].setInitialFocus(); 265 this.pages()['loginPage'].setInitialFocus();
206 } 266 }
207 return anError; 267 return anError;
208 }, this, event)) 268 }, this, event))
209 deferredResult.callback(); 269 deferredResult.callback();
210 270
211 return deferredResult; 271 return deferredResult;
212 }, 272 },
213 273
214 //------------------------------------------------------------------------- 274 //-------------------------------------------------------------------------
215 275
216 registerNewUser: function (credentials) { 276 registerNewUser: function (credentials) {
217 vardeferredResult; 277 vardeferredResult;
218 278
219 this.overlay().show("creating user"); 279 this.overlay().show("creating user");
220 280
221 this.pages()['registrationPage'].setProps({disabled:true}); 281 this.pages()['registrationPage'].setProps({disabled:true});
222 deferredResult = new Clipperz.Async.Deferred('MainController.registerNewUser', {trace:false}); 282 deferredResult = new Clipperz.Async.Deferred('MainController.registerNewUser', {trace:false});
223 deferredResult.addCallback(Clipperz.PM.DataModel.User.registerNewAccount, 283 deferredResult.addCallback(Clipperz.PM.DataModel.User.registerNewAccount,
@@ -310,79 +370,92 @@ MochiKit.Base.update(Clipperz.PM.UI.MainController.prototype, {
310 }, 370 },
311 371
312 setFilter: function (aValue) { 372 setFilter: function (aValue) {
313 this._filter = aValue; 373 this._filter = aValue;
314 }, 374 },
315 375
316 searchCards: function (someParameters) { 376 searchCards: function (someParameters) {
317//console.log("SEARCH CARDS", someParameters); 377//console.log("SEARCH CARDS", someParameters);
318 this.setFilter(someParameters); 378 this.setFilter(someParameters);
319 this.showRecordList(); 379 this.showRecordList();
320 }, 380 },
321 381
322 //========================================================================= 382 //=========================================================================
323 383
324 runApplication: function () { 384 runApplication: function () {
325 MochiKit.Signal.connect(window, 'onpopstate',MochiKit.Base.method(this, 'historyGoBack')); 385 MochiKit.Signal.connect(window, 'onpopstate',MochiKit.Base.method(this, 'historyGoBack'));
386 /// TODO: remove this TEST HACK
326 this.moveInPage(this.currentPage(), 'cardListPage'); 387 this.moveInPage(this.currentPage(), 'cardListPage');
327 return this.showRecordList(); 388 return this.showRecordList();
389
390 // this.moveInPage(this.currentPage(), 'preferencePage');
328 }, 391 },
329 392
330 showRecord: function (aRecordReference) { 393 showRecord: function (aRecordReference) {
331//console.log("Show Record", aRecordReference); 394//console.log("Show Record", aRecordReference);
332 vardeferredResult; 395 vardeferredResult;
333 396
334 this.pages()['cardListPage'].setProps({selectedCard:aRecordReference}); 397 this.pages()['cardListPage'].setProps({selectedCard:aRecordReference});
335 deferredResult = new Clipperz.Async.Deferred('MainController.runApplication', {trace:false}); 398 deferredResult = new Clipperz.Async.Deferred('MainController.runApplication', {trace:false});
336 // deferredResult.addMethod(this.user(), 'getRecord', aRecordReference['_reference']);
337 deferredResult.addMethod(this.user(), 'getRecord', aRecordReference); 399 deferredResult.addMethod(this.user(), 'getRecord', aRecordReference);
338 deferredResult.addMethodcaller('content'); 400 deferredResult.addMethodcaller('content');
339 deferredResult.addCallback(MochiKit.Base.bind(function (aCard) { 401 deferredResult.addCallback(MochiKit.Base.bind(function (aCard) {
340//console.log("CARD DETAILS", aCard); 402//console.log("CARD DETAILS", aCard);
341 this.pages()['cardDetailPage'].setProps({card: aCard}); 403 this.pages()['cardDetailPage'].setProps({card: aCard});
342 this.pages()['cardListPage'].setProps({selectedCard: null}); 404 this.pages()['cardListPage'].setProps({selectedCard: null});
343 }, this)); 405 }, this));
344 deferredResult.addMethod(this, 'moveInPage', this.currentPage(), 'cardDetailPage', true); 406 deferredResult.addMethod(this, 'moveInPage', this.currentPage(), 'cardDetailPage', true);
345 deferredResult.callback(); 407 deferredResult.callback();
346 408
347 return deferredResult; 409 return deferredResult;
348 }, 410 },
349 411
350 runDirectLogin: function (someParameters) { 412 runDirectLogin: function (someParameters) {
351console.log("RUN DIRECT LOGIN", someParameters); 413//console.log("RUN DIRECT LOGIN", someParameters);
352 vardeferredResult; 414 vardeferredResult;
353 415
354 // this.pages()['cardListPage'].setProps({selectedCard:aRecordReference});
355 deferredResult = new Clipperz.Async.Deferred('MainController.runDirectLogin', {trace:false}); 416 deferredResult = new Clipperz.Async.Deferred('MainController.runDirectLogin', {trace:false});
356 // deferredResult.addMethod(this.user(), 'getRecord', aRecordReference['_reference']);
357 deferredResult.addMethod(this.user(), 'getRecord', someParameters['record']); 417 deferredResult.addMethod(this.user(), 'getRecord', someParameters['record']);
358 deferredResult.addMethodcaller('directLoginWithReference', someParameters['directLogin']); 418 deferredResult.addMethodcaller('directLoginWithReference', someParameters['directLogin']);
359 deferredResult.addCallback(Clipperz.PM.UI.DirectLoginRunner.openDirectLogin); 419 deferredResult.addCallback(Clipperz.PM.UI.DirectLoginRunner.openDirectLogin);
360 deferredResult.callback(); 420 deferredResult.callback();
361 421
362 return deferredResult; 422 return deferredResult;
363 }, 423 },
364 424
365 shouldExitApp: function (anEvent) { 425 shouldExitApp: function (anEvent) {
366console.log("SHOULD EXIT APP"); 426//console.log("SHOULD EXIT APP");
367 anEvent.preventDefault(); 427 anEvent.preventDefault();
368 anEvent.stopPropagation(); 428 anEvent.stopPropagation();
369 }, 429 },
370 430
371 //========================================================================= 431 //=========================================================================
372 432
433 showPreferences: function (anEvent) {
434 vardeferredResult;
435
436 this.pages()['preferencePage'].setProps({});
437 deferredResult = new Clipperz.Async.Deferred('MainController.showPreferences', {trace:false});
438 deferredResult.addMethod(this, 'moveInPage', this.currentPage(), 'preferencePage', true);
439 deferredResult.callback();
440
441 return deferredResult;
442 },
443
444 //=========================================================================
445
373 genericErrorHandler: function (anEvent, anError) { 446 genericErrorHandler: function (anEvent, anError) {
374 var errorMessage; 447 var errorMessage;
375 varresult; 448 varresult;
376 449
377 result = anError; 450 result = anError;
378 errorMessage = "login failed"; 451 errorMessage = "login failed";
379 452
380 if (anError['isPermanent'] === true) { 453 if (anError['isPermanent'] === true) {
381 this.pages()['errorPage'].setProps({message:anError.message}); 454 this.pages()['errorPage'].setProps({message:anError.message});
382 this.moveInPage(this.currentPage(), 'errorPage'); 455 this.moveInPage(this.currentPage(), 'errorPage');
383 errorMessage = "failure"; 456 errorMessage = "failure";
384 } else { 457 } else {
385 if ('pin' in anEvent) { 458 if ('pin' in anEvent) {
386 errorCount = Clipperz.PM.PIN.recordFailedAttempt(); 459 errorCount = Clipperz.PM.PIN.recordFailedAttempt();
387 if (errorCount == -1) { 460 if (errorCount == -1) {
388 errorMessage = "PIN resetted"; 461 errorMessage = "PIN resetted";
@@ -467,25 +540,44 @@ console.log("SHOULD EXIT APP");
467//console.log("ADD ITEM TO HISTORY - window", window); 540//console.log("ADD ITEM TO HISTORY - window", window);
468//console.log("ADD ITEM TO HISTORY - window.history", window.history); 541//console.log("ADD ITEM TO HISTORY - window.history", window.history);
469 window.history.pushState({'fromPage': fromPage, 'toPage': toPage}); 542 window.history.pushState({'fromPage': fromPage, 'toPage': toPage});
470 //# window.history.pushState(); 543 //# window.history.pushState();
471//console.log("ADDED ITEM TO HISTORY"); 544//console.log("ADDED ITEM TO HISTORY");
472 } else { 545 } else {
473//console.log("Skip HISTORY"); 546//console.log("Skip HISTORY");
474 } 547 }
475 }, 548 },
476 549
477 moveOutPage: function (fromPage, toPage) { 550 moveOutPage: function (fromPage, toPage) {
478 this.slidePage(MochiKit.DOM.getElement(fromPage), MochiKit.DOM.getElement(toPage), 'RIGHT'); 551 this.slidePage(MochiKit.DOM.getElement(fromPage), MochiKit.DOM.getElement(toPage), 'RIGHT');
479 this.setCurrentPage(toPage); 552 this.setCurrentPage(toPage);
480 }, 553 },
481 554
482 //========================================================================= 555 //=========================================================================
556
557 synchronizeLocalData: function (anEvent) {
558 vardeferredResult;
559
560 deferredResult = new Clipperz.Async.Deferred('MainController.synchronizeLocalData', {trace:true});
561 // deferredResult.addMethod(this.proxy(), 'message', 'downloadAccountData', {});
562 deferredResult.addMethod(this.user().connection(), 'message', 'downloadAccountData', {});
563 deferredResult.addCallback(function (aResult) {
564 Clipperz.PM.DataModel.devicePreferences.setAccountDataWityResponse(aResult);
565 // localStorage.setItem('clipperz_dump_data', aResult['data']);
566 // localStorage.setItem('clipperz_dump_version', aResult['version']);
567 // localStorage.setItem('clipperz_dump_date', new Date());
568 })
569 deferredResult.callback();
570
571 return deferredResult;
572 },
573
574 //=========================================================================
483/* 575/*
484 wrongAppVersion: function (anError) { 576 wrongAppVersion: function (anError) {
485 // this.pages()['errorPage'].setProps({message:anError.message}); 577 // this.pages()['errorPage'].setProps({message:anError.message});
486 // this.moveInPage('errorPage', this.currentPage()); 578 // this.moveInPage('errorPage', this.currentPage());
487 }, 579 },
488*/ 580*/
489 //========================================================================= 581 //=========================================================================
490 __syntaxFix__: "syntax fix" 582 __syntaxFix__: "syntax fix"
491}); 583});