2014-03-25 11:35:04 -03:00
'use strict' ;
2014-09-16 17:30:30 -03:00
angular . module ( 'copayApp.controllers' ) . controller ( 'SidebarController' , function ( $scope , $rootScope , $sce , $location , $http , $filter , notification , controllerUtils ) {
2014-08-12 15:26:15 -04:00
$scope . menu = [ {
'title' : 'Receive' ,
2014-09-02 12:30:31 -03:00
'icon' : 'fi-download' ,
2014-08-12 15:26:15 -04:00
'link' : 'receive'
} , {
'title' : 'Send' ,
'icon' : 'fi-arrow-right' ,
'link' : 'send'
} , {
'title' : 'History' ,
'icon' : 'fi-clipboard-pencil' ,
'link' : 'history'
} , {
2014-09-02 12:52:52 -03:00
'title' : 'Settings' ,
'icon' : 'fi-widget' ,
2014-08-21 11:08:20 -04:00
'link' : 'more'
2014-08-12 15:26:15 -04:00
} ] ;
$scope . signout = function ( ) {
logout ( ) ;
} ;
// Ensures a graceful disconnect
window . onbeforeunload = function ( ) {
controllerUtils . logout ( ) ;
} ;
$scope . $on ( '$destroy' , function ( ) {
window . onbeforeunload = undefined ;
} ) ;
2014-07-18 15:23:01 -03:00
2014-05-15 13:04:26 -07:00
2014-08-12 15:26:15 -04:00
$scope . refresh = function ( ) {
var w = $rootScope . wallet ;
2014-08-28 16:37:34 -03:00
w . sendWalletReady ( ) ;
2014-08-12 15:26:15 -04:00
if ( $rootScope . addrInfos . length > 0 ) {
controllerUtils . updateBalance ( function ( ) {
$rootScope . $digest ( ) ;
} ) ;
2014-07-16 19:00:34 -03:00
}
2014-08-12 15:26:15 -04:00
} ;
2014-07-16 19:00:34 -03:00
2014-08-12 15:26:15 -04:00
$scope . isActive = function ( item ) {
return item . link && item . link == $location . path ( ) . split ( '/' ) [ 1 ] ;
} ;
2014-07-08 15:26:20 -03:00
2014-08-12 15:26:15 -04:00
function logout ( ) {
2014-08-28 18:58:43 -03:00
controllerUtils . logout ( ) ;
2014-08-12 15:26:15 -04:00
}
2014-07-30 20:12:22 -03:00
2014-08-12 15:26:15 -04:00
// ng-repeat defined number of times instead of repeating over array?
$scope . getNumber = function ( num ) {
return new Array ( num ) ;
}
2014-08-07 18:57:19 -03:00
2014-08-12 15:26:15 -04:00
if ( $rootScope . wallet ) {
2014-08-15 12:43:43 -04:00
$scope . $on ( '$idleWarn' , function ( a , countdown ) {
if ( ! ( countdown % 5 ) )
2014-09-16 17:30:30 -03:00
notification . warning ( 'Session will be closed' , $filter ( 'translate' ) ( 'Your session is about to expire due to inactivity in' ) + ' ' + countdown + ' ' + $filter ( 'translate' ) ( 'seconds' ) ) ;
2014-08-12 15:26:15 -04:00
} ) ;
$scope . $on ( '$idleTimeout' , function ( ) {
$scope . signout ( ) ;
notification . warning ( 'Session closed' , 'Session closed because a long time of inactivity' ) ;
} ) ;
2014-08-15 12:43:43 -04:00
$scope . $on ( '$keepalive' , function ( ) {
$rootScope . wallet . keepAlive ( ) ;
} ) ;
2014-08-12 15:26:15 -04:00
}
} ) ;