2013-08-30 17:56:53 +02:00
/ *
2018-11-25 17:31:43 +01:00
Copyright 2008 - 2018 Clipperz Srl
2013-08-30 17:56:53 +02:00
This file is part of Clipperz , the online password manager .
For further information about its features and functionalities please
refer to http : //www.clipperz.com.
* Clipperz is free software : you can redistribute it and / or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
* Clipperz is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU Affero General Public License for more details .
* You should have received a copy of the GNU Affero General Public
License along with Clipperz . If not , see http : //www.gnu.org/licenses/.
* /
2014-07-28 18:07:48 +02:00
"use strict" ;
2013-08-30 17:56:53 +02:00
Clipperz . Base . module ( 'Clipperz.PM.UI' ) ;
Clipperz . PM . UI . MainController = function ( ) {
2013-10-02 09:59:30 +02:00
// this._proxy = null;
2014-07-28 18:07:48 +02:00
this . _mediaQueryStyle = "narrow" ;
2013-08-30 17:56:53 +02:00
this . _user = null ;
2014-07-28 18:07:48 +02:00
this . _filter = { 'type' : 'ALL' } ;
2016-11-27 15:05:10 +01:00
this . _notifications = [ ] ;
2013-08-30 17:56:53 +02:00
2014-07-30 09:28:05 +02:00
this . _shouldIncludeArchivedCards = false ;
2014-07-28 18:07:48 +02:00
this . _isSelectionPanelOpen = false ;
this . _isSettingsPanelOpen = false ;
2016-11-27 15:05:10 +01:00
// this._isAttachmentQueueBoxOpen = false;
// this._isCertificateQueueBoxOpen = false;
2014-07-28 18:07:48 +02:00
2013-08-30 17:56:53 +02:00
this . _pageStack = [ 'loadingPage' ] ;
this . _overlay = new Clipperz . PM . UI . Components . Overlay ( ) ;
2014-07-28 18:07:48 +02:00
this . _isTouchDevice = ( 'ontouchstart' in window || 'onmsgesturechange' in window ) ;
this . _isDesktop = window . screenX != 0 && ! this . _isTouchDevice ;
this . _hasKeyboard = this . _isDesktop ;
2014-10-12 14:30:17 +02:00
2015-09-23 13:44:29 +02:00
this . _userPreferences = null ;
2014-12-30 10:28:59 +01:00
this . _recordsInfo = null ;
2015-01-04 18:50:50 +01:00
this . _selectedCards = null ;
2014-10-12 14:30:17 +02:00
this . _selectedCardInfo = null ;
2014-07-28 18:07:48 +02:00
this . _closeMaskAction = null ;
2015-03-10 22:59:24 +01:00
2015-09-23 10:24:49 +02:00
this . _lockListener = null ;
this . _lockTimeout = null ;
2014-07-28 18:07:48 +02:00
this . _pages = { } ;
this . renderPages ( [
'loginPage' ,
'registrationPage' ,
2015-09-23 10:24:49 +02:00
'unlockPage' ,
2014-07-28 18:07:48 +02:00
'mainPage' ,
'cardDetailPage' ,
'errorPage' ,
] ) ;
this . registerForNotificationCenterEvents ( [
2014-09-19 18:27:26 +02:00
'doLogin' , 'registerNewUser' , 'showRegistrationForm' , 'goBack' ,
2016-03-29 11:45:50 +02:00
'updateUserAccountInfo' ,
2015-09-23 13:44:29 +02:00
'logout' ,
'enableLock' , 'disableLock' , 'unlock' ,
2015-09-30 20:09:58 +02:00
'updatePIN' , 'disablePIN' , 'forcePassphraseLogin' , 'forcePassphraseUnlock' ,
2015-05-21 14:32:51 +02:00
'changePassphrase' , 'deleteAccount' ,
2015-10-06 15:33:42 +02:00
/*'updateUserPreferences',*/ 'setPreferences' ,
2015-06-27 19:08:20 +02:00
'updateOTPListAndDetails' , 'createNewOTP' , 'deleteOTPs' , 'changeOTPLabel' ,
2015-05-21 14:32:51 +02:00
'importCards' ,
'downloadExport' ,
'updateProgress' ,
2016-11-27 15:05:10 +01:00
'toggleSelectionPanel' , 'hideSelectionPanel' , 'toggleSettingsPanel' , // 'toggleAttachmentQueueBox', 'toggleCertificateQueueBox',
2014-09-19 18:27:26 +02:00
'matchMediaQuery' , 'unmatchMediaQuery' ,
2016-03-29 11:45:50 +02:00
'selectAllCards' , 'selectRecentCards' , 'selectCardsWithCertificate' , 'selectCardsWithAttachments' , 'selectUntaggedCards' , 'tagSelected' , 'search' ,
2014-08-22 08:38:53 +02:00
'refreshCardEditDetail' ,
2017-01-21 15:03:42 +01:00
'saveCardEdits' , 'cancelCardEdits' , 'copyFieldValueFeedback' ,
2015-01-04 18:50:50 +01:00
'selectCard' ,
2014-07-28 18:07:48 +02:00
'addCardClick' ,
2016-11-27 15:05:10 +01:00
'deleteCard' , 'toggleArchiveCard' , 'cloneCard' , 'editCard' , // 'createCertificate',
'downloadCertificate' , 'showCertificatePreview' , 'hideCertificatePreview' , 'showCertificateCard' , // 'closeCertificateNotification'
2014-09-19 18:27:26 +02:00
'addTag' , 'removeTag' ,
'showArchivedCards' , 'hideArchivedCards' ,
2014-07-28 18:07:48 +02:00
'goBackToMainPage' ,
'maskClick' ,
2015-08-20 10:52:49 +02:00
'closeHelp' ,
2015-01-02 10:13:04 +01:00
'downloadOfflineCopy' ,
2015-08-26 23:03:41 +02:00
'runDirectLogin' , 'removeDirectLogin' ,
2015-11-23 16:10:44 +01:00
'exitSearch' ,
2016-11-27 15:05:10 +01:00
'addAttachment' , 'removeAttachment' , 'getAttachment' , 'cancelAttachment' , // 'closeAttachmentNotification', 'updateAttachmentQueueInfo',
'addNotification' , 'acknowledgeNotification' ,
2014-07-28 18:07:48 +02:00
] ) ;
2015-11-23 16:10:44 +01:00
this . _attachmentController = new Clipperz . PM . UI . AttachmentController ( {
'uploadMessageCallback' : MochiKit . Base . method ( this , 'uploadMessageCallback' ) ,
'downloadMessageCallback' : MochiKit . Base . method ( this , 'downloadMessageCallback' ) ,
'reloadServerStatusCallback' : MochiKit . Base . method ( this , 'reloadAttachmentServerStatusCallback' )
} ) ;
2016-03-29 11:45:50 +02:00
2016-11-27 15:05:10 +01:00
// this._certificateQueueStatus = [];
2016-03-29 11:45:50 +02:00
document . addEventListener ( 'dragover' , MochiKit . Base . method ( this , 'blockDragOver' ) , false ) ;
2015-11-23 16:10:44 +01:00
2015-01-06 15:42:14 +01:00
Mousetrap . bind ( [ '/' ] , MochiKit . Base . method ( this , 'focusOnSearch' ) ) ;
Mousetrap . bind ( [ 'left' , 'h' , 'esc' ] , MochiKit . Base . method ( this , 'exitCurrentSelection' ) ) ;
Mousetrap . bind ( [ 'right' , 'l' , 'enter' ] , MochiKit . Base . method ( this , 'selectDetail' ) ) ;
Mousetrap . bind ( [ 'up' , 'k' ] , MochiKit . Base . method ( this , 'selectPreviousCard' ) ) ;
Mousetrap . bind ( [ 'down' , 'j' ] , MochiKit . Base . method ( this , 'selectNextCard' ) ) ;
2015-09-10 14:56:07 +02:00
Mousetrap . bind ( [ '*' ] , MochiKit . Base . method ( this , 'selectAllCards_handler' ) ) ;
2013-08-30 17:56:53 +02:00
2015-08-20 10:52:49 +02:00
Mousetrap . bind ( [ '?' ] , MochiKit . Base . method ( this , 'showHelp_handler' ) ) ;
2015-11-24 17:17:29 +01:00
Mousetrap . bind ( [ 'l o c k' ] , MochiKit . Base . method ( this , 'lockShortcut' ) ) ;
2015-08-20 10:52:49 +02:00
2015-08-21 11:42:05 +02:00
// Mousetrap.bind(['t e s t'], MochiKit.Base.method(this, 'downloadExport_handler'));
2013-08-30 17:56:53 +02:00
return this ;
}
MochiKit . Base . update ( Clipperz . PM . UI . MainController . prototype , {
toString : function ( ) {
return "Clipperz.PM.UI.MainController" ;
} ,
//=========================================================================
overlay : function ( ) {
return this . _overlay ;
} ,
2015-05-21 14:32:51 +02:00
updateProgress _handler : function ( aProgressPercentage ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.updateProgress_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'updateProgress' , aProgressPercentage )
] , { trace : false } ) ;
2015-05-21 14:32:51 +02:00
} ,
2013-08-30 17:56:53 +02:00
loginForm : function ( ) {
return this . _loginForm ;
} ,
registrationWizard : function ( ) {
return this . _registrationWizard ;
} ,
//=========================================================================
2015-06-27 19:08:20 +02:00
/ *
proxy : function ( ) {
return this . _proxy ;
} ,
setProxy : function ( aValue ) {
this . _proxy = aValue ;
} ,
* /
//=========================================================================
2013-08-30 17:56:53 +02:00
isOnline : function ( ) {
return navigator . onLine ;
2013-10-02 09:59:30 +02:00
// return false;
2013-08-30 17:56:53 +02:00
} ,
hasLocalData : function ( ) {
2013-10-02 09:59:30 +02:00
// return false;
return ( Clipperz . PM . DataModel . devicePreferences . accountData ( ) != null ) ;
2013-08-30 17:56:53 +02:00
} ,
loginMode : function ( ) {
// PIN is set using this command:
// Clipperz.PM.PIN.setCredentialsWithPIN('1234', {'username':'joe', 'passphrase':'clipperz'});
2015-09-01 12:18:27 +02:00
return ( Clipperz . PM . PIN . isLocalStorageSupported ( ) && Clipperz . PM . PIN . isSet ( ) ) ? 'PIN' : 'CREDENTIALS' ;
2013-08-30 17:56:53 +02:00
} ,
//=========================================================================
pages : function ( ) {
return this . _pages ;
} ,
pageStack : function ( ) {
return this . _pageStack ;
} ,
//=========================================================================
2013-10-02 09:59:30 +02:00
showOfflineError : function ( ) {
2015-09-23 10:24:49 +02:00
Clipperz . log ( "THE BROWSER IS OFFLINE" ) ;
2013-10-02 09:59:30 +02:00
} ,
2013-08-30 17:56:53 +02:00
selectInitialProxy : function ( ) {
if ( this . isOnline ( ) ) {
2013-10-02 09:59:30 +02:00
// this._proxy = Clipperz.PM.Proxy.defaultProxy;
2013-08-30 17:56:53 +02:00
} else {
if ( this . hasLocalData ( ) ) {
2013-10-02 09:59:30 +02:00
// this._proxy = new Clipperz.PM.Proxy.Offline({dataStore: new Clipperz.PM.Proxy.Offline.LocalStorageDataStore(), shouldPayTolls:false});
Clipperz . PM . Proxy . defaultProxy = new Clipperz . PM . Proxy . Offline ( { dataStore : new Clipperz . PM . Proxy . Offline . LocalStorageDataStore ( ) , shouldPayTolls : false } ) ;
2013-08-30 17:56:53 +02:00
} else {
this . showOfflineError ( ) ;
}
}
} ,
2013-10-02 09:59:30 +02:00
// proxy: function () {
// return this._proxy;
// },
2013-08-30 17:56:53 +02:00
//=========================================================================
2014-07-28 18:07:48 +02:00
capitaliseFirstLetter : function ( aValue ) {
return aValue . charAt ( 0 ) . toUpperCase ( ) + aValue . slice ( 1 ) ;
} ,
renderPages : function ( pages ) {
var self = this ;
MochiKit . Iter . forEach ( pages , function ( aPageName ) {
2016-03-29 11:45:50 +02:00
self . _pages [ aPageName ] = ReactDOM . render (
2014-07-28 18:07:48 +02:00
Clipperz . PM . UI . Components . Pages [ self . capitaliseFirstLetter ( aPageName ) ] ( self . pageProperties ( aPageName ) ) ,
MochiKit . DOM . getElement ( aPageName )
) ;
} ) ;
} ,
registerForNotificationCenterEvents : function ( events ) {
var self = this ;
MochiKit . Iter . forEach ( events , function ( anEvent ) {
2016-03-29 11:45:50 +02:00
// MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, anEvent, MochiKit.Base.method(self, anEvent + '_handler'));
MochiKit . Signal . connect ( Clipperz . Signal . NotificationCenter , anEvent , MochiKit . Base . method ( self , 'eventHandlerErrorCatcher' , anEvent ) ) ;
2015-09-23 10:24:49 +02:00
MochiKit . Signal . connect ( Clipperz . Signal . NotificationCenter , anEvent , MochiKit . Base . method ( self , 'resetLockTimeout' ) ) ;
2014-07-28 18:07:48 +02:00
} ) ;
2013-08-30 17:56:53 +02:00
// MochiKit.Signal.connect(window, 'onpopstate', MochiKit.Base.method(this, 'historyGoBack'));
2014-07-28 18:07:48 +02:00
// MochiKit.Signal.connect(window, 'onbeforeunload', MochiKit.Base.method(this, 'shouldExitApp'));
2013-08-30 17:56:53 +02:00
} ,
2016-03-29 11:45:50 +02:00
eventHandlerErrorCatcher : function ( anEvent , aValue ) {
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( "MainController.eventHandlerErrorCatcher" , { trace : false } ) ;
deferredResult . addMethod ( this , anEvent + '_handler' ) ;
deferredResult . addErrback ( MochiKit . Base . bind ( function ( anError ) {
if ( ! anError instanceof MochiKit . Async . CancelledError ) {
this . overlay ( ) . hide ( true ) ;
this . moveInPage ( this . currentPage ( ) , 'errorPage' ) ;
this . pages ( ) [ 'errorPage' ] . setProps ( { 'error' : anError } ) ;
console . log ( "CATCHED UNHANDLED ERROR" ) ;
}
return anError ;
} , this ) ) ;
deferredResult . callback ( aValue ) ;
return deferredResult ;
} ,
2013-08-30 17:56:53 +02:00
//-------------------------------------------------------------------------
2014-10-12 14:30:17 +02:00
/ *
selectionChange _handler : function ( anEvent ) {
2013-10-02 09:59:30 +02:00
var selection ;
var selectionRange ;
var selectionNode ;
var valueElement ;
// other hints: http://www.bearpanther.com/2013/05/27/easy-text-selection-in-mobile-safari/
// SELECTION: https://developer.mozilla.org/en-US/docs/Web/API/Selection
// RANGE: https://developer.mozilla.org/en-US/docs/Web/API/Range
// NODE TYPES: https://developer.mozilla.org/en-US/docs/Web/API/Node.nodeType
selection = MochiKit . DOM . currentWindow ( ) . getSelection ( ) ;
//console.log("-- selection", selection);
selectionRange = selection . getRangeAt ( 0 ) ;
selectionNode = selectionRange . startContainer . childNodes [ selectionRange . startOffset ] ;
//console.log("-- selectionNode", selectionNode);
if ( selectionNode != undefined ) {
valueElement = MochiKit . DOM . getFirstElementByTagAndClassName ( '*' , 'value' , selectionNode ) ;
//console.log("-- valueElement", valueElement);
}
if ( ( valueElement != null ) && ( valueElement != selectionNode ) ) {
var range ;
range = MochiKit . DOM . currentDocument ( ) . createRange ( ) ;
range . selectNodeContents ( valueElement ) ;
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
anEvent . preventDefault ( ) ;
anEvent . stopPropagation ( ) ;
//console.log("updated selection", MochiKit.DOM.currentWindow().getSelection());
}
//console.log("-----------");
} ,
2014-10-12 14:30:17 +02:00
* /
2013-10-02 09:59:30 +02:00
//-------------------------------------------------------------------------
2013-08-30 17:56:53 +02:00
run : function ( parameters ) {
var shouldShowRegistrationForm ;
2013-10-02 09:59:30 +02:00
var canRegisterNewUsers ;
canRegisterNewUsers = Clipperz . PM . Proxy . defaultProxy . canRegisterNewUsers ( ) ;
2013-08-30 17:56:53 +02:00
this . selectInitialProxy ( ) ;
2013-10-02 09:59:30 +02:00
shouldShowRegistrationForm = parameters [ 'shouldShowRegistrationForm' ] && canRegisterNewUsers ;
2013-08-30 17:56:53 +02:00
2015-03-03 17:42:25 +01:00
this . showLoginForm ( ) ;
2013-08-30 17:56:53 +02:00
if ( shouldShowRegistrationForm ) {
2014-07-28 18:07:48 +02:00
this . showRegistrationForm _handler ( ) ;
2013-08-30 17:56:53 +02:00
}
2015-03-03 17:42:25 +01:00
2014-07-28 18:07:48 +02:00
// this.overlay().done("", 0.5);
this . overlay ( ) . hide ( ) ;
2013-08-30 17:56:53 +02:00
} ,
2015-04-14 10:44:23 +02:00
//-------------------------------------------------------------------------
2015-06-27 19:08:20 +02:00
checkPassphrase : function ( passphraseIn ) {
2015-04-14 10:44:23 +02:00
var deferredResult ;
2015-05-21 14:32:51 +02:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.checkPassphrase" , { trace : false } ) ;
2015-04-14 10:44:23 +02:00
deferredResult . addMethod ( this . user ( ) , 'getPassphrase' ) ;
deferredResult . addCallback ( function ( candidatePassphrase , realPassphrase ) { return candidatePassphrase == realPassphrase ; } , passphraseIn ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2013-08-30 17:56:53 +02:00
//-------------------------------------------------------------------------
showLoginForm : function ( ) {
var loginFormPage ;
loginFormPage = this . pages ( ) [ 'loginPage' ] ;
2015-03-11 18:19:29 +01:00
// loginFormPage.setProps({'mode':this.loginMode(), 'isNewUserRegistrationAvailable':Clipperz.PM.Proxy.defaultProxy.canRegisterNewUsers()});
loginFormPage . setProps ( { 'mode' : this . loginMode ( ) } ) ;
2013-08-30 17:56:53 +02:00
this . moveInPage ( this . currentPage ( ) , 'loginPage' ) ;
MochiKit . Async . callLater ( 0.5 , MochiKit . Base . method ( loginFormPage , 'setInitialFocus' ) ) ;
2015-08-18 17:31:02 +02:00
MochiKit . Async . callLater ( 0.5 , MochiKit . Base . method ( this , 'recursivelyPollLoginFormForChanges' ) ) ;
} ,
recursivelyPollLoginFormForChanges : function ( ) {
this . pages ( ) [ 'loginPage' ] . pollForChanges ( ) ;
if ( this . currentPage ( ) == 'loginPage' ) {
MochiKit . Async . callLater ( 0.5 , MochiKit . Base . method ( this , 'recursivelyPollLoginFormForChanges' ) ) ;
}
2013-08-30 17:56:53 +02:00
} ,
2014-07-28 18:07:48 +02:00
showRegistrationForm _handler : function ( ) {
2013-08-30 17:56:53 +02:00
var currentPage ;
var registrationPage ;
currentPage = this . currentPage ( ) ;
registrationPage = this . pages ( ) [ 'registrationPage' ] ;
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.showRegistrationForm_handler" , [
MochiKit . Base . method ( this , 'setCurrentPage' , 'loginPage' ) ,
MochiKit . Base . method ( registrationPage , 'setProps' , { } ) ,
MochiKit . Base . method ( this , 'moveInPage' , currentPage , 'registrationPage' ) ,
MochiKit . Base . partial ( MochiKit . Async . callLater , 0.5 , MochiKit . Base . method ( registrationPage , 'setInitialFocus' ) )
] , { trace : false } ) ;
2013-08-30 17:56:53 +02:00
} ,
2015-09-30 20:09:58 +02:00
forcePassphraseLogin _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.forcePassphraseLogin_handler" , [
MochiKit . Base . method ( this . pages ( ) [ 'loginPage' ] , 'setProps' , { 'forceCredentials' : true } ) ,
MochiKit . Base . partial ( MochiKit . Async . callLater , 0.1 , MochiKit . Base . method ( this . pages ( ) [ 'loginPage' ] , 'setInitialFocus' ) )
] , { trace : false } ) ;
2015-09-30 20:09:58 +02:00
} ,
forcePassphraseUnlock _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.forcePassphraseUnlock_handler" , [
MochiKit . Base . method ( this . pages ( ) [ 'unlockPage' ] , 'setProps' , { 'forceCredentials' : true } ) ,
MochiKit . Base . partial ( MochiKit . Async . callLater , 0.1 , MochiKit . Base . method ( this . pages ( ) [ 'unlockPage' ] , 'setInitialFocus' ) )
] , { trace : false } ) ;
2015-09-30 20:09:58 +02:00
} ,
2013-08-30 17:56:53 +02:00
//=========================================================================
2014-07-28 18:07:48 +02:00
doLogin _handler : function ( event ) {
return this . doLogin ( event ) ;
} ,
doLogin : function ( someCredentials ) {
var deferredResult ;
2013-08-30 17:56:53 +02:00
var credentials ;
var getPassphraseDelegate ;
var user ;
user = null ;
2015-11-30 14:12:27 +01:00
this . overlay ( ) . show ( "logging in" , false , false ) ;
2013-08-30 17:56:53 +02:00
this . pages ( ) [ 'loginPage' ] . setProps ( { disabled : true } ) ;
2014-07-28 18:07:48 +02:00
if ( 'pin' in someCredentials ) {
credentials = Clipperz . PM . PIN . credentialsWithPIN ( someCredentials [ 'pin' ] ) ;
2013-08-30 17:56:53 +02:00
} else {
2014-07-28 18:07:48 +02:00
credentials = someCredentials ;
2013-08-30 17:56:53 +02:00
}
getPassphraseDelegate = MochiKit . Base . partial ( MochiKit . Async . succeed , credentials . passphrase ) ;
user = new Clipperz . PM . DataModel . User ( { 'username' : credentials . username , 'getPassphraseFunction' : getPassphraseDelegate } ) ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.doLogin' , { trace : false } ) ;
deferredResult . addCallback ( MochiKit . Async . wait , 0.1 ) ;
deferredResult . addMethod ( Clipperz . Crypto . PRNG . defaultRandomGenerator ( ) , 'deferredEntropyCollection' ) ;
deferredResult . addMethod ( user , 'login' ) ;
2015-09-01 12:18:27 +02:00
if ( Clipperz . PM . PIN . isLocalStorageSupported ( ) ) {
deferredResult . addMethod ( Clipperz . PM . PIN , 'resetFailedAttemptCount' ) ;
}
2013-08-30 17:56:53 +02:00
deferredResult . addMethod ( this , 'setUser' , user ) ;
2015-09-23 13:44:29 +02:00
deferredResult . addMethod ( this , 'updateUserPreferences' ) ;
2013-08-30 17:56:53 +02:00
deferredResult . addMethod ( this , 'runApplication' ) ;
2016-11-27 15:05:10 +01:00
// deferredResult.addMethod(this, 'updateCertificateQueueInfo');
2013-08-30 17:56:53 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'done' , "" , 1 ) ;
2015-07-20 10:27:28 +02:00
deferredResult . addErrback ( MochiKit . Base . method ( this , 'genericErrorHandler' , someCredentials , "login failed" ) ) ;
2013-08-30 17:56:53 +02:00
deferredResult . addErrback ( MochiKit . Base . bind ( function ( anEvent , anError ) {
if ( anError [ 'isPermanent' ] != true ) {
this . pages ( ) [ 'loginPage' ] . setProps ( { disabled : false , 'mode' : this . loginMode ( ) } ) ;
2013-10-02 09:59:30 +02:00
this . pages ( ) [ 'loginPage' ] . setInitialFocus ( ) ;
}
2016-03-29 11:45:50 +02:00
return anEvent ; // anError;
2014-07-28 18:07:48 +02:00
} , this , someCredentials ) )
2013-08-30 17:56:53 +02:00
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2015-07-04 18:43:59 +02:00
logout _handler : function ( ) {
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.logout' , { trace : false } ) ;
deferredResult . addMethod ( this . user ( ) , 'logout' ) ;
deferredResult . addCallback ( function ( ) {
window . location . href = '/' ;
} )
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2015-11-24 17:17:29 +01:00
lockShortcut : function ( anEvent ) {
anEvent . preventDefault ( ) ;
return this . lock ( ) ;
} ,
2015-09-23 10:24:49 +02:00
lock : function ( ) {
var deferredResult ;
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'disableLock' ) ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.lock_handler' , { trace : false } ) ;
// force exit edit state OR skip lock if pending changes are present
deferredResult . addMethod ( this , 'exitCurrentSelection' ) ;
deferredResult . addMethod ( this , 'resetPanels' ) ;
deferredResult . addMethod ( this , 'moveOutPage' , this . currentPage ( ) , 'unlockPage' ) ;
deferredResult . addMethod ( this . user ( ) , 'lock' ) ;
deferredResult . addMethod ( this , 'deleteCleanTextData' ) ;
2015-09-23 13:39:22 +02:00
deferredResult . addMethod ( this . pages ( ) [ 'unlockPage' ] , 'setProps' , { 'username' : this . user ( ) . username ( ) } ) ;
2015-11-30 11:47:06 +01:00
deferredResult . addCallback ( MochiKit . Async . callLater , 0.1 , MochiKit . Base . method ( this . pages ( ) [ 'unlockPage' ] , 'resetUnlockForm' ) ) ;
2015-09-23 10:24:49 +02:00
deferredResult . addMethod ( this . pages ( ) [ 'unlockPage' ] , 'setInitialFocus' ) ;
deferredResult . addCallback ( MochiKit . Async . callLater , 1 , MochiKit . Base . method ( this . pages ( ) [ 'mainPage' ] , 'replaceProps' , { 'locked' : true } ) ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2016-03-29 11:45:50 +02:00
unlock _handler : function ( someInfo ) {
var deferredResult ;
var credential = someInfo [ 'credential' ] ;
var credentialType = someInfo [ 'credentialType' ] ;
var user , passphrase , getPassphraseDelegate ;
2015-09-23 10:24:49 +02:00
2015-10-27 14:31:39 +01:00
// var user = this.user();
var oldUser = this . user ( ) ;
2015-09-23 10:24:49 +02:00
var unlockPage = this . pages ( ) [ 'unlockPage' ] ;
2015-09-23 13:39:22 +02:00
var overlay = this . overlay ( ) ;
2015-09-30 20:09:58 +02:00
2015-11-30 14:12:27 +01:00
overlay . show ( "validating…" , false ) ;
2016-03-29 11:45:50 +02:00
passphrase = ( credentialType == 'PIN' ) ? Clipperz . PM . PIN . credentialsWithPIN ( credential ) [ 'passphrase' ] : credential ;
2015-09-30 20:09:58 +02:00
2015-10-27 14:31:39 +01:00
getPassphraseDelegate = MochiKit . Base . partial ( MochiKit . Async . succeed , passphrase ) ;
user = new Clipperz . PM . DataModel . User ( { 'username' : oldUser . username ( ) , 'getPassphraseFunction' : getPassphraseDelegate } ) ;
2015-11-23 16:10:44 +01:00
deferredResult = new Clipperz . Async . Deferred ( 'MainController.unlock_handler' , { trace : false } ) ;
2015-10-27 14:31:39 +01:00
2015-09-23 10:24:49 +02:00
deferredResult . addMethod ( unlockPage , 'setProps' , { 'disabled' : true } ) ;
2015-10-27 14:31:39 +01:00
deferredResult . addMethod ( user , 'login' ) ;
deferredResult . addMethod ( this , 'setUser' , user ) ;
// deferredResult.addMethod(user, 'unlock', MochiKit.Base.partial(MochiKit.Async.succeed, passphrase));
2015-09-30 20:09:58 +02:00
deferredResult . addErrback ( MochiKit . Base . bind ( function ( aValue ) {
2015-09-23 10:24:49 +02:00
var innerDeferredResult ;
2015-09-30 20:09:58 +02:00
var errorMessage ;
errorMessage = 'failed' ;
2016-03-29 11:45:50 +02:00
if ( credentialType == 'PIN' ) {
2015-09-30 20:09:58 +02:00
var attemptsLeft = Clipperz . PM . PIN . recordFailedAttempt ( ) ;
if ( attemptsLeft == - 1 ) {
errorMessage = 'PIN resetted' ;
}
}
2015-09-23 10:24:49 +02:00
innerDeferredResult = new Clipperz . Async . Deferred ( 'MainController.unlock_handler <incorrect passphrase>' , { trace : false } ) ;
2015-09-30 20:09:58 +02:00
innerDeferredResult . addMethod ( unlockPage , 'setProps' , {
'disabled' : false ,
'mode' : this . loginMode ( ) ,
} ) ;
2015-09-23 10:24:49 +02:00
innerDeferredResult . addMethod ( unlockPage , 'setInitialFocus' ) ;
2015-09-30 20:09:58 +02:00
innerDeferredResult . addMethod ( overlay , 'failed' , errorMessage , 1 ) ;
2015-09-23 10:24:49 +02:00
innerDeferredResult . addCallback ( MochiKit . Async . fail , aValue ) ;
innerDeferredResult . callback ( ) ;
return aValue ;
2015-09-30 20:09:58 +02:00
} , this ) ) ;
2015-09-23 10:24:49 +02:00
2016-03-29 11:45:50 +02:00
if ( credentialType == 'PIN' ) {
2015-09-30 20:09:58 +02:00
deferredResult . addMethod ( Clipperz . PM . PIN , 'resetFailedAttemptCount' ) ;
}
2015-09-23 13:44:29 +02:00
deferredResult . addMethod ( this , 'updateUserPreferences' ) ;
2015-09-23 13:41:57 +02:00
deferredResult . addMethod ( this , 'moveInPage' , this . currentPage ( ) , 'mainPage' ) ;
2015-09-23 10:24:49 +02:00
deferredResult . addMethod ( this , 'refreshUI' ) ;
2015-09-30 20:09:58 +02:00
deferredResult . addMethod ( unlockPage , 'setProps' , {
'disabled' : false ,
'forceCredentials' : false ,
} ) ;
2015-11-30 11:47:06 +01:00
// deferredResult.addMethod(unlockPage, 'resetUnlockForm');
2015-09-23 10:24:49 +02:00
deferredResult . addCallback ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'enableLock' ) ;
2016-11-27 15:05:10 +01:00
// deferredResult.addMethod(this, 'updateCertificateQueueInfo');
2015-09-23 13:39:22 +02:00
deferredResult . addMethod ( overlay , 'done' , "" , 0.5 ) ;
2016-03-29 11:45:50 +02:00
deferredResult . addErrback ( MochiKit . Async . succeed , true ) ;
2015-09-23 10:24:49 +02:00
deferredResult . callback ( ) ;
return deferredResult ;
2015-09-30 20:09:58 +02:00
// this.user().setPassphraseFunction(function(){return passphrase;});
2015-09-23 10:24:49 +02:00
// TODO: check if passphrase is correct by try/catch on decrypting something
// this.moveOutPage(this.currentPage(), 'mainPage');
// TODO: check why the unlock form keeps the value stored (doesn't happen with the login form...)
} ,
deleteCleanTextData : function ( ) {
this . _recordsInfo = null ;
this . _selectedCards = null ;
this . _selectedCardInfo = null ;
2015-09-23 13:44:29 +02:00
this . _userPreferences = null ;
2015-09-23 10:24:49 +02:00
} ,
2013-08-30 17:56:53 +02:00
//-------------------------------------------------------------------------
2014-07-28 18:07:48 +02:00
registerNewUser _handler : function ( credentials ) {
2013-08-30 17:56:53 +02:00
var deferredResult ;
this . overlay ( ) . show ( "creating user" ) ;
this . pages ( ) [ 'registrationPage' ] . setProps ( { disabled : true } ) ;
2014-08-04 18:33:37 +02:00
deferredResult = new Clipperz . Async . Deferred ( 'MainController.registerNewUser' , { trace : false } ) ;
2013-08-30 17:56:53 +02:00
deferredResult . addCallback ( Clipperz . PM . DataModel . User . registerNewAccount ,
credentials [ 'username' ] ,
MochiKit . Base . partial ( MochiKit . Async . succeed , credentials [ 'passphrase' ] )
) ;
deferredResult . addMethod ( this , 'doLogin' , credentials ) ;
2015-07-20 10:27:28 +02:00
deferredResult . addMethod ( this , 'importCards' , Clipperz . PM . DefaultCards ) ;
deferredResult . addErrback ( MochiKit . Base . method ( this , 'genericErrorHandler' , credentials , "registration failed" ) ) ;
2013-08-30 17:56:53 +02:00
deferredResult . addErrback ( MochiKit . Base . bind ( function ( anError ) {
if ( anError [ 'isPermanent' ] != true ) {
this . pages ( ) [ 'registrationPage' ] . setProps ( { disabled : false } ) ;
this . pages ( ) [ 'registrationPage' ] . setInitialFocus ( ) ;
}
return anError ;
} , this ) ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
//-------------------------------------------------------------------------
user : function ( ) {
return this . _user ;
} ,
setUser : function ( aUser ) {
this . _user = aUser ;
return this . _user ;
} ,
//=========================================================================
2014-07-28 18:07:48 +02:00
filter : function ( ) {
return this . _filter ;
} ,
setFilter : function ( aType , aValue ) {
this . _filter = { 'type' : aType , 'value' : aValue } ;
return this . _filter ;
} ,
2014-07-30 09:28:05 +02:00
shouldIncludeArchivedCards : function ( ) {
return this . _shouldIncludeArchivedCards ;
} ,
setShouldIncludeArchivedCards : function ( aValue ) {
this . _shouldIncludeArchivedCards = aValue ;
} ,
2014-07-28 18:07:48 +02:00
//----------------------------------------------------------------------------
collectRecordInfo : function ( aRecord ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.updateOTPListAndDetails" , [
Clipperz . Async . collectResults ( "MainController.updateOTPListAndDetails <inner results>" , {
'recordInfo' : MochiKit . Base . method ( aRecord , 'collectRecordInfo' ) ,
// 'certificateMetadata': MochiKit.Base.method(aRecord, 'certificateMetadata'),
'hasPendingChanges' : MochiKit . Base . method ( this . user ( ) , 'hasPendingChanges' ) ,
} , { trace : false } ) ,
function ( someData ) {
var result ;
result = someData [ 'recordInfo' ] ;
result [ 'hasPendingChanges' ] = someData [ 'hasPendingChanges' ] ;
return result ;
} ,
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
return deferredResult ;
2013-08-30 17:56:53 +02:00
} ,
2016-03-29 11:45:50 +02:00
//----------------------------------------------------------------------------
2015-01-06 15:42:14 +01:00
showCardDetailInNarrowView : function ( aValue ) {
return Clipperz . Async . callbacks ( "MainController.showCardDetailInNarrowView" , [
2015-03-10 22:59:24 +01:00
MochiKit . Base . method ( this , 'setPageProperties' , 'cardDetailPage' , 'features' , this . features ( ) ) ,
2015-01-06 15:42:14 +01:00
MochiKit . Base . method ( this , 'setPageProperties' , 'cardDetailPage' , 'selectedCard' , aValue ) ,
MochiKit . Base . method ( this , 'moveInPage' , this . currentPage ( ) , 'cardDetailPage' ) ,
2015-03-21 12:18:14 +01:00
function ( ) { return aValue ; } ,
2015-01-06 15:42:14 +01:00
] , { trace : false } ) ;
} ,
updateSelectedCard : function ( someInfo , shouldShowLoading , shouldShowCardDetail ) {
2013-08-30 17:56:53 +02:00
var deferredResult ;
2015-01-04 18:50:50 +01:00
var showLoading = typeof ( shouldShowLoading ) !== 'undefined' ? shouldShowLoading : true ;
2014-07-28 18:07:48 +02:00
if ( someInfo == null ) {
this . setPageProperties ( 'mainPage' , 'selectedCard' , { } ) ;
deferredResult = MochiKit . Async . succeed ( ) ;
} else {
2014-08-22 08:38:53 +02:00
if ( showLoading ) {
2015-11-30 11:47:06 +01:00
// this.setPageProperties('mainPage', 'selectedCard', {'loading':true, 'label':someInfo['label'], '_reference':someInfo['reference']});
this . overlay ( ) . show ( '' , true , false , true )
2014-08-22 08:38:53 +02:00
}
2014-07-28 18:07:48 +02:00
deferredResult = new Clipperz . Async . Deferred ( 'MainController.updateSelectedCard' , { trace : false } ) ;
deferredResult . addMethod ( this . user ( ) , 'getRecord' , someInfo [ 'reference' ] ) ;
deferredResult . addMethod ( this , 'collectRecordInfo' ) ;
deferredResult . addMethod ( this , 'setPageProperties' , 'mainPage' , 'selectedCard' ) ;
2015-01-06 15:42:14 +01:00
if ( ( this . mediaQueryStyle ( ) == 'narrow' ) && shouldShowCardDetail ) {
deferredResult . addMethod ( this , 'showCardDetailInNarrowView' ) ;
2014-07-28 18:07:48 +02:00
}
2015-11-30 11:47:06 +01:00
deferredResult . addMethod ( this . overlay ( ) , 'hide' , true ) ;
2014-07-28 18:07:48 +02:00
MochiKit . Async . callLater ( 0.1 , MochiKit . Base . method ( deferredResult , 'callback' ) ) ;
}
2013-08-30 17:56:53 +02:00
return deferredResult ;
} ,
2014-07-28 18:07:48 +02:00
//............................................................................
2013-08-30 17:56:53 +02:00
2014-07-28 18:07:48 +02:00
regExpFilterGenerator : function ( aRegExp , aSearchField ) {
var searchField = aSearchField ? aSearchField : Clipperz . PM . DataModel . Record . defaultSearchField ;
return function ( aCardInfo ) {
aRegExp . lastIndex = 0 ;
return aRegExp . test ( aCardInfo [ searchField ] ) ;
}
} ,
selectedCardReference : function ( ) {
return this . pages ( ) [ 'mainPage' ] . props &&
this . pages ( ) [ 'mainPage' ] . props [ 'selectedCard' ] &&
this . pages ( ) [ 'mainPage' ] . props [ 'selectedCard' ] [ '_reference' ]
? this . pages ( ) [ 'mainPage' ] . props [ 'selectedCard' ] [ '_reference' ]
: '' ;
2013-08-30 17:56:53 +02:00
} ,
2014-07-28 18:07:48 +02:00
isSelectedCardStillVisible : function ( someCards ) {
var result ;
var reference ;
reference = this . selectedCardReference ( ) ;
result = MochiKit . Iter . some ( someCards , function ( aCardInfo ) {
return aCardInfo [ '_reference' ] == reference ;
} ) ;
return result ;
2013-08-30 17:56:53 +02:00
} ,
2014-12-30 10:28:59 +01:00
//----------------------------------------------------------------------------
recordsInfo : function ( ) {
return this . _recordsInfo ;
} ,
setRecordsInfo : function ( someRecordsInfo ) {
2016-03-29 11:45:50 +02:00
//console.log("setRecordsInfo", someRecordsInfo);
2014-12-30 10:28:59 +01:00
this . _recordsInfo = someRecordsInfo ;
return this . _recordsInfo ;
} ,
resetRecordsInfo : function ( ) {
this . _recordsInfo = null ;
2015-01-04 18:50:50 +01:00
this . _selectedCards = null ;
2014-12-30 10:28:59 +01:00
} ,
2014-10-12 14:30:17 +02:00
getRecordsInfo : function ( cardInfo , shouldIncludeArchivedCards ) {
2014-12-30 10:28:59 +01:00
var deferredResult ;
if ( this . _recordsInfo == null ) {
deferredResult = new Clipperz . Async . Deferred ( 'MainController.getRecordsInfo' , { trace : false } ) ;
deferredResult . addMethod ( this . user ( ) , 'getRecordsInfo' , Clipperz . PM . DataModel . Record . defaultCardInfo /*, shouldIncludeArchivedCards*/ ) ;
deferredResult . addMethod ( this , 'setRecordsInfo' ) ;
deferredResult . callback ( ) ;
} else {
deferredResult = MochiKit . Async . succeed ( this . _recordsInfo ) ;
}
return deferredResult ;
2014-10-12 14:30:17 +02:00
} ,
2015-01-04 18:50:50 +01:00
//............................................................................
selectedCards : function ( ) {
return this . _selectedCards ;
} ,
setSelectedCards : function ( aValue ) {
this . _selectedCards = aValue ;
return this . _selectedCards ;
} ,
2014-12-30 10:28:59 +01:00
//----------------------------------------------------------------------------
2014-07-28 18:07:48 +02:00
updateSelectedCards : function ( shouldIncludeArchivedCards , aFilter ) {
var deferredResult ;
2014-10-12 14:30:17 +02:00
var filterCriteria ;
2014-07-28 18:07:48 +02:00
var sortCriteria ;
2014-10-12 14:30:17 +02:00
var rangeFilter ;
var fullFilterCriteria ;
var selectedCardReference = this . _selectedCardInfo ? this . _selectedCardInfo [ 'reference' ] : null ;
if ( aFilter [ 'type' ] == 'ALL' ) {
filterCriteria = MochiKit . Base . operator . truth ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
} else if ( aFilter [ 'type' ] == 'RECENT' ) {
filterCriteria = MochiKit . Base . operator . truth ;
2015-07-20 10:27:28 +02:00
sortCriteria = Clipperz . Base . reverseComparator ( MochiKit . Base . keyComparator ( '_accessDate' ) ) ;
2015-02-06 17:24:31 +01:00
rangeFilter = function ( someCards ) { return someCards . slice ( 0 , 10 ) } ;
2016-03-29 11:45:50 +02:00
} else if ( aFilter [ 'type' ] == 'WITH_CERTIFICATE' ) {
filterCriteria = function ( aRecordInfo ) { return aRecordInfo [ 'hasBeenCertified' ] ; } ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
2015-11-23 16:10:44 +01:00
} else if ( aFilter [ 'type' ] == 'WITH_ATTACHMENTS' ) {
filterCriteria = function ( aRecordInfo ) { return aRecordInfo . attachmentsCount > 0 ; } ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
2014-10-12 14:30:17 +02:00
} else if ( aFilter [ 'type' ] == 'SEARCH' ) {
filterCriteria = this . regExpFilterGenerator ( Clipperz . PM . DataModel . Record . regExpForSearch ( aFilter [ 'value' ] ) ) ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
} else if ( aFilter [ 'type' ] == 'TAG' ) {
filterCriteria = this . regExpFilterGenerator ( Clipperz . PM . DataModel . Record . regExpForTag ( aFilter [ 'value' ] ) ) ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
} else if ( aFilter [ 'type' ] == 'UNTAGGED' ) {
filterCriteria = this . regExpFilterGenerator ( Clipperz . PM . DataModel . Record . regExpForNoTag ( ) ) ;
sortCriteria = Clipperz . Base . caseInsensitiveKeyComparator ( 'label' ) ;
rangeFilter = MochiKit . Base . operator . identity ;
}
fullFilterCriteria = function ( aRecordInfo ) {
var result ;
if ( aRecordInfo [ '_reference' ] == selectedCardReference ) {
result = true ;
} else {
if ( ( shouldIncludeArchivedCards == false ) && ( aRecordInfo [ '_isArchived' ] ) ) {
result = false ;
} else {
result = filterCriteria ( aRecordInfo ) ;
}
}
2014-07-28 18:07:48 +02:00
2014-10-12 14:30:17 +02:00
return result ;
}
deferredResult = new Clipperz . Async . Deferred ( 'MainController.updateSelectedCards' , { trace : false } ) ;
deferredResult . addMethod ( this , 'getRecordsInfo' , Clipperz . PM . DataModel . Record . defaultCardInfo , shouldIncludeArchivedCards ) ;
2014-07-28 18:07:48 +02:00
2014-10-12 14:30:17 +02:00
deferredResult . addCallback ( MochiKit . Base . filter , fullFilterCriteria ) ;
deferredResult . addMethodcaller ( 'sort' , sortCriteria ) ;
deferredResult . addCallback ( rangeFilter ) ;
2014-07-28 18:07:48 +02:00
deferredResult . addMethod ( this , 'setPageProperties' , 'mainPage' , 'cards' ) ;
deferredResult . addCallback ( MochiKit . Base . bind ( function ( someCards ) {
2015-01-04 18:50:50 +01:00
this . setSelectedCards ( someCards ) ;
2014-07-28 18:07:48 +02:00
if ( ! this . isSelectedCardStillVisible ( someCards ) ) {
this . updateSelectedCard ( null ) ;
} ;
} , this ) ) ;
deferredResult . addMethod ( this , 'setPageProperties' , 'mainPage' , 'filter' , this . filter ( ) ) ;
2013-08-30 17:56:53 +02:00
2014-07-28 18:07:48 +02:00
deferredResult . callback ( ) ;
2013-10-02 09:59:30 +02:00
2014-07-28 18:07:48 +02:00
return deferredResult ;
2013-08-30 17:56:53 +02:00
} ,
2014-07-28 18:07:48 +02:00
2014-07-30 09:28:05 +02:00
refreshSelectedCards : function ( ) {
return this . updateSelectedCards ( this . shouldIncludeArchivedCards ( ) , this . filter ( ) ) ;
} ,
refreshUI : function ( selectedCardReference ) {
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.refreshUI' , { trace : false } ) ;
deferredResult . addMethod ( this , 'refreshSelectedCards' ) ;
deferredResult . addMethod ( this , 'renderTags' ) ;
if ( selectedCardReference != null ) {
deferredResult . addMethod ( this . user ( ) , 'getRecord' , selectedCardReference ) ;
deferredResult . addMethod ( this , 'collectRecordInfo' ) ;
2015-02-04 23:44:32 +01:00
deferredResult . addMethod ( this , 'setPageProperties' , this . currentPage ( ) , 'selectedCard' ) ;
2014-07-30 09:28:05 +02:00
}
2015-02-04 23:44:32 +01:00
2014-07-30 09:28:05 +02:00
deferredResult . callback ( ) ;
2015-09-23 10:24:49 +02:00
2014-07-30 09:28:05 +02:00
return deferredResult ;
} ,
2015-09-23 10:24:49 +02:00
//----------------------------------------------------------------------------
enableLock _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.enableLock_handler" , [
MochiKit . Base . partial ( MochiKit . Signal . connect , Clipperz . Signal . NotificationCenter , 'lock' , MochiKit . Base . method ( this , 'lock' ) )
] , { trace : false } ) ;
2015-09-23 10:24:49 +02:00
} ,
disableLock _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.disableLock_handler" , [
MochiKit . Base . partial ( MochiKit . Signal . disconnectAll , Clipperz . Signal . NotificationCenter , 'lock' )
] , { trace : false } ) ;
2015-09-23 10:24:49 +02:00
} ,
2015-09-30 20:09:58 +02:00
updatePIN _handler : function ( aPIN ) {
return Clipperz . Async . callbacks ( "MainController.updatePIN_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "updating …" , true ) ,
MochiKit . Base . method ( Clipperz . PM . PIN , 'updatePin' , this . user ( ) , aPIN ) ,
2015-10-02 14:48:22 +02:00
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 1 )
2015-09-30 20:09:58 +02:00
] , { trace : false } ) ;
} ,
disablePIN _handler : function ( ) {
return Clipperz . Async . callbacks ( "MainController.disablePIN_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "disabling …" , true ) ,
MochiKit . Base . method ( Clipperz . PM . PIN , 'disablePin' ) ,
2015-10-02 14:48:22 +02:00
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 1 )
2015-09-30 20:09:58 +02:00
] , { trace : false } ) ;
} ,
2015-09-23 10:24:49 +02:00
resetLockTimeout : function ( ) {
if ( this . user ( ) ) {
return Clipperz . Async . callbacks ( "MainController.resetLockTimeout" , [
2015-09-23 13:41:57 +02:00
MochiKit . Base . method ( this . user ( ) , 'getPreference' , 'lock' ) ,
MochiKit . Base . bind ( function ( someLockInfo ) {
2015-09-23 10:24:49 +02:00
if ( this . _lockTimeout ) {
clearTimeout ( this . _lockTimeout ) ;
}
2015-09-23 13:41:57 +02:00
if ( someLockInfo [ 'enabled' ] == true ) {
var aDelay = someLockInfo [ 'timeoutInMinutes' ] * 60 * 1000 ;
2015-09-23 10:24:49 +02:00
this . _lockTimeout = setTimeout ( function ( ) {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'lock' ) ;
} , aDelay ) ;
}
} , this )
] , { trace : false } ) ;
}
} ,
2014-07-30 09:28:05 +02:00
2014-07-28 18:07:48 +02:00
//----------------------------------------------------------------------------
2013-08-30 17:56:53 +02:00
2015-02-06 17:24:31 +01:00
getAllCardsCount : function ( ) {
var archivedCardsFilter = this . shouldIncludeArchivedCards ( )
? MochiKit . Async . succeed
: MochiKit . Base . partial ( MochiKit . Base . filter , function ( someRecordInfo ) { return ! someRecordInfo [ '_isArchived' ] ; } ) ;
2015-11-23 16:10:44 +01:00
return Clipperz . Async . callbacks ( "MainController.getAllCardsCount" , [
2015-02-06 17:24:31 +01:00
MochiKit . Base . method ( this . user ( ) , 'getRecords' ) ,
MochiKit . Base . partial ( MochiKit . Base . map , Clipperz . Async . collectResults ( "collectResults" , { '_fullLabel' : MochiKit . Base . methodcaller ( 'fullLabel' ) , '_isArchived' : MochiKit . Base . methodcaller ( 'isArchived' ) } , { trace : false } ) ) ,
Clipperz . Async . collectAll ,
archivedCardsFilter ,
function ( someCards ) { return someCards . length ; } ,
] , { trace : false } ) ;
} ,
2015-11-26 10:09:52 +01:00
2016-03-29 11:45:50 +02:00
getCardsWithCertificateCount : function ( ) {
var archivedCardsFilter = this . shouldIncludeArchivedCards ( )
? MochiKit . Async . succeed
: MochiKit . Base . partial ( MochiKit . Base . filter , function ( someRecordInfo ) { return ! someRecordInfo [ '_isArchived' ] ; } ) ;
return Clipperz . Async . callbacks ( "MainController.getCardsWithCertificateCount" , [
MochiKit . Base . method ( this . user ( ) , 'getRecords' ) ,
MochiKit . Base . partial ( MochiKit . Base . map , Clipperz . Async . collectResults ( "collectResults" , { 'hasBeenCertified' : MochiKit . Base . methodcaller ( 'hasBeenCertified' ) , '_isArchived' : MochiKit . Base . methodcaller ( 'isArchived' ) } , { trace : false } ) ) ,
Clipperz . Async . collectAll ,
archivedCardsFilter ,
function ( aResult ) {
return MochiKit . Base . filter ( function ( aRecordInfo ) { return aRecordInfo [ 'hasBeenCertified' ] === true ; } , aResult ) . length ;
}
] , { trace : false } ) ;
} ,
2015-11-23 16:10:44 +01:00
getCardsWithAttachmentsCount : function ( ) {
var archivedCardsFilter = this . shouldIncludeArchivedCards ( )
? MochiKit . Async . succeed
: MochiKit . Base . partial ( MochiKit . Base . filter , function ( someRecordInfo ) { return ! someRecordInfo [ '_isArchived' ] ; } ) ;
return Clipperz . Async . callbacks ( "MainController.getCardsWithAttachmentsCount" , [
MochiKit . Base . method ( this . user ( ) , 'getRecords' ) ,
MochiKit . Base . partial ( MochiKit . Base . map , Clipperz . Async . collectResults ( "collectResults" , { 'attachmentsCount' : MochiKit . Base . methodcaller ( 'attachmentsCount' ) , '_isArchived' : MochiKit . Base . methodcaller ( 'isArchived' ) } , { trace : false } ) ) ,
Clipperz . Async . collectAll ,
archivedCardsFilter ,
function ( aResult ) {
return MochiKit . Base . filter ( function ( aRecordInfo ) { return aRecordInfo [ 'attachmentsCount' ] > 0 ; } , aResult ) . length ;
}
] , { trace : false } ) ;
} ,
2014-08-02 14:45:22 +02:00
getArchivedCardsCount : function ( ) {
return Clipperz . Async . callbacks ( "MainController.getArchivedCardsCount" , [
MochiKit . Base . method ( this . user ( ) , 'getRecords' ) ,
MochiKit . Base . partial ( MochiKit . Base . map , Clipperz . Async . collectResults ( "collectResults" , { '_isArchived' : MochiKit . Base . methodcaller ( 'isArchived' ) } , { trace : false } ) ) ,
Clipperz . Async . collectAll ,
function ( aResult ) {
return MochiKit . Base . filter ( function ( aRecordInfo ) { return aRecordInfo [ '_isArchived' ] ; } , aResult ) . length ;
}
] , { trace : false } ) ;
} ,
getUntaggedCardsCount : function ( ) {
var archivedCardsFilter = this . shouldIncludeArchivedCards ( )
? MochiKit . Async . succeed
: MochiKit . Base . partial ( MochiKit . Base . filter , function ( someRecordInfo ) { return ! someRecordInfo [ '_isArchived' ] ; } ) ;
return Clipperz . Async . callbacks ( "MainController.getUntaggedCardsCount" , [
MochiKit . Base . method ( this . user ( ) , 'getRecords' ) ,
MochiKit . Base . partial ( MochiKit . Base . map , Clipperz . Async . collectResults ( "collectResults" , { '_fullLabel' : MochiKit . Base . methodcaller ( 'fullLabel' ) , '_isArchived' : MochiKit . Base . methodcaller ( 'isArchived' ) } , { trace : false } ) ) ,
Clipperz . Async . collectAll ,
archivedCardsFilter ,
MochiKit . Base . partial ( MochiKit . Base . filter , this . regExpFilterGenerator ( Clipperz . PM . DataModel . Record . regExpForNoTag ( ) , '_fullLabel' ) ) ,
function ( someCards ) { return someCards . length ; } ,
] , { trace : false } ) ;
} ,
//----------------------------------------------------------------------------
2014-07-28 18:07:48 +02:00
setPageProperties : function ( aPageName , aKey , aValue ) {
var props = { } ;
props [ aKey ] = aValue ;
this . pages ( ) [ aPageName ] . setProps ( props ) ;
2015-09-23 10:24:49 +02:00
2014-07-28 18:07:48 +02:00
return aValue ;
} ,
2013-08-30 17:56:53 +02:00
2014-09-19 18:27:26 +02:00
allTags : function ( shouldIncludeArchivedCards ) {
return this . user ( ) . getTags ( shouldIncludeArchivedCards ) ;
} ,
2014-07-30 09:28:05 +02:00
renderTags : function ( ) {
return Clipperz . Async . callbacks ( "MainController.renderTags" , [
2014-09-19 18:27:26 +02:00
// MochiKit.Base.method(this.user(), 'getTags', this.shouldIncludeArchivedCards()),
MochiKit . Base . method ( this , 'allTags' , this . shouldIncludeArchivedCards ( ) ) ,
2014-07-30 09:28:05 +02:00
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'tags' ) ,
2015-03-03 17:42:25 +01:00
MochiKit . Base . method ( this , 'allTags' , true || this . shouldIncludeArchivedCards ( ) ) ,
MochiKit . Base . keys ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'allTags' ) ,
2015-02-06 17:24:31 +01:00
MochiKit . Base . method ( this , 'getAllCardsCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'allCardsCount' ) ,
2016-03-29 11:45:50 +02:00
MochiKit . Base . method ( this , 'getCardsWithCertificateCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'withCertificateCardsCount' ) ,
2015-11-23 16:10:44 +01:00
MochiKit . Base . method ( this , 'getCardsWithAttachmentsCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'withAttachmentCardsCount' ) ,
2014-08-02 14:45:22 +02:00
MochiKit . Base . method ( this , 'getArchivedCardsCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'archivedCardsCount' ) ,
MochiKit . Base . method ( this , 'getUntaggedCardsCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'untaggedCardsCount' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'shouldIncludeArchivedCards' , this . shouldIncludeArchivedCards ( ) ) ,
2014-07-30 09:28:05 +02:00
] , { trace : false } ) ;
} ,
2014-07-28 18:07:48 +02:00
renderAccountData : function ( ) {
2014-07-30 09:28:05 +02:00
return Clipperz . Async . callbacks ( "MainController.renderAccountData" , [
MochiKit . Base . method ( this , 'setFilter' , 'ALL' ) ,
MochiKit . Base . method ( this , 'refreshUI' , null )
] , { trace : false } ) ;
2013-08-30 17:56:53 +02:00
} ,
2014-07-28 18:07:48 +02:00
//=========================================================================
2015-12-07 10:56:27 +01:00
historyReplaceState : function ( args ) {
2015-12-09 11:18:34 +01:00
if ( ( window . document . origin != null ) && ( window . document . origin != "null" ) ) {
2015-12-07 10:56:27 +01:00
window . history . replaceState . apply ( window . history , arguments ) ;
}
} ,
historyPushState : function ( args ) {
2015-12-09 11:18:34 +01:00
if ( ( window . document . origin != null ) && ( window . document . origin != "null" ) ) {
2015-12-07 10:56:27 +01:00
window . history . pushState . apply ( window . history , arguments ) ;
}
} ,
historyState : function ( args ) {
2015-12-09 11:18:34 +01:00
if ( ( window . document . origin != null ) && ( window . document . origin != "null" ) ) {
2015-12-07 10:56:27 +01:00
return window . history . state . apply ( window . history , arguments ) ;
}
} ,
//=========================================================================
2014-07-28 18:07:48 +02:00
runApplication : function ( anUser ) {
2015-12-07 10:56:27 +01:00
this . historyReplaceState ( { selectedCardInfo : null } , "" , window . location . toString ( ) ) ;
2016-03-29 11:45:50 +02:00
this . historyPushState ( { selectedCardInfo : null } , "" , window . location . toString ( ) ) ;
2014-07-28 18:07:48 +02:00
this . moveInPage ( this . currentPage ( ) , 'mainPage' ) ;
2015-09-23 10:24:49 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'enableLock' ) ;
this . resetLockTimeout ( ) ;
2015-11-23 16:10:44 +01:00
this . registerHistoryHandler ( ) ;
2015-09-23 10:24:49 +02:00
2014-07-28 18:07:48 +02:00
return this . renderAccountData ( ) ;
} ,
2015-01-02 14:19:33 +01:00
2014-07-28 18:07:48 +02:00
runDirectLogin _handler : function ( someParameters ) {
2013-08-30 17:56:53 +02:00
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.runDirectLogin' , { trace : false } ) ;
deferredResult . addMethod ( this . user ( ) , 'getRecord' , someParameters [ 'record' ] ) ;
deferredResult . addMethodcaller ( 'directLoginWithReference' , someParameters [ 'directLogin' ] ) ;
2015-01-02 14:19:33 +01:00
deferredResult . addCallback ( Clipperz . PM . UI . DirectLoginController . openDirectLogin ) ;
2013-08-30 17:56:53 +02:00
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2015-08-26 23:03:41 +02:00
2016-03-29 11:45:50 +02:00
removeDirectLogin _handler : function ( someInfo ) {
2015-08-26 23:03:41 +02:00
var deferredResult ;
2016-03-29 11:45:50 +02:00
var record = someInfo [ 'record' ] ;
var directLoginReference = someInfo [ 'directLoginReference' ] ;
2015-08-26 23:03:41 +02:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.removeDirectLogin_handler" , { 'trace' : false } ) ;
deferredResult . addMethodcaller ( 'directLogins' ) ;
2016-03-29 11:45:50 +02:00
deferredResult . addCallback ( MochiKit . Base . itemgetter ( directLoginReference ) ) ;
2015-08-26 23:03:41 +02:00
deferredResult . addMethodcaller ( 'remove' ) ;
2016-03-29 11:45:50 +02:00
deferredResult . addCallback ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'refreshCardEditDetail' , record . reference ( ) ) ;
2015-08-26 23:03:41 +02:00
2016-03-29 11:45:50 +02:00
deferredResult . callback ( record ) ;
2015-08-26 23:03:41 +02:00
return deferredResult ;
} ,
2015-01-02 14:19:33 +01:00
/ *
2013-08-30 17:56:53 +02:00
shouldExitApp : function ( anEvent ) {
2013-10-02 09:59:30 +02:00
//console.log("SHOULD EXIT APP");
2013-08-30 17:56:53 +02:00
anEvent . preventDefault ( ) ;
anEvent . stopPropagation ( ) ;
} ,
2014-07-28 18:07:48 +02:00
* /
2013-08-30 17:56:53 +02:00
//=========================================================================
2014-07-28 18:07:48 +02:00
/ *
showPreferences _handler : function ( anEvent ) {
2013-10-02 09:59:30 +02:00
var deferredResult ;
this . pages ( ) [ 'preferencePage' ] . setProps ( { } ) ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.showPreferences' , { trace : false } ) ;
deferredResult . addMethod ( this , 'moveInPage' , this . currentPage ( ) , 'preferencePage' , true ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2014-07-28 18:07:48 +02:00
* /
2013-10-02 09:59:30 +02:00
//=========================================================================
2015-07-20 10:27:28 +02:00
genericErrorHandler : function ( anEvent , aMessage , anError ) {
2013-08-30 17:56:53 +02:00
var errorMessage ;
var result ;
result = anError ;
2015-07-20 10:27:28 +02:00
// errorMessage = "login failed";
errorMessage = aMessage ;
2013-08-30 17:56:53 +02:00
if ( anError [ 'isPermanent' ] === true ) {
this . pages ( ) [ 'errorPage' ] . setProps ( { message : anError . message } ) ;
this . moveInPage ( this . currentPage ( ) , 'errorPage' ) ;
errorMessage = "failure" ;
} else {
if ( 'pin' in anEvent ) {
2015-09-30 20:09:58 +02:00
var errorCount = Clipperz . PM . PIN . recordFailedAttempt ( ) ;
2015-10-02 14:48:22 +02:00
2013-08-30 17:56:53 +02:00
if ( errorCount == - 1 ) {
errorMessage = "PIN resetted" ;
}
}
}
this . overlay ( ) . failed ( errorMessage , 1 ) ;
return result ;
} ,
//=========================================================================
slidePage : function ( fromPage , toPage , direction ) {
var fromPosition ;
2014-07-28 18:07:48 +02:00
var toPosition ;
var itemToTransition ;
2013-08-30 17:56:53 +02:00
if ( direction == "LEFT" ) {
fromPosition = 'right' ;
2014-07-28 18:07:48 +02:00
toPosition = 'left' ;
itemToTransition = toPage ;
2013-08-30 17:56:53 +02:00
} else {
fromPosition = 'left' ;
2014-07-28 18:07:48 +02:00
toPosition = 'right' ;
itemToTransition = fromPage ;
2013-08-30 17:56:53 +02:00
}
2014-07-28 18:07:48 +02:00
MochiKit . DOM . addElementClass ( itemToTransition , 'transition' ) ;
2013-08-30 17:56:53 +02:00
2014-07-28 18:07:48 +02:00
MochiKit . Async . callLater ( 0 , function ( ) {
MochiKit . DOM . addElementClass ( fromPage , toPosition ) ;
2013-08-30 17:56:53 +02:00
MochiKit . DOM . removeElementClass ( toPage , fromPosition ) ;
} )
MochiKit . Async . callLater ( 0.5 , function ( ) {
2014-07-28 18:07:48 +02:00
MochiKit . DOM . removeElementClass ( itemToTransition , 'transition' ) ;
2013-08-30 17:56:53 +02:00
} )
} ,
//.........................................................................
2014-07-28 18:07:48 +02:00
goBack _handler : function ( ) {
2013-08-30 17:56:53 +02:00
var fromPage ;
var toPage ;
fromPage = this . pageStack ( ) . shift ( ) ;
toPage = this . currentPage ( ) ;
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.goBack_handler" , [
MochiKit . Base . method ( this . pages ( ) [ toPage ] , 'setProps' , { } ) ,
MochiKit . Base . method ( this , 'moveOutPage' , fromPage , toPage )
] , { trace : false } ) ;
2013-08-30 17:56:53 +02:00
} ,
2015-12-07 10:56:27 +01:00
// historyGoBack: function (anEvent) {
// anEvent.preventDefault();
// anEvent.stopPropagation();
// this.goBack();
// },
2013-08-30 17:56:53 +02:00
currentPage : function ( ) {
return this . pageStack ( ) [ 0 ] ;
} ,
setCurrentPage : function ( aPage ) {
this . pageStack ( ) . unshift ( aPage ) ;
2014-07-28 18:07:48 +02:00
this . refreshCurrentPage ( ) ;
2013-08-30 17:56:53 +02:00
} ,
moveInPage : function ( fromPage , toPage , addToHistory ) {
2014-08-22 08:38:53 +02:00
if ( fromPage != toPage ) {
var shouldAddItemToHistory ;
2013-08-30 17:56:53 +02:00
2015-10-05 09:30:31 +02:00
if ( this . proxyInfo ( ) [ 'proxyType' ] != 'OFFLINE_COPY' ) {
shouldAddItemToHistory = typeof ( addToHistory ) == 'undefined' ? false : addToHistory ;
} else {
shouldAddItemToHistory = false ;
}
2013-08-30 17:56:53 +02:00
2014-08-22 08:38:53 +02:00
this . slidePage ( MochiKit . DOM . getElement ( fromPage ) , MochiKit . DOM . getElement ( toPage ) , 'LEFT' ) ;
this . setCurrentPage ( toPage ) ;
2013-08-30 17:56:53 +02:00
2015-11-23 16:10:44 +01:00
// Skipping push on page change: history needs to be more granular
// New states are pushed on user actions (view card, back to main page, ...)
// if (shouldAddItemToHistory) {
// window.history.pushState({'fromPage': fromPage, 'toPage': toPage}, "");
// } else {
2013-08-30 17:56:53 +02:00
//console.log("Skip HISTORY");
2015-11-23 16:10:44 +01:00
// }
2014-08-22 08:38:53 +02:00
} else {
//console.log("No need to move in the same page");
2013-08-30 17:56:53 +02:00
}
} ,
moveOutPage : function ( fromPage , toPage ) {
this . slidePage ( MochiKit . DOM . getElement ( fromPage ) , MochiKit . DOM . getElement ( toPage ) , 'RIGHT' ) ;
this . setCurrentPage ( toPage ) ;
} ,
2014-07-28 18:07:48 +02:00
//-------------------------------------------------------------------------
2015-03-10 22:59:24 +01:00
featureSet : function ( ) {
return this . userAccountInfo ( ) [ 'featureSet' ] ;
} ,
2014-07-28 18:07:48 +02:00
2015-03-10 22:59:24 +01:00
features : function ( ) {
// return this.userAccountInfo()['features'];
return Clipperz . PM . Proxy . defaultProxy . features ( this . userAccountInfo ( ) [ 'features' ] ) ;
2014-07-28 18:07:48 +02:00
} ,
2015-03-10 22:59:24 +01:00
//.........................................................................
2015-09-23 13:39:22 +02:00
userInfo : function ( ) {
2015-04-14 10:44:23 +02:00
var result ;
2015-06-27 19:08:20 +02:00
result = { } ;
2015-04-14 10:44:23 +02:00
2015-09-23 13:39:22 +02:00
result [ 'checkPassphraseCallback' ] = MochiKit . Base . bind ( this . checkPassphrase , this ) ;
2015-04-14 10:44:23 +02:00
if ( this . user ( ) != null ) {
result [ 'username' ] = this . user ( ) . username ( ) ;
}
return result ;
} ,
2014-07-28 18:07:48 +02:00
userAccountInfo : function ( ) {
var result ;
result = { } ;
if ( this . user ( ) != null ) {
var usefulFields = [
'currentSubscriptionType' ,
'expirationDate' ,
2015-03-10 22:59:24 +01:00
'referenceDate' ,
2014-07-28 18:07:48 +02:00
'featureSet' ,
2015-01-21 18:29:08 +01:00
'features' ,
2014-07-28 18:07:48 +02:00
'isExpired' ,
'isExpiring' ,
2016-03-29 11:45:50 +02:00
'paymentVerificationPending' ,
'attachmentQuota' ,
'certificateQuota'
2014-07-28 18:07:48 +02:00
] ;
var attributes = this . user ( ) . accountInfo ( ) . _attributes ;
MochiKit . Iter . forEach ( usefulFields , function ( aFieldName ) {
result [ aFieldName ] = attributes [ aFieldName ] ;
} )
} ;
return result ;
} ,
2015-03-10 22:59:24 +01:00
2016-03-29 11:45:50 +02:00
updateUserAccountInfo _handler : function ( anEvent ) {
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( "updateUserAccountInfo_handler" , { trace : false } ) ;
deferredResult . addMethod ( this . user ( ) , 'updateAccountInfo' ) ;
deferredResult . addMethod ( this , 'refreshCurrentPage' ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2015-03-10 22:59:24 +01:00
proxyInfo : function ( ) {
return {
'proxyType' : Clipperz . PM . Proxy . defaultProxy . type ( ) ,
'proxyTypeDescription' : Clipperz . PM . Proxy . defaultProxy . typeDescription ( )
}
} ,
2015-08-20 12:04:31 +02:00
2015-11-23 16:10:44 +01:00
attachmentController : function ( ) {
return this . _attachmentController ;
} ,
attachmentQueueInfo : function ( ) {
var queue ;
var notifications ;
var elementFetchCallback ;
if ( this . _attachmentController ) {
2016-11-27 15:05:10 +01:00
//console.log(">>> attachmentController", this._attachmentController);
2015-11-23 16:10:44 +01:00
queue = this . _attachmentController . getQueueInfo ( ) ;
2016-11-27 15:05:10 +01:00
// notifications = this._attachmentController.getNotificationsInfo();
2015-11-23 16:10:44 +01:00
elementFetchCallback = MochiKit . Base . method ( this . _attachmentController , 'getQueueElement' ) ;
} else {
2016-11-27 15:05:10 +01:00
//console.log(">>> attachmentController -> NULL");
2015-11-23 16:10:44 +01:00
queue = [ ] ;
2016-11-27 15:05:10 +01:00
// notifications = [];
2015-11-23 16:10:44 +01:00
elementFetchCallback = null ;
}
2016-11-27 15:05:10 +01:00
//console.log("<<< attachmentController", queue, notifications);
2015-11-23 16:10:44 +01:00
return {
'queue' : queue ,
'notifications' : notifications ,
'elementFetchCallback' : elementFetchCallback ,
}
} ,
2015-03-10 22:59:24 +01:00
//-------------------------------------------------------------------------
messageBoxContent : function ( ) {
var message ;
var level ;
message = "" ;
level = 'HIDE' ;
if ( this . featureSet ( ) == 'EXPIRED' ) {
2015-07-20 10:27:28 +02:00
message = "Expired subscription" ;
2015-03-10 22:59:24 +01:00
level = 'ERROR' ;
}
return {
'message' : message ,
'level' : level
} ;
} ,
2015-09-23 13:44:29 +02:00
deviceProperties : function ( ) {
2014-07-28 18:07:48 +02:00
return {
'style' : this . mediaQueryStyle ( ) ,
2015-03-10 22:59:24 +01:00
'isTouchDevice' : this . isTouchDevice ( ) ,
'isDesktop' : this . isDesktop ( ) ,
2015-09-30 20:09:58 +02:00
'hasKeyboard' : this . hasKeyboard ( ) ,
'PIN' : Clipperz . PM . PIN
2014-07-28 18:07:48 +02:00
} ;
} ,
pageProperties : function ( aPageName ) {
var result ;
var extraProperties = null ;
2015-09-23 13:44:29 +02:00
result = this . deviceProperties ( ) ;
if ( this . user ( ) != null ) {
result = MochiKit . Base . update ( result , { 'preferences' : this . userPreferences ( ) } ) ;
}
2014-07-28 18:07:48 +02:00
if ( aPageName == 'loginPage' ) {
extraProperties = {
2015-09-30 20:09:58 +02:00
'mode' : this . loginMode ( ) ,
2015-03-11 18:19:29 +01:00
'isNewUserRegistrationAvailable' : Clipperz . PM . Proxy . defaultProxy . canRegisterNewUsers ( ) ,
2014-07-28 18:07:48 +02:00
'disabled' : false ,
2015-08-20 12:04:31 +02:00
'proxyInfo' : this . proxyInfo ( ) ,
2014-07-28 18:07:48 +02:00
} ;
2015-09-30 20:09:58 +02:00
} else if ( aPageName == 'unlockPage' ) {
extraProperties = {
2015-10-05 09:30:31 +02:00
'mode' : this . loginMode ( ) ,
'proxyInfo' : this . proxyInfo ( ) ,
2015-09-30 20:09:58 +02:00
}
2014-07-28 18:07:48 +02:00
} else if ( aPageName == 'registrationPage' ) {
} else if ( aPageName == 'mainPage' ) {
extraProperties = {
2014-08-02 14:45:22 +02:00
'messageBox' : this . messageBoxContent ( ) ,
2015-04-14 10:44:23 +02:00
'userInfo' : this . userInfo ( ) ,
2015-01-21 18:29:08 +01:00
'accountInfo' : this . userAccountInfo ( ) ,
2015-11-26 10:09:52 +01:00
'selectionPanelStatus' : this . isSelectionPanelOpen ( ) ? 'OPEN' : 'CLOSED' ,
'settingsPanelStatus' : this . isSettingsPanelOpen ( ) ? 'OPEN' : 'CLOSED' ,
2016-11-27 15:05:10 +01:00
// 'attachmentQueueBoxStatus': this.isAttachmentQueueBoxOpen() ? 'OPEN' : 'CLOSED',
// 'certificateQueueBoxStatus': this.isCertificateQueueBoxOpen() ? 'OPEN' : 'CLOSED',
2015-03-10 22:59:24 +01:00
'featureSet' : this . featureSet ( ) ,
'features' : this . features ( ) ,
'proxyInfo' : this . proxyInfo ( ) ,
2015-11-23 16:10:44 +01:00
'locked' : false ,
2016-11-27 15:05:10 +01:00
'notifications' : this . notifications ( ) ,
2015-11-23 16:10:44 +01:00
'attachmentQueueInfo' : this . attachmentQueueInfo ( ) ,
2016-11-27 15:05:10 +01:00
// 'certificateQueueInfo': this.certificateQueueInfo(),
2014-08-02 14:45:22 +02:00
// 'shouldIncludeArchivedCards': this.shouldIncludeArchivedCards(),
2014-07-28 18:07:48 +02:00
// 'cards': …,
// 'tags': …,
// 'selectedCard': …,
} ;
2015-09-23 13:44:29 +02:00
} else if ( aPageName == 'cardDetailPage' ) {
extraProperties = {
2016-11-27 15:05:10 +01:00
'notifications' : this . notifications ( ) ,
2015-11-23 16:10:44 +01:00
'attachmentQueueInfo' : this . attachmentQueueInfo ( ) ,
2016-11-27 15:05:10 +01:00
// 'certificateQueueInfo': this.certificateQueueInfo(),
2015-11-26 10:09:52 +01:00
'proxyInfo' : this . proxyInfo ( ) ,
2015-09-23 13:44:29 +02:00
} ;
2014-07-28 18:07:48 +02:00
} else if ( aPageName == 'errorPage' ) {
extraProperties = {
'message' : ''
} ;
}
2015-09-23 17:47:55 +02:00
result = MochiKit . Base . update ( result , extraProperties ) ;
2014-07-28 18:07:48 +02:00
return result ;
} ,
refreshCurrentPage : function ( ) {
if ( this . pages ( ) [ this . currentPage ( ) ] != null ) {
this . pages ( ) [ this . currentPage ( ) ] . setProps ( this . pageProperties ( this . currentPage ( ) ) ) ;
}
} ,
2013-10-02 09:59:30 +02:00
2014-07-28 18:07:48 +02:00
//=========================================================================
/ *
synchronizeLocalData _handler : function ( anEvent ) {
2013-10-02 09:59:30 +02:00
var deferredResult ;
2014-07-28 18:07:48 +02:00
deferredResult = new Clipperz . Async . Deferred ( 'MainController.synchronizeLocalData' , { trace : false } ) ;
2013-10-02 09:59:30 +02:00
// deferredResult.addMethod(this.proxy(), 'message', 'downloadAccountData', {});
deferredResult . addMethod ( this . user ( ) . connection ( ) , 'message' , 'downloadAccountData' , { } ) ;
deferredResult . addCallback ( function ( aResult ) {
Clipperz . PM . DataModel . devicePreferences . setAccountDataWityResponse ( aResult ) ;
// localStorage.setItem('clipperz_dump_data', aResult['data']);
// localStorage.setItem('clipperz_dump_version', aResult['version']);
// localStorage.setItem('clipperz_dump_date', new Date());
} )
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2014-07-28 18:07:48 +02:00
* /
2013-10-02 09:59:30 +02:00
//=========================================================================
2014-07-28 18:07:48 +02:00
resetPanels : function ( ) {
this . _isSelectionPanelOpen = false ;
this . _isSettingsPanelOpen = false ;
2015-07-20 10:27:28 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'closeSettingsPanel' ) ;
2014-07-28 18:07:48 +02:00
} ,
2015-01-06 15:42:14 +01:00
featureAvailableForStyles : function ( listOfSupportedStyles ) {
return MochiKit . Iter . some ( listOfSupportedStyles , MochiKit . Base . partial ( MochiKit . Base . operator . eq , this . mediaQueryStyle ( ) ) ) ;
} ,
2015-01-04 18:50:50 +01:00
2015-01-06 15:42:14 +01:00
shouldShowCardDetailWhenMovingBetweenCardsUsingKeys : function ( ) {
return ! ( this . featureAvailableForStyles ( [ 'narrow' ] ) && ( this . currentPage ( ) == 'mainPage' ) ) ;
} ,
isSelectionPanelHidable : function ( ) {
return ! this . featureAvailableForStyles ( [ 'extra-wide' ] ) ;
2015-01-04 16:53:08 +01:00
} ,
2015-01-04 18:50:50 +01:00
2014-07-28 18:07:48 +02:00
isSelectionPanelOpen : function ( ) {
return this . _isSelectionPanelOpen ;
} ,
2015-01-04 18:50:50 +01:00
2014-07-28 18:07:48 +02:00
toggleSelectionPanel _handler : function ( anEvent ) {
2015-01-04 16:53:08 +01:00
if ( this . isSelectionPanelHidable ( ) == true ) {
2015-01-06 15:42:14 +01:00
if ( this . currentPage ( ) == 'cardDetailPage' ) {
this . goBackToMainPage ( ) ;
}
2015-01-04 16:53:08 +01:00
this . _isSelectionPanelOpen = ! this . _isSelectionPanelOpen ;
this . setCloseMaskAction ( MochiKit . Base . method ( this , 'toggleSelectionPanel_handler' ) ) ;
this . refreshCurrentPage ( ) ;
}
2014-07-28 18:07:48 +02:00
} ,
2015-10-01 16:40:35 +02:00
hideSelectionPanel _handler : function ( anEvent ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.hideSelectionPanel_handler" , [
MochiKit . Base . bind ( function ( ) {
if ( this . isSelectionPanelOpen ( ) ) {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'toggleSelectionPanel' ) ;
}
} , this )
] , { trace : false } ) ;
2015-10-01 16:40:35 +02:00
} ,
2014-07-28 18:07:48 +02:00
isSettingsPanelOpen : function ( ) {
return this . _isSettingsPanelOpen ;
} ,
2015-01-04 18:50:50 +01:00
2014-07-28 18:07:48 +02:00
toggleSettingsPanel _handler : function ( anEvent ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.toggleSettingsPanel_handler" , [
MochiKit . Base . bind ( function ( ) {
this . _isSettingsPanelOpen = ! this . _isSettingsPanelOpen ;
this . setCloseMaskAction ( MochiKit . Base . method ( this , 'toggleSettingsPanel_handler' ) ) ;
if ( this . _isSettingsPanelOpen == false ) {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'closeSettingsPanel' ) ;
}
this . refreshCurrentPage ( ) ;
} , this )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
2016-11-27 15:05:10 +01:00
/ *
2015-11-23 16:10:44 +01:00
isAttachmentQueueBoxOpen : function ( ) {
return this . _isAttachmentQueueBoxOpen ;
} ,
toggleAttachmentQueueBox _handler : function ( anEvent ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.toggleAttachmentQueueBox_handler" , [
MochiKit . Base . bind ( function ( ) {
this . _isAttachmentQueueBoxOpen = ! this . _isAttachmentQueueBoxOpen ;
this . _isCertificateQueueBoxOpen = false ;
this . refreshCurrentPage ( ) ;
} , this )
] , { trace : false } ) ;
} ,
2016-11-27 15:05:10 +01:00
* /
2016-03-29 11:45:50 +02:00
//----------------------------------------------------------------------------
2016-11-27 15:05:10 +01:00
/ *
2016-03-29 11:45:50 +02:00
isCertificateQueueBoxOpen : function ( ) {
return this . _isCertificateQueueBoxOpen ;
} ,
toggleCertificateQueueBox _handler : function ( anEvent ) {
return Clipperz . Async . callbacks ( "MainController.toggleCertificateQueueBox_handler" , [
MochiKit . Base . bind ( function ( ) {
this . _isCertificateQueueBoxOpen = ! this . _isCertificateQueueBoxOpen ;
this . _isAttachmentQueueBoxOpen = false ;
this . refreshCurrentPage ( ) ;
} , this )
] , { trace : false } ) ;
2015-11-23 16:10:44 +01:00
} ,
2016-11-27 15:05:10 +01:00
* /
2015-01-04 18:50:50 +01:00
//----------------------------------------------------------------------------
selectedCardInfo : function ( ) {
return this . _selectedCardInfo ;
} ,
selectedCardIndex : function ( ) {
var selectedCardInfo ;
var result ;
result = - 1 ;
selectedCardInfo = this . selectedCardInfo ( ) ;
if ( selectedCardInfo != null ) {
var selectedCards ;
var reference ;
var i , c ;
selectedCards = this . selectedCards ( ) ;
reference = selectedCardInfo [ 'reference' ] ;
c = selectedCards . length ;
i = 0 ;
while ( i < c && result == - 1 ) {
if ( selectedCards [ i ] [ '_reference' ] == reference ) {
result = i ;
} else {
i ++ ;
}
}
}
return result ;
} ,
cardInfoAtIndex : function ( anIndex ) {
var card ;
card = this . selectedCards ( ) [ anIndex ] ;
2015-01-06 15:42:14 +01:00
2015-01-04 18:50:50 +01:00
return {
'label' : card [ 'label' ] ,
'reference' : card [ '_reference' ]
} ;
} ,
previousCardInfo : function ( ) {
var currentIndex ;
var nextIndex ;
2015-01-06 15:42:14 +01:00
var result ;
2015-01-04 18:50:50 +01:00
currentIndex = this . selectedCardIndex ( ) ;
if ( currentIndex == - 1 ) {
nextIndex = this . selectedCards ( ) . length - 1 ;
} else {
nextIndex = Math . max ( currentIndex - 1 , 0 ) ;
}
2015-01-06 15:42:14 +01:00
if ( currentIndex == nextIndex ) {
result = null ;
} else {
result = this . cardInfoAtIndex ( nextIndex ) ;
}
return result ;
2015-01-04 18:50:50 +01:00
} ,
nextCardInfo : function ( ) {
var currentIndex ;
var nextIndex ;
2015-01-06 15:42:14 +01:00
var result ;
2015-01-04 18:50:50 +01:00
currentIndex = this . selectedCardIndex ( ) ;
if ( currentIndex == - 1 ) {
nextIndex = 0 ;
} else {
nextIndex = Math . min ( currentIndex + 1 , this . selectedCards ( ) . length - 1 ) ;
}
2015-01-06 15:42:14 +01:00
if ( currentIndex == nextIndex ) {
result = null ;
} else {
result = this . cardInfoAtIndex ( nextIndex ) ;
}
return result ;
2015-01-04 18:50:50 +01:00
} ,
//............................................................................
2015-01-06 15:42:14 +01:00
goBackToMainPage : function ( anEvent ) {
if ( this . currentPage ( ) == 'cardDetailPage' ) {
2015-02-04 23:44:32 +01:00
var resetSelection = null ;
this . updateSelectedCard ( resetSelection , true , false ) ;
2015-01-06 15:42:14 +01:00
this . moveOutPage ( this . currentPage ( ) , 'mainPage' ) ;
}
} ,
2015-02-03 18:23:30 +01:00
selectCard : function ( someInfo , shouldUpdateCardDetail ) {
var result ;
2014-10-12 14:30:17 +02:00
2015-03-10 22:59:24 +01:00
if ( this . featureSet ( ) != 'EXPIRED' ) {
2015-01-21 18:29:08 +01:00
this . _selectedCardInfo = someInfo ;
this . refreshSelectedCards ( ) ;
2015-02-03 18:23:30 +01:00
result = this . updateSelectedCard ( someInfo , true , shouldUpdateCardDetail ) ;
2015-01-21 18:29:08 +01:00
// # TODO: make the selected element visible;
// this may not always be the case, as selection can also be changed using keys.
// MochiKit.Visual.ScrollTo(MochiKit.DOM.getElement("xxx"));
2015-02-03 18:23:30 +01:00
} else {
result = MochiKit . Async . succeed ( ) ;
} ;
return result ;
} ,
resetSelectedCard : function ( ) {
this . _selectedCardInfo = null ;
} ,
2016-03-29 11:45:50 +02:00
selectCard _handler : function ( someInfo ) {
var cardInfo = someInfo [ 'cardInfo' ] ;
var shouldUpdateCardDetail = someInfo [ 'update' ] ;
return Clipperz . Async . callbacks ( "MainController.selectCard_handler" , [
MochiKit . Base . method ( this , 'selectCard' , cardInfo , shouldUpdateCardDetail ) ,
MochiKit . Base . method ( this , 'historyPushState' , { selectedCardInfo : cardInfo } , "" , window . location . toString ( ) )
] , { trace : false } ) ;
} ,
blockDragOver : function ( anEvent ) {
anEvent . stopPropagation ( ) ;
anEvent . preventDefault ( ) ;
anEvent . dataTransfer . dropEffect = 'none' ;
2014-07-30 09:28:05 +02:00
} ,
2014-08-22 08:38:53 +02:00
refreshCardEditDetail _handler : function ( aRecordReference ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.refreshCardEditDetail_handler" , [
MochiKit . Base . method ( this , 'updateSelectedCard' , { 'reference' : aRecordReference } , false , true )
] , { trace : false } ) ;
2014-08-22 08:38:53 +02:00
} ,
2015-01-04 18:50:50 +01:00
//----------------------------------------------------------------------------
2015-06-27 19:08:20 +02:00
2015-05-21 14:32:51 +02:00
downloadExport _handler : function ( ) {
var exportController ;
var deferredResult ;
2015-08-21 11:42:05 +02:00
exportController = new Clipperz . PM . UI . ExportController ( ) ;
2015-05-21 14:32:51 +02:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.downloadExport_handler" , { trace : false } ) ;
2015-08-21 11:42:05 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'show' , "loading …" , true , true ) ;
deferredResult . addMethod ( this . user ( ) , 'getRecordsLoadingAllData' ) ;
deferredResult . addCallbackPass ( MochiKit . Base . method ( this . overlay ( ) , 'show' , "exporting …" , true , true ) ) ;
2015-05-21 14:32:51 +02:00
deferredResult . addMethod ( exportController , 'run' ) ;
deferredResult . addMethod ( this . overlay ( ) , 'done' , "" , 1 ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
//----------------------------------------------------------------------------
2015-04-03 14:44:04 +02:00
changePassphrase _handler : function ( newPassphrase ) {
2015-04-03 16:03:17 +02:00
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
var deferredResult ;
var getPassphraseDelegate ;
var user ;
2015-06-27 19:08:20 +02:00
2015-04-03 16:03:17 +02:00
getPassphraseDelegate = MochiKit . Base . partial ( MochiKit . Async . succeed , newPassphrase ) ;
user = new Clipperz . PM . DataModel . User ( { 'username' : this . user ( ) . username ( ) , 'getPassphraseFunction' : getPassphraseDelegate } ) ;
deferredResult = new Clipperz . Async . Deferred ( "MainController.changePassphrase_handler" , { trace : false } ) ;
deferredResult . addMethod ( this . overlay ( ) , 'show' , "changing …" , true ) ;
2015-06-27 19:08:20 +02:00
deferredResult . addMethod ( this . user ( ) , 'changePassphrase' , getPassphraseDelegate ) ;
2015-04-03 16:03:17 +02:00
deferredResult . addMethod ( user , 'login' ) ;
deferredResult . addMethod ( this , 'setUser' , user ) ;
deferredResult . addMethod ( this . overlay ( ) , 'done' , "saved" , 1 ) ;
deferredResult . callback ( ) ;
return deferredResult ;
2015-06-27 19:08:20 +02:00
} ,
2015-04-14 10:44:23 +02:00
deleteAccount _handler : function ( ) {
var deferredResult ;
2015-05-21 14:32:51 +02:00
var doneMessageDelay = 2 ;
2015-06-27 19:08:20 +02:00
2015-04-14 10:44:23 +02:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.deleteAccount_handler" , { trace : false } ) ;
2015-05-21 14:32:51 +02:00
deferredResult . addCallback ( MochiKit . Base . method ( this , 'ask' , {
'question' : "Do you really want to permanently delete your account?" ,
'possibleAnswers' : {
'cancel' : { 'label' : "No" , 'isDefault' : true , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
'revert' : { 'label' : "Yes" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'callback' ) }
}
} ) ) ,
2015-04-14 10:44:23 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'show' , "deleting …" , true ) ;
deferredResult . addMethod ( this . user ( ) , 'deleteAccount' ) ;
2015-05-21 14:32:51 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'done' , "deleted" , doneMessageDelay ) ;
deferredResult . addCallback ( MochiKit . Async . callLater , doneMessageDelay , function ( ) { window . location . href = '/' ; } ) ;
2015-04-14 10:44:23 +02:00
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2015-09-23 13:44:29 +02:00
//----------------------------------------------------------------------------
2015-06-27 19:08:20 +02:00
2015-09-23 13:44:29 +02:00
userPreferences : function ( ) {
return this . _userPreferences ;
} ,
setUserPreferences : function ( someValues ) {
this . _userPreferences = someValues ;
return someValues ;
} ,
updateUserPreferences : function ( ) {
return Clipperz . Async . callbacks ( "MainController.updateUserPreferences" , [
2015-09-23 10:24:49 +02:00
MochiKit . Base . method ( this . user ( ) , 'getPreferences' ) ,
2015-09-23 13:44:29 +02:00
MochiKit . Base . method ( this , 'setUserPreferences' ) ,
2015-09-23 10:24:49 +02:00
] , { trace : false } ) ;
} ,
2015-10-06 15:33:42 +02:00
setPreferences _handler : function ( anObject ) {
return Clipperz . Async . callbacks ( "MainController.setPreferences_handler" , [
2015-09-23 10:24:49 +02:00
MochiKit . Base . method ( this . overlay ( ) , 'show' , "" , true ) ,
2015-10-06 15:33:42 +02:00
MochiKit . Base . method ( this . user ( ) , 'setPreferences' , anObject ) ,
2015-09-23 13:44:29 +02:00
MochiKit . Base . method ( this , 'updateUserPreferences' ) ,
MochiKit . Base . method ( this , 'refreshCurrentPage' ) ,
2015-09-23 10:24:49 +02:00
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 0.5 ) ,
] , { trace : false } ) ;
} ,
2015-09-23 13:44:29 +02:00
//----------------------------------------------------------------------------
2015-05-14 18:55:18 +02:00
importCards _handler : function ( data ) {
return Clipperz . Async . callbacks ( "MainController.importCards_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "importing …" , true ) ,
2015-06-27 19:08:20 +02:00
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'toggleSettingsPanel' ) ,
2015-07-20 10:27:28 +02:00
function ( ) { return data ; } ,
MochiKit . Base . method ( this , 'importCards' ) ,
MochiKit . Base . method ( this . overlay ( ) , 'done' , "finished" , 1 ) ,
MochiKit . Base . method ( this . pages ( ) [ this . currentPage ( ) ] , 'setProps' , { 'mode' : 'view' , 'showGlobalMask' : false } ) ,
] , { trace : false } ) ;
} ,
importCards : function ( data ) {
return Clipperz . Async . callbacks ( "MainController.importCards" , [
2015-06-27 19:08:20 +02:00
function ( ) { return data ; } ,
MochiKit . Base . partial ( MochiKit . Base . map , MochiKit . Base . method ( this . user ( ) , 'createNewRecordFromJSON' ) ) ,
2015-05-14 18:55:18 +02:00
Clipperz . Async . collectAll ,
MochiKit . Base . method ( this . user ( ) , 'saveChanges' ) ,
MochiKit . Base . partial ( MochiKit . Base . method ( this , 'resetRecordsInfo' ) ) ,
MochiKit . Base . partial ( MochiKit . Base . method ( this , 'refreshUI' , null ) ) ,
] , { trace : false } ) ;
} ,
2015-04-03 14:44:04 +02:00
2015-06-27 19:08:20 +02:00
//----------------------------------------------------------------------------
updateOTPListAndDetails : function ( ) {
return Clipperz . Async . callbacks ( "MainController.updateOTPListAndDetails" , [
2015-09-23 10:24:49 +02:00
Clipperz . Async . collectResults ( "MainController.updateOTPListAndDetails <inner results>" , {
2015-06-27 19:08:20 +02:00
'userInfo' : MochiKit . Base . method ( this , 'userInfo' ) ,
'otpDetails' : Clipperz . Async . collectResults ( "User.updateOTPListAndDetails <otpDetails>" , {
'otpList' : MochiKit . Base . method ( this . user ( ) , 'getOneTimePasswords' ) ,
'otpsDetails' : MochiKit . Base . method ( this . user ( ) , 'getOneTimePasswordsDetails' ) ,
} ) ,
} , { trace : false } ) ,
function ( someData ) {
return MochiKit . Base . update ( someData [ 'userInfo' ] , someData [ 'otpDetails' ] ) ;
} ,
MochiKit . Base . bind ( function ( someUserInfo ) {
this . setPageProperties ( 'mainPage' , 'userInfo' , someUserInfo ) ;
} , this )
] , { trace : false } ) ;
} ,
/ * U s e d o n l y o n e t i m e ( t h e f i r s t t i m e t h e O T P E x t r a F e a t u r e l o a d s ) , o t h e r t i m e s
the list update is triggered by other operations . Maybe the first OTP list retrieval
could be done during init , so that this would not be necessary . * /
updateOTPListAndDetails _handler : function ( ) {
return this . updateOTPListAndDetails ( ) ;
} ,
createNewOTP _handler : function ( ) {
return Clipperz . Async . callbacks ( "MainController.createNewOTP_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "" , true ) ,
MochiKit . Base . method ( this . user ( ) , 'createNewOTP' ) ,
MochiKit . Base . method ( this , 'updateOTPListAndDetails' ) ,
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 0.5 ) ,
] , { trace : false } ) ;
} ,
deleteOTPs _handler : function ( aList ) {
return Clipperz . Async . callbacks ( "MainController.deleteOTPs_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "" , true ) ,
MochiKit . Base . method ( this . user ( ) , 'deleteOTPs' , aList ) ,
MochiKit . Base . method ( this , 'updateOTPListAndDetails' ) ,
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 0.5 ) ,
] , { trace : false } ) ;
} ,
2016-03-29 11:45:50 +02:00
changeOTPLabel _handler : function ( someInfo ) {
var reference = someInfo [ 'reference' ] ;
var label = someInfo [ 'label' ] ;
2015-06-27 19:08:20 +02:00
return Clipperz . Async . callbacks ( "MainController.changeOTPLabel_handler" , [
MochiKit . Base . method ( this . overlay ( ) , 'show' , "" , true ) ,
2016-03-29 11:45:50 +02:00
MochiKit . Base . method ( this . user ( ) , 'changeOTPLabel' , reference , label ) ,
2015-06-27 19:08:20 +02:00
MochiKit . Base . method ( this , 'updateOTPListAndDetails' ) ,
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 0.5 ) ,
] , { trace : false } ) ;
} ,
2015-04-03 14:44:04 +02:00
//----------------------------------------------------------------------------
2014-12-30 10:28:59 +01:00
saveChanges : function ( ) {
2015-01-02 10:13:04 +01:00
// TODO: handle errors while savings
2014-12-30 10:28:59 +01:00
return Clipperz . Async . callbacks ( "MainController.saveChanges" , [
2015-01-02 10:13:04 +01:00
MochiKit . Base . method ( this . overlay ( ) , 'show' , "saving …" , true ) ,
2014-12-30 10:28:59 +01:00
MochiKit . Base . method ( this . user ( ) , 'saveChanges' ) ,
2015-01-04 16:53:08 +01:00
MochiKit . Base . method ( this , 'resetRecordsInfo' ) ,
2015-01-02 10:13:04 +01:00
MochiKit . Base . method ( this . overlay ( ) , 'done' , "saved" , 1 ) ,
2014-12-30 10:28:59 +01:00
] , { trace : false } ) ;
} ,
2014-08-22 08:38:53 +02:00
saveCardEdits _handler : function ( aRecordReference ) {
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
var self = this ;
2015-11-26 16:02:44 +01:00
var record , wasBrandNew ;
2014-08-22 08:38:53 +02:00
return Clipperz . Async . callbacks ( "MainController.saveCardEdits_handler" , [
2014-09-05 18:17:41 +02:00
MochiKit . Base . method ( currentPage , 'setProps' , { 'showGlobalMask' : true } ) ,
2015-11-26 16:02:44 +01:00
MochiKit . Base . method ( this . user ( ) , 'getRecord' , aRecordReference ) ,
function ( aRecord ) { record = aRecord ; wasBrandNew = aRecord . isBrandNew ( ) ; } ,
2014-12-30 10:28:59 +01:00
MochiKit . Base . method ( this , 'saveChanges' ) ,
2015-11-26 16:02:44 +01:00
// When new record has attachments, server status should be updated as soon as it is available
function ( ) { return wasBrandNew ; } ,
Clipperz . Async . deferredIf ( 'WasBrandNew' , [
function ( ) { return record ; } ,
MochiKit . Base . method ( this , 'reloadAttachmentServerStatusCallback' )
] , [
// MochiKit.Async.succeed
] ) ,
2014-09-05 18:17:41 +02:00
MochiKit . Base . method ( currentPage , 'setProps' , { 'mode' : 'view' , 'showGlobalMask' : false } ) ,
MochiKit . Base . method ( this , 'refreshUI' , aRecordReference ) ,
2015-09-23 10:24:49 +02:00
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'enableLock' ) ,
2014-08-26 17:31:24 +02:00
] , { trace : false } ) ;
2014-08-22 08:38:53 +02:00
} ,
cancelCardEdits _handler : function ( aRecordReference ) {
2015-11-23 16:10:44 +01:00
return this . cancelCardEdits ( aRecordReference ) ;
} ,
cancelCardEdits : function ( aRecordReference ) {
2014-08-22 08:38:53 +02:00
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
var self = this ;
2014-08-26 17:31:24 +02:00
var wasBrandNew ;
2014-08-22 08:38:53 +02:00
return Clipperz . Async . callbacks ( "MainController.cancelCardEdits_handler" , [
2014-08-26 17:31:24 +02:00
MochiKit . Base . method ( this . user ( ) , 'getRecord' , aRecordReference ) ,
MochiKit . Base . methodcaller ( 'isBrandNew' ) ,
function ( aValue ) { wasBrandNew = aValue } ,
2014-08-22 08:38:53 +02:00
MochiKit . Base . method ( this . user ( ) , 'hasPendingChanges' ) ,
Clipperz . Async . deferredIf ( 'HasPendingChanges' , [
MochiKit . Base . method ( self , 'ask' , {
2015-07-05 09:09:33 +02:00
'question' : "There are pending changes to your card. Ignore changes?" ,
2014-08-22 08:38:53 +02:00
'possibleAnswers' : {
'cancel' : { 'label' : "No" , 'isDefault' : true , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
'revert' : { 'label' : "Yes" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'callback' ) }
}
2014-09-05 18:17:41 +02:00
} ) ,
2014-08-22 08:38:53 +02:00
] , [
// MochiKit.Async.succeed
] ) ,
MochiKit . Base . method ( this . user ( ) , 'revertChanges' ) ,
2014-09-05 18:17:41 +02:00
MochiKit . Base . method ( currentPage , 'setProps' , { 'mode' : 'view' } ) ,
2014-08-26 17:31:24 +02:00
MochiKit . Base . bind ( function ( ) {
var info ;
if ( wasBrandNew == true ) {
info = null ;
} else {
info = { 'reference' : aRecordReference } ;
}
2015-01-06 15:42:14 +01:00
this . updateSelectedCard ( info , false , true ) ;
2015-02-03 18:23:30 +01:00
} , this ) ,
MochiKit . Base . bind ( function ( ) {
if ( ( wasBrandNew == true ) && ( this . currentPage ( ) == 'cardDetailPage' ) ) {
this . goBackToMainPage ( ) ;
}
} , this ) ,
2015-09-23 10:24:49 +02:00
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'enableLock' ) ,
2014-08-26 17:31:24 +02:00
] , { trace : false } ) ;
2014-08-22 08:38:53 +02:00
} ,
2014-07-30 09:28:05 +02:00
//----------------------------------------------------------------------------
2014-08-02 14:45:22 +02:00
ask : function ( someInfo ) {
var deferredResult ;
2014-08-04 18:33:37 +02:00
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
2014-08-02 14:45:22 +02:00
deferredResult = new Clipperz . Async . Deferred ( 'MainController.ask' , { trace : false } ) ;
2014-09-05 18:17:41 +02:00
currentPage . setProps ( { 'ask' : { 'info' : someInfo , 'deferred' : deferredResult } , 'showGlobalMask' : true } ) ;
2014-08-02 14:45:22 +02:00
2014-09-05 18:17:41 +02:00
deferredResult . addBothPass ( MochiKit . Base . method ( currentPage , 'setProps' , { 'ask' : null , 'showGlobalMask' : false } ) ) ;
2014-08-02 14:45:22 +02:00
return deferredResult ;
} ,
2014-07-28 18:07:48 +02:00
//----------------------------------------------------------------------------
addCardClick _handler : function ( ) {
2015-02-04 23:44:32 +01:00
var newRecord ;
2015-11-24 17:17:29 +01:00
this . selectAllCards ( ) ;
2014-08-26 17:31:24 +02:00
return Clipperz . Async . callbacks ( "MainController.addCardClick_handler" , [
MochiKit . Base . method ( this . user ( ) , 'createNewRecord' ) ,
2015-02-03 18:23:30 +01:00
function ( aValue ) {
2015-02-04 23:44:32 +01:00
newRecord = aValue ;
return newRecord ;
2015-02-03 18:23:30 +01:00
} ,
2016-11-27 15:05:10 +01:00
MochiKit . Base . methodcaller ( 'addField' , { 'label' : "username" , 'value' : "" , 'hidden' : false } ) ,
function ( ) { return newRecord ; } ,
MochiKit . Base . methodcaller ( 'addField' , { 'label' : "password" , 'value' : "" , 'hidden' : true } ) ,
function ( ) { return newRecord ; } ,
2015-02-04 23:44:32 +01:00
MochiKit . Base . methodcaller ( 'reference' ) ,
2014-08-26 17:31:24 +02:00
MochiKit . Base . method ( this , 'refreshUI' ) ,
2015-02-04 23:44:32 +01:00
function ( ) { return newRecord ; } ,
MochiKit . Base . methodcaller ( 'reference' ) ,
MochiKit . Base . bind ( function ( aRecordReference ) {
2015-02-03 18:23:30 +01:00
return this . selectCard ( {
2015-02-04 23:44:32 +01:00
'reference' : aRecordReference ,
2015-02-03 18:23:30 +01:00
'label' : ""
} , true ) ;
} , this ) ,
2014-09-19 18:27:26 +02:00
MochiKit . Base . method ( this , 'enterEditMode' ) ,
2014-08-26 17:31:24 +02:00
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
deleteCard _handler : function ( anEvent ) {
2014-08-04 18:33:37 +02:00
var self = this ;
2014-07-30 09:28:05 +02:00
return Clipperz . Async . callbacks ( "MainController.deleteCard_handler" , [
2014-08-04 18:33:37 +02:00
MochiKit . Base . method ( self , 'ask' , {
2014-08-02 14:45:22 +02:00
'question' : "Delete card?" ,
'possibleAnswers' : {
2014-08-04 18:33:37 +02:00
'cancel' : { 'label' : "No" , 'isDefault' : true , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
2014-08-02 14:45:22 +02:00
'delete' : { 'label' : "Yes" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'callback' ) }
}
} ) ,
2014-07-30 09:28:05 +02:00
MochiKit . Base . method ( this . user ( ) , 'getRecord' , anEvent [ 'reference' ] ) ,
MochiKit . Base . method ( this . user ( ) , 'deleteRecord' ) ,
2014-12-30 10:28:59 +01:00
MochiKit . Base . method ( this , 'saveChanges' ) ,
2015-02-13 08:54:00 +01:00
MochiKit . Base . method ( this , 'exitCurrentSelection' ) ,
2014-07-30 09:28:05 +02:00
MochiKit . Base . method ( this , 'refreshUI' )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
2014-10-12 10:56:27 +02:00
toggleArchiveCard _handler : function ( anEvent ) {
2014-07-30 09:28:05 +02:00
return Clipperz . Async . callbacks ( "MainController.archiveCard_handler" , [
MochiKit . Base . method ( this . user ( ) , 'getRecord' , anEvent [ 'reference' ] ) ,
2014-10-12 10:56:27 +02:00
MochiKit . Base . methodcaller ( 'toggleArchive' ) ,
2014-12-30 10:28:59 +01:00
MochiKit . Base . method ( this , 'saveChanges' ) ,
2014-07-30 09:28:05 +02:00
MochiKit . Base . method ( this , 'refreshUI' , anEvent [ 'reference' ] )
2014-08-02 14:45:22 +02:00
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
2014-08-26 17:31:24 +02:00
cloneCard _handler : function ( anEvent ) {
2015-01-02 10:13:04 +01:00
var cardInfo ;
2014-08-26 17:31:24 +02:00
return Clipperz . Async . callbacks ( "MainController.cloneCard_handler" , [
MochiKit . Base . method ( this . user ( ) , 'getRecord' , anEvent [ 'reference' ] ) ,
MochiKit . Base . method ( this . user ( ) , 'cloneRecord' ) ,
2015-01-02 10:13:04 +01:00
Clipperz . Async . collectResults ( "MainController.cloneCard_handler <card info>" , {
'label' : MochiKit . Base . methodcaller ( 'label' ) ,
'reference' : MochiKit . Base . methodcaller ( 'reference' )
} , { trace : false } ) ,
function ( aValue ) { cardInfo = aValue ; return aValue ; } ,
MochiKit . Base . method ( this , 'saveChanges' ) ,
2016-03-29 11:45:50 +02:00
function ( ) {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'selectCard' , { 'cardInfo' : cardInfo , 'update' : false } ) ;
2015-01-02 10:13:04 +01:00
} ,
function ( aValue ) { return cardInfo [ 'reference' ] ; } ,
2014-08-26 17:31:24 +02:00
MochiKit . Base . method ( this , 'refreshUI' ) ,
2015-01-06 15:42:14 +01:00
] , { trace : false } ) ;
2014-08-26 17:31:24 +02:00
} ,
2015-11-26 10:09:52 +01:00
2015-11-23 16:10:44 +01:00
isPageInEditMode : function ( ) {
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
2015-11-26 10:09:52 +01:00
return currentPage ? currentPage . props [ 'mode' ] == 'edit' : false ;
2015-11-23 16:10:44 +01:00
} ,
2014-08-26 17:31:24 +02:00
2014-09-19 18:27:26 +02:00
enterEditMode : function ( ) {
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
currentPage . setProps ( { 'mode' : 'edit' } ) ;
2015-09-23 10:24:49 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'disableLock' ) ;
2014-09-19 18:27:26 +02:00
return Clipperz . Async . callbacks ( "MainController.enterEditMode" , [
MochiKit . Base . method ( this , 'allTags' , true ) ,
MochiKit . Base . keys ,
function ( aValue ) {
currentPage . setProps ( { 'allTags' : aValue } ) ;
} ,
] , { trace : false } ) ;
} ,
2014-07-28 18:07:48 +02:00
editCard _handler : function ( anEvent ) {
2014-09-19 18:27:26 +02:00
this . enterEditMode ( ) ;
} ,
2016-03-29 11:45:50 +02:00
certificateDetails : function ( aRecordReference ) {
return Clipperz . Async . callbacks ( "MainController.certificateDetails" , [
Clipperz . Async . collectResults ( "MainController.certificateDetails <inner results>" , {
'wallet' : MochiKit . Base . method ( this . user ( ) , 'getWallet' ) ,
'record' : MochiKit . Base . method ( this . user ( ) , 'getRecord' , aRecordReference ) ,
} , { trace : false } ) ,
Clipperz . Async . collectResults ( "MainController.showCertificatePreview_handler <inner results>" , {
'transaction' : function ( someValues ) { return someValues [ 'record' ] . computeCertificateInfo ( someValues [ 'wallet' ] ) ; } ,
'metadata' : [
MochiKit . Base . itemgetter ( 'record' ) ,
MochiKit . Base . methodcaller ( 'certificateMetadata' ) ,
Clipperz . Base . evalJSON
]
} , { trace : false } ) ,
] , { trace : false } ) ;
} ,
downloadCertificate _handler : function ( aRecordReference ) {
//console.log("DOWNLOAD CERTIFICATE", aRecordReference);
var certificateDownloadController ;
var deferredResult ;
certificateDownloadController = new Clipperz . PM . UI . CertificateDownloadController ( ) ;
deferredResult = new Clipperz . Async . Deferred ( "MainController.downloadCertificate_handler" , { trace : false } ) ;
deferredResult . addMethod ( this . overlay ( ) , 'show' , "" , true , false ) ;
deferredResult . addMethod ( this . user ( ) , 'getRecord' , aRecordReference ) ;
deferredResult . collectResults ( {
'attachments' : MochiKit . Base . methodcaller ( 'attachmentsInfo' ) ,
'certificateInfo' : MochiKit . Base . methodcaller ( 'certificateInfo' ) ,
'certificateDetails' : MochiKit . Base . method ( this , 'certificateDetails' , aRecordReference ) ,
} , { trace : false } ) ;
deferredResult . addMethod ( certificateDownloadController , 'run' ) ;
deferredResult . addMethod ( this . overlay ( ) , 'done' , "" , 1 ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
showCertificatePreview _handler : function ( aRecordReference ) {
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
currentPage . setProps ( { 'showCertificatePreview' : true } ) ;
return Clipperz . Async . callbacks ( "MainController.showCertificatePreview_handler" , [
MochiKit . Base . method ( this , 'certificateDetails' , aRecordReference ) ,
function ( aValue ) {
currentPage . setProps ( { 'certificateDetails' : aValue } ) ;
} ,
] , { trace : false } ) ;
} ,
hideCertificatePreview _handler : function ( aRecordReference ) {
return Clipperz . Async . callbacks ( "MainController.hideCertificatePreview_handler" , [
MochiKit . Base . method ( this . pages ( ) [ this . currentPage ( ) ] , 'setProps' , { 'showCertificatePreview' : false } )
] , { trace : false } ) ;
} ,
2016-11-27 15:05:10 +01:00
/ *
2016-03-29 11:45:50 +02:00
createCertificate _handler : function ( anEvent ) {
//console.log("CREATE CERTIFICATE HANDLER", anEvent);
//console.log("CREATE CERTIFICATE", this.user().accountInfo(), this.userAccountInfo());
var certificateQuota = this . userAccountInfo ( ) [ 'certificateQuota' ] ;
var availableCertificates =
certificateQuota [ 'totalNumber' ]
- ( certificateQuota [ 'used' ] [ 'published' ] + certificateQuota [ 'used' ] [ 'requested' ] ) ;
var result ;
var self = this ;
if ( availableCertificates > 0 ) {
var documentID ;
//console.log("CREATE CERTIFICATE - availableCertificates", availableCertificates);
result = Clipperz . Async . callbacks ( "MainController.createCertificate_handler [option A]" , [
MochiKit . Base . method ( self , 'ask' , {
'question' : "Create certificate?" ,
'description' : [
React . DOM . p ( { 'className' : 'cardCertificateWarning' } , "You are going to register the content of this card on the Bitcoin blockchain." ) ,
React . DOM . p ( { 'className' : 'cardCertificateWarning' } , "Afterward you won't be able to make any change, so make sure the card contains all the desired data and files before proceeding." ) ,
React . DOM . p ( { 'className' : 'cardCertificateWarning' } , availableCertificates + " registrations left" ) ,
] ,
'possibleAnswers' : {
'cancel' : { 'label' : "Cancel" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
'delete' : { 'label' : "Continue" , 'isDefault' : true , 'answer' : MochiKit . Base . methodcaller ( 'callback' ) }
}
} ) ,
MochiKit . Base . method ( this . overlay ( ) , 'show' , "registering" , true ) ,
MochiKit . Base . method ( this . user ( ) , 'getRecord' , anEvent [ 'reference' ] ) ,
MochiKit . Base . method ( this . user ( ) , 'createCertificateForRecord' ) ,
MochiKit . Base . method ( this . user ( ) , 'saveChangesWithExtraParameters' ) ,
MochiKit . Base . method ( this . user ( ) , 'getRecord' , anEvent [ 'reference' ] ) ,
MochiKit . Base . methodcaller ( 'updateCertificateInfo' ) ,
MochiKit . Base . method ( this . overlay ( ) , 'done' , "" , 1 ) ,
MochiKit . Base . method ( this , 'updateCertificateQueueInfo' ) ,
MochiKit . Base . method ( this , 'resetRecordsInfo' ) ,
MochiKit . Base . method ( this , 'refreshUI' , anEvent [ 'reference' ] ) ,
] , { trace : false } ) ;
} else {
result = Clipperz . Async . callbacks ( "MainController.createCertificate_handler [option B]" , [
MochiKit . Base . method ( self , 'ask' , {
'question' : "Sorry, registration not available" ,
'description' : [
React . DOM . p ( { 'className' : 'cardCertificateWarning' } , "You can't register this card on the Bitcoin blockchain because you have already consumed all your quota. Replenish your supply!" ) ,
] ,
'possibleAnswers' : {
'cancel' : { 'label' : "Ok" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
// 'subscribe': {'label':"Upgrade", 'isDefault':true, 'answer':MochiKit.Base.noop, 'disabled':true}
}
} ) ,
] , { trace : false } ) ;
}
return result ;
} ,
2016-11-27 15:05:10 +01:00
* /
2016-03-29 11:45:50 +02:00
//...........................................................................
2016-11-27 15:05:10 +01:00
/ *
2016-03-29 11:45:50 +02:00
updateCertificateQueueInfo : function ( ) {
return Clipperz . Async . callbacks ( "MainController.updateCertificateQueueInfo" , [
MochiKit . Base . method ( this . user ( ) . connection ( ) , 'message' , 'getCertificatesStatus' , { } ) ,
MochiKit . Base . bind ( function ( certificatesStatus ) {
return MochiKit . Base . map ( MochiKit . Base . bind ( function ( certificateStatus ) {
var matchingRecords ;
var result ;
matchingRecords = MochiKit . Base . filter ( function ( aRecordInfo ) { return aRecordInfo [ '_reference' ] == certificateStatus [ 0 ] ; } , this . _recordsInfo ) ;
if ( matchingRecords . length == 1 ) {
result = { 'reference' : certificateStatus [ 0 ] , 'status' : certificateStatus [ 1 ] , 'label' : matchingRecords [ 0 ] [ 'label' ] } ;
} else {
result = null ;
}
return result ;
} , this ) , MochiKit . Base . zip ( MochiKit . Base . keys ( certificatesStatus ) , MochiKit . Base . values ( certificatesStatus ) ) ) ;
} , this ) ,
MochiKit . Base . method ( this , '_updatedCertificateQueueInfo' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'certificateQueueInfo' ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'cardDetailPage' , 'certificateQueueInfo' ) ,
] , { trace : false } ) ;
} ,
_updatedCertificateQueueInfo : function ( newQueueStatus ) {
var hasPendingPublishingCertificate ;
this . _certificateQueueStatus = newQueueStatus ;
hasPendingPublishingCertificate = MochiKit . Iter . some ( this . _certificateQueueStatus , function ( anInfo ) { return ( anInfo && ( anInfo [ 'status' ] == 'requested' ) ) ; } ) ;
//console.log("hasPendingPublishingCertificate", hasPendingPublishingCertificate);
if ( hasPendingPublishingCertificate ) {
//console.log("Rescheduled call to 'updateCertificateQueueInfo'");
MochiKit . Async . callLater ( 10 * 60 , MochiKit . Base . method ( this , 'updateCertificateQueueInfo' ) ) ;
}
return this . _certificateQueueStatus ;
} ,
certificateQueueInfo : function ( ) {
return this . _certificateQueueStatus ;
} ,
closeCertificateNotification _handler : function ( aRecordReference ) {
return Clipperz . Async . callbacks ( "MainController.closeCertificateNotification_handler" , [
MochiKit . Base . method ( this . user ( ) . connection ( ) , 'message' , 'acknowledgeCertificateStatus' , { 'reference' : aRecordReference } ) ,
MochiKit . Base . method ( this , 'updateCertificateQueueInfo' ) ,
] , { trace : false } ) ;
} ,
showCertificateCard _handler : function ( aRecordReference ) {
console . log ( "showCertificateCard_handler" ) ;
return Clipperz . Async . callbacks ( "MainController.showCertificateCard_handler" , [
// MochiKit.Base.bind(function () { this._isAttachmentQueueBoxOpen = false; }, this),
MochiKit . Base . method ( this , 'selectCard_handler' , { 'cardInfo' : { 'reference' : aRecordReference } , 'update' : true } ) ,
] , { trace : false } ) ;
} ,
2016-11-27 15:05:10 +01:00
* /
2016-03-29 11:45:50 +02:00
//===========================================================================
2014-09-19 18:27:26 +02:00
addTag _handler : function ( anEvent ) {
var record = this . pages ( ) [ this . currentPage ( ) ] . props [ 'selectedCard' ] [ '_record' ] ;
var tag = anEvent ;
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.addTag' , { trace : false } ) ;
deferredResult . addMethod ( record , 'addTag' , tag ) ;
deferredResult . addMethod ( this , 'collectRecordInfo' , record ) ;
deferredResult . addMethod ( this , 'setPageProperties' , this . currentPage ( ) , 'selectedCard' ) ;
// deferredResult.addMethod(this, 'refreshCurrentPage');
deferredResult . callback ( ) ;
return deferredResult ;
} ,
removeTag _handler : function ( anEvent ) {
var record = this . pages ( ) [ this . currentPage ( ) ] . props [ 'selectedCard' ] [ '_record' ] ;
var tag = anEvent ;
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( 'MainController.removeTag' , { trace : false } ) ;
deferredResult . addMethod ( record , 'removeTag' , tag ) ;
deferredResult . addMethod ( this , 'collectRecordInfo' , record ) ;
deferredResult . addMethod ( this , 'setPageProperties' , this . currentPage ( ) , 'selectedCard' ) ;
// deferredResult.addMethod(this, 'refreshCurrentPage');
deferredResult . callback ( ) ;
return deferredResult ;
2014-07-28 18:07:48 +02:00
} ,
goBackToMainPage _handler : function ( anEvent ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.goBackToMainPage_handler" , [
MochiKit . Base . method ( this , 'goBackToMainPage' , anEvent ) ,
MochiKit . Base . method ( this , 'historyPushState' , { selectedCardInfo : null } , "" , window . location . toString ( ) )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
//============================================================================
selectAllCards _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.selectAllCards_handler" , [
MochiKit . Base . method ( this , 'selectAllCards' )
] , { trace : false } ) ;
2015-11-23 16:10:44 +01:00
} ,
selectAllCards : function ( ) {
2015-08-20 10:52:49 +02:00
this . setPageProperties ( 'mainPage' , 'searchTerm' , '' ) ;
2015-01-04 18:50:50 +01:00
this . resetSelectedCard ( ) ;
2014-07-28 18:07:48 +02:00
this . setFilter ( 'ALL' ) ;
2015-10-01 16:40:35 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ;
2014-07-30 09:28:05 +02:00
return this . refreshSelectedCards ( ) ;
2014-07-28 18:07:48 +02:00
} ,
selectRecentCards _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.selectRecentCards_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , 'RECENT' ) ,
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
} ,
selectCardsWithCertificate _handler : function ( ) {
return Clipperz . Async . callbacks ( "MainController.selectCardsWithCertificate_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , 'WITH_CERTIFICATE' ) ,
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
2015-11-23 16:10:44 +01:00
selectCardsWithAttachments _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.selectCardsWithAttachments_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , 'WITH_ATTACHMENTS' ) ,
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
2015-11-23 16:10:44 +01:00
} ,
2014-09-22 16:53:44 +02:00
search _handler : function ( aValue ) {
2016-03-29 11:45:50 +02:00
var searchType ;
2014-10-12 14:30:17 +02:00
2014-09-22 16:53:44 +02:00
if ( aValue == "" ) {
2016-03-29 11:45:50 +02:00
searchType = 'ALL' ;
2014-09-22 16:53:44 +02:00
} else {
2016-03-29 11:45:50 +02:00
searchType = 'SEARCH' ;
2014-09-22 16:53:44 +02:00
}
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.search_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , searchType , aValue ) ,
MochiKit . Base . method ( this , 'setPageProperties' , 'mainPage' , 'searchTerm' , aValue ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
2014-09-22 16:53:44 +02:00
} ,
2014-07-28 18:07:48 +02:00
tagSelected _handler : function ( aTag ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.tagSelected_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , 'TAG' , aTag ) ,
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
2014-07-30 09:28:05 +02:00
} ,
2014-08-02 14:45:22 +02:00
selectUntaggedCards _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.selectUntaggedCards_handler" , [
MochiKit . Base . method ( this , 'resetSelectedCard' ) ,
MochiKit . Base . method ( this , 'setFilter' , 'UNTAGGED' ) ,
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'hideSelectionPanel' ) ,
MochiKit . Base . method ( this , 'refreshSelectedCards' )
] , { trace : false } ) ;
2014-08-02 14:45:22 +02:00
} ,
2014-07-30 09:28:05 +02:00
//............................................................................
showArchivedCards _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.showArchivedCards_handler" , [
MochiKit . Base . method ( this , 'setShouldIncludeArchivedCards' , true ) ,
MochiKit . Base . method ( this , 'refreshUI' )
] , { trace : false } ) ;
2014-07-30 09:28:05 +02:00
} ,
hideArchivedCards _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.hideArchivedCards_handler" , [
MochiKit . Base . method ( this , 'setShouldIncludeArchivedCards' , false ) ,
MochiKit . Base . method ( this , 'refreshUI' )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
//----------------------------------------------------------------------------
setCloseMaskAction : function ( aFunction ) {
this . _closeMaskAction = aFunction ;
} ,
maskClick _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.maskClick_handler" , [
MochiKit . Base . bind ( function ( ) {
this . _closeMaskAction . apply ( this ) ;
this . _closeMaskAction = null ;
} , this )
] , { trace : false } ) ;
2014-07-28 18:07:48 +02:00
} ,
2015-08-20 10:52:49 +02:00
//............................................................................
showHelp _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.showHelp_handler" , [
MochiKit . Base . bind ( function ( ) {
if ( this . currentPage ( ) == 'mainPage' ) {
this . setPageProperties ( this . currentPage ( ) , 'showHelp' , true ) ;
}
} , this )
] , { trace : false } ) ;
2015-08-20 10:52:49 +02:00
} ,
closeHelp _handler : function ( ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.closeHelp_handler" , [
MochiKit . Base . method ( this , 'setPageProperties' , this . currentPage ( ) , 'showHelp' , false )
] , { trace : false } ) ;
2015-08-20 10:52:49 +02:00
} ,
isShowingHelp : function ( ) {
return this . pages ( ) [ this . currentPage ( ) ] . props [ 'showHelp' ] ;
} ,
2014-07-28 18:07:48 +02:00
//============================================================================
matchMediaQuery _handler : function ( newQueryStyle ) {
2015-11-26 10:09:52 +01:00
var wasInEditMode = this . isPageInEditMode ( ) ;
var currentPage = this . currentPage ( ) ;
var selectedCardInfo = this . selectedCardInfo ( ) ;
2014-07-28 18:07:48 +02:00
this . _mediaQueryStyle = newQueryStyle ;
2015-11-30 11:47:06 +01:00
MochiKit . DOM . setElementClass ( document . body , newQueryStyle ) ;
2015-11-26 10:09:52 +01:00
if ( currentPage == 'cardDetailPage' ) {
2014-07-28 18:07:48 +02:00
this . moveOutPage ( this . currentPage ( ) , 'mainPage' ) ;
}
2015-11-26 10:09:52 +01:00
if ( selectedCardInfo ) {
this . pages ( ) [ currentPage ] . setProps ( { 'mode' : 'view' } ) ;
if ( currentPage == 'mainPage' && newQueryStyle == 'narrow' ) {
this . selectCard ( selectedCardInfo , true ) ;
}
if ( wasInEditMode ) {
MochiKit . Async . callLater ( 0.1 , MochiKit . Base . method ( this , 'enterEditMode' ) ) ;
MochiKit . Async . callLater ( 0.1 , MochiKit . Base . method ( this , 'updateSelectedCard' , this . selectedCardInfo ( ) , false , true ) ) ;
}
}
2014-07-28 18:07:48 +02:00
this . resetPanels ( ) ;
this . refreshCurrentPage ( ) ;
} ,
unmatchMediaQuery _handler : function ( queryStyle ) {
} ,
mediaQueryStyle : function ( ) {
return this . _mediaQueryStyle ;
} ,
//----------------------------------------------------------------------------
isTouchDevice : function ( ) {
return this . _isTouchDevice ;
} ,
isDesktop : function ( ) {
return this . _isDesktop ;
} ,
hasKeyboard : function ( ) {
return this . _hasKeyboard ;
} ,
2015-01-02 10:13:04 +01:00
//============================================================================
2015-01-04 16:53:08 +01:00
downloadOfflineCopy _handler : function ( anEvent ) {
2015-01-02 10:13:04 +01:00
var downloadHref ;
var deferredResult ;
var newWindow ;
downloadHref = window . location . href . replace ( /\/[^\/]*$/ , '' ) + Clipperz _dumpUrl ;
newWindow = window . open ( "" , "" ) ;
deferredResult = new Clipperz . Async . Deferred ( "AppController.handleDownloadOfflineCopy" , { trace : false } ) ;
deferredResult . addCallback ( MochiKit . Base . method ( this . user ( ) . connection ( ) , 'message' ) , 'echo' , { 'echo' : "echo" } ) ;
deferredResult . addCallback ( function ( aWindow ) {
aWindow . location . href = downloadHref ;
} , newWindow ) ;
deferredResult . callback ( ) ;
2015-01-06 15:42:14 +01:00
2015-01-02 10:13:04 +01:00
return deferredResult ;
} ,
2014-07-28 18:07:48 +02:00
//============================================================================
2015-01-04 16:53:08 +01:00
focusOnSearch : function ( anEvent ) {
anEvent . preventDefault ( ) ;
2015-02-03 18:23:30 +01:00
2015-02-03 18:24:49 +01:00
if ( this . pages ( ) [ this . currentPage ( ) ] . props [ 'mode' ] == 'edit' ) {
// pass
} else {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'toggleSelectionPanel' ) ;
MochiKit . DOM . getElement ( 'searchValue' ) . focus ( ) ;
MochiKit . DOM . getElement ( 'searchValue' ) . select ( ) ;
}
2015-01-04 16:53:08 +01:00
} ,
2015-01-06 15:42:14 +01:00
2015-01-04 16:53:08 +01:00
exitSearch _handler : function ( anEvent ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.exitSearch_handler" , [
MochiKit . Base . partial ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'toggleSelectionPanel' ) ,
MochiKit . Base . method ( MochiKit . DOM . getElement ( 'searchValue' ) , 'blur' )
] , { trace : false } ) ;
2015-01-04 16:53:08 +01:00
} ,
selectPreviousCard : function ( ) {
2015-01-06 15:42:14 +01:00
var prevCardInfo ;
var shouldUpdateCardDetail ;
prevCardInfo = this . previousCardInfo ( ) ;
shouldUpdateCardDetail = this . shouldShowCardDetailWhenMovingBetweenCardsUsingKeys ( ) ;
2015-11-23 16:10:44 +01:00
2015-01-06 15:42:14 +01:00
if ( prevCardInfo != null ) {
2016-03-29 11:45:50 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'selectCard' , { 'cardInfo' : prevCardInfo , 'update' : shouldUpdateCardDetail } ) ;
2015-01-06 15:42:14 +01:00
}
2015-01-04 16:53:08 +01:00
} ,
selectNextCard : function ( ) {
2015-01-06 15:42:14 +01:00
var nextCardInfo ;
var shouldUpdateCardDetail ;
nextCardInfo = this . nextCardInfo ( ) ;
shouldUpdateCardDetail = this . shouldShowCardDetailWhenMovingBetweenCardsUsingKeys ( ) ;
2015-11-23 16:10:44 +01:00
2015-01-06 15:42:14 +01:00
if ( nextCardInfo != null ) {
2016-03-29 11:45:50 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'selectCard' , { 'cardInfo' : nextCardInfo , 'update' : shouldUpdateCardDetail } ) ;
2015-01-06 15:42:14 +01:00
}
} ,
selectDetail : function ( ) {
//console.log("TODO: SELECT DETAIL (right arrow key)", this.mediaQueryStyle(), this.currentPage(), this.selectedCardInfo());
if ( ( this . mediaQueryStyle ( ) == 'narrow' ) && ( this . currentPage ( ) == 'mainPage' ) ) {
Clipperz . Async . callbacks ( "MainController.selectDetail" , [
MochiKit . Base . method ( this . user ( ) , 'getRecord' , this . selectedCardInfo ( ) [ 'reference' ] ) ,
MochiKit . Base . method ( this , 'collectRecordInfo' ) ,
MochiKit . Base . method ( this , 'showCardDetailInNarrowView' ) ,
] , { trace : false } ) . callback ( ) ;
}
2015-01-04 16:53:08 +01:00
} ,
2015-01-06 15:42:14 +01:00
exitCurrentSelection : function ( ) {
2015-08-20 10:52:49 +02:00
if ( this . isShowingHelp ( ) ) {
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'closeHelp' ) ;
} else {
2016-03-29 11:45:50 +02:00
var currentPage = this . pages ( ) [ this . currentPage ( ) ] ;
if ( currentPage . props [ 'showCertificatePreview' ] == true ) {
currentPage . setProps ( { 'showCertificatePreview' : false } ) ;
} else if ( this . currentPage ( ) == 'cardDetailPage' ) {
2015-08-20 10:52:49 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'goBackToMainPage' , { 'reference' : this . selectedCardInfo ( ) [ 'reference' ] } ) ;
} else if ( this . currentPage ( ) == 'mainPage' ) {
2016-03-29 11:45:50 +02:00
MochiKit . Signal . signal ( Clipperz . Signal . NotificationCenter , 'selectCard' , { 'cardInfo' : null , 'update' : true } ) ;
2015-08-20 10:52:49 +02:00
}
2015-01-06 15:42:14 +01:00
}
} ,
2015-01-04 16:53:08 +01:00
//============================================================================
2015-11-23 16:10:44 +01:00
2016-11-27 15:05:10 +01:00
addNotification _handler : function ( aNotification ) {
2016-11-27 16:05:23 +01:00
//console.log("ADD NOTIFICATION", aNotification);
2016-11-27 15:05:10 +01:00
var notification ;
notification = {
'id' : Clipperz . PM . Crypto . randomKey ( ) ,
'date' : new Date ( ) ,
'message' : aNotification [ 'message' ] ,
'level' : aNotification [ 'level' ] ,
'callback' : aNotification [ 'callback' ] ,
} ;
this . notifications ( ) . unshift ( notification ) ;
this . updateNotifications ( ) ;
} ,
acknowledgeNotification _handler : function ( aNotificationReference ) {
2016-11-27 16:05:23 +01:00
//console.log("ACKNOWLEDGE NOTIFICATION", aNotificationReference);
2016-11-27 15:05:10 +01:00
var objectIndex = - 1 ;
var i , c ;
c = this . notifications ( ) . length ;
for ( i = 0 ; i < c ; i ++ ) {
if ( this . notifications ( ) [ i ] [ 'id' ] == aNotificationReference ) {
objectIndex = i ;
}
}
if ( objectIndex != - 1 ) {
Clipperz . Base . removeObjectAtIndexFromArray ( objectIndex , this . notifications ( ) ) ;
} else {
console . log ( "WARNING: notification with ID '" + aNotificationReference + "' not found" ) ;
}
this . updateNotifications ( ) ;
} ,
notifications : function ( ) {
return this . _notifications ;
} ,
updateNotifications : function ( ) {
2016-11-27 16:05:23 +01:00
//console.log("UPDATE NOTIFICATIONS");
2016-11-27 15:05:10 +01:00
this . setPageProperties ( this . currentPage ( ) , 'notifications' , this . notifications ( ) ) ;
} ,
/ *
2015-11-23 16:10:44 +01:00
updateAttachmentQueueInfo _handler : function ( someProperties ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController.updateAttachmentQueueInfo_handler" , [
MochiKit . Base . method ( this , 'setPageProperties' , this . currentPage ( ) , 'attachmentQueueInfo' , this . attachmentQueueInfo ( ) )
] , { trace : false } ) ;
2015-11-23 16:10:44 +01:00
} ,
2016-11-27 15:05:10 +01:00
* /
2016-03-29 11:45:50 +02:00
addAttachment _handler : function ( aFileInfo ) { // aReference, someMetadata, aKey, aNonce
2015-11-23 16:10:44 +01:00
var deferredResult ;
2016-03-29 11:45:50 +02:00
var record = aFileInfo [ 'record' ] ;
var file = aFileInfo [ 'file' ] ;
//console.log("addAttachment_handler", aFileInfo, record, file);
2015-11-23 16:10:44 +01:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.addCardAttachment_handler" , { 'trace' : false } ) ;
2016-03-29 11:45:50 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'show' , "reading" , true ) ;
deferredResult . addMethod ( record , 'createNewAttachment' ) ;
deferredResult . addCallback ( MochiKit . Base . methodcaller ( 'setFile' , file ) ) ;
2015-11-23 16:10:44 +01:00
deferredResult . addMethod ( this . attachmentController ( ) , 'addAttachment' ) ;
2016-03-29 11:45:50 +02:00
deferredResult . addMethod ( this . overlay ( ) , 'hide' , true ) ;
deferredResult . addCallback ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'refreshCardEditDetail' , record . reference ( ) ) ;
2015-11-23 16:10:44 +01:00
deferredResult . callback ( ) ;
return deferredResult ;
} ,
2017-01-21 15:03:42 +01:00
copyFieldValueFeedback _handler : function ( ) {
// this.overlay().show("copy", true);
// MochiKit.Async.callLater(0.5, MochiKit.Base.method(this.overlay(), 'hide', true));
this . overlay ( ) . show ( "copying …" , true ) ;
this . overlay ( ) . customResult ( 'copy' , "copied" , 0.5 ) ;
} ,
2016-03-29 11:45:50 +02:00
uploadMessageCallback : function ( someArguments , aProgressCallback ) {
2015-11-23 16:10:44 +01:00
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( "MainController.uploadMessageCallback" , { 'trace' : false } ) ;
deferredResult . addMethod ( this . user ( ) . connection ( ) , 'uploadAttachment' , someArguments , aProgressCallback ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
//----------------------------------------------------------------------------
2016-03-29 11:45:50 +02:00
removeAttachment _handler : function ( anAttachmentInfo ) {
2015-11-23 16:10:44 +01:00
var deferredResult ;
2016-03-29 11:45:50 +02:00
var record = anAttachmentInfo [ 'record' ] ;
var attachment = anAttachmentInfo [ 'attachment' ] ;
2015-11-23 16:10:44 +01:00
deferredResult = new Clipperz . Async . Deferred ( "MainController.removeAttachment_handler" , { trace : false } ) ;
deferredResult . addCallback ( MochiKit . Base . method ( this , 'ask' , {
'question' : "Do you really want to delete this attachment?" ,
'possibleAnswers' : {
'cancel' : { 'label' : "No" , 'isDefault' : true , 'answer' : MochiKit . Base . methodcaller ( 'cancel' , new MochiKit . Async . CancelledError ( ) ) } ,
'revert' : { 'label' : "Yes" , 'isDefault' : false , 'answer' : MochiKit . Base . methodcaller ( 'callback' ) }
}
} ) ) ,
2016-03-29 11:45:50 +02:00
deferredResult . addMethod ( this , 'cancelAttachment_handler' , attachment ) ;
deferredResult . addMethod ( record , 'removeAttachment' , attachment ) ;
deferredResult . addCallback ( MochiKit . Signal . signal , Clipperz . Signal . NotificationCenter , 'refreshCardEditDetail' , record . reference ( ) ) ;
2015-11-23 16:10:44 +01:00
deferredResult . callback ( ) ;
return deferredResult ;
} ,
//----------------------------------------------------------------------------
2016-03-29 11:45:50 +02:00
getAttachment _handler : function ( anAttachment ) {
2015-11-23 16:10:44 +01:00
this . attachmentController ( ) . getAttachment ( anAttachment ) ;
} ,
downloadMessageCallback : function ( anAttachment , aProgressCallback ) {
var deferredResult ;
deferredResult = new Clipperz . Async . Deferred ( "MainController.downloadAttachment_handler" , { 'trace' : false } ) ;
deferredResult . addMethod ( this . user ( ) . connection ( ) , 'downloadAttachment' , {
'reference' : anAttachment . reference ( )
} , aProgressCallback ) ;
deferredResult . callback ( ) ;
return deferredResult ;
} ,
//----------------------------------------------------------------------------
cancelAttachment _handler : function ( anAttachment ) {
return this . attachmentController ( ) . cancelAttachment ( anAttachment ) ;
} ,
2016-11-27 15:05:10 +01:00
/ *
2015-11-23 16:10:44 +01:00
closeAttachmentNotification _handler : function ( aNotificationId ) {
2016-03-29 11:45:50 +02:00
return Clipperz . Async . callbacks ( "MainController." , [
MochiKit . Base . method ( this . attachmentController ( ) , 'removeNotification' , aNotificationId )
] , { trace : false } ) ;
2015-11-23 16:10:44 +01:00
} ,
2016-11-27 15:05:10 +01:00
* /
2015-11-23 16:10:44 +01:00
//----------------------------------------------------------------------------
reloadAttachmentServerStatusCallback : function ( aRecord ) {
2015-11-26 16:02:44 +01:00
if ( ! aRecord . isBrandNew ( ) ) {
return Clipperz . Async . callbacks ( "MainController.reloadAttachmentServerStatus_handler" , [
2016-03-29 11:45:50 +02:00
MochiKit . Base . method ( aRecord , 'updatedAttachmentServerStatus' ) ,
2015-11-26 16:02:44 +01:00
MochiKit . Base . bind ( function ( ) {
if ( this . _selectedCardInfo && this . _selectedCardInfo [ 'reference' ] ) {
this . refreshUI ( this . _selectedCardInfo [ 'reference' ] ) ;
}
} , this ) ,
] , { trace : false } ) ;
}
2015-11-23 16:10:44 +01:00
} ,
//============================================================================
registerHistoryHandler : function ( ) {
window . onpopstate = MochiKit . Base . method ( this , 'handleOnpopstate' ) ;
} ,
handleOnpopstate : function ( anEvent ) {
if ( this . filter ( ) . type != 'ALL' ) {
this . selectAllCards ( ) ;
2015-12-07 10:56:27 +01:00
// window.history.pushState(window.history.state, "", window.location.toString());
this . historyPushState ( this . historyState , "" , window . location . toString ( ) ) ;
2015-11-23 16:10:44 +01:00
} else if ( anEvent . state ) {
if ( this . isPageInEditMode ( ) ) {
2015-12-07 10:56:27 +01:00
// window.history.pushState({selectedCardInfo: this.selectedCardInfo()}, "", window.location.toString());
this . historyPushState ( { selectedCardInfo : this . selectedCardInfo ( ) } , "" , window . location . toString ( ) ) ;
2015-11-23 16:10:44 +01:00
this . cancelCardEdits ( this . selectedCardReference ( ) ) ;
} else {
if ( anEvent . state [ 'selectedCardInfo' ] ) {
this . selectCard ( anEvent . state [ 'selectedCardInfo' ] , true ) ;
} else {
this . selectCard ( null , true ) ;
this . goBackToMainPage ( ) ;
}
}
}
// console.log('History changed', anEvent.state);
} ,
//============================================================================
2013-08-30 17:56:53 +02:00
/ *
wrongAppVersion : function ( anError ) {
// this.pages()['errorPage'].setProps({message:anError.message});
// this.moveInPage('errorPage', this.currentPage());
} ,
* /
//=========================================================================
_ _syntaxFix _ _ : "syntax fix"
} ) ;