2014-03-25 11:35:04 -03:00
'use strict' ;
2014-03-28 14:08:14 -04:00
angular . module ( 'copay.header' ) . controller ( 'HeaderController' ,
2014-05-15 02:13:25 -03:00
function ( $scope , $rootScope , $location , $notification , walletFactory , controllerUtils ) {
2014-04-29 19:26:12 -03:00
$scope . menu = [
{
2014-04-20 20:21:54 -03:00
'title' : 'Addresses' ,
'icon' : 'fi-address-book' ,
'link' : '#/addresses'
2014-03-26 09:18:42 -03:00
} , {
'title' : 'Transactions' ,
2014-04-15 12:33:00 -03:00
'icon' : 'fi-loop' ,
2014-03-26 09:18:42 -03:00
'link' : '#/transactions'
} , {
'title' : 'Send' ,
2014-04-15 12:33:00 -03:00
'icon' : 'fi-arrow-right' ,
2014-03-26 09:18:42 -03:00
'link' : '#/send'
} , {
'title' : 'Backup' ,
2014-04-15 12:33:00 -03:00
'icon' : 'fi-archive' ,
2014-03-26 09:18:42 -03:00
'link' : '#/backup'
2014-04-15 14:02:45 -03:00
} ] ;
2014-03-25 11:35:04 -03:00
2014-04-18 19:08:01 -03:00
$rootScope . $watch ( 'wallet' , function ( wallet ) {
if ( wallet ) {
2014-05-13 04:03:09 -03:00
controllerUtils . updateTxs ( ) ;
2014-04-18 19:08:01 -03:00
}
} ) ;
2014-05-15 02:13:25 -03:00
// Initialize alert notification (not show when init wallet)
2014-05-15 10:41:42 -03:00
$rootScope . txAlertCount = 0 ;
2014-05-15 02:13:25 -03:00
$notification . enableHtml5Mode ( ) ; // for chrome: if support, enable it
2014-05-15 10:41:42 -03:00
$rootScope . $watch ( 'txAlertCount' , function ( txAlertCount ) {
if ( txAlertCount && txAlertCount > 0 ) {
$notification . info ( 'New Transaction' , ( $rootScope . txAlertCount == 1 ) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope . txAlertCount + ' pending transaction proposals' , txAlertCount ) ;
2014-05-15 02:13:25 -03:00
}
} ) ;
2014-03-26 09:18:42 -03:00
$scope . isActive = function ( item ) {
2014-04-15 14:02:45 -03:00
if ( item . link && item . link . replace ( '#' , '' ) == $location . path ( ) ) {
2014-03-26 09:18:42 -03:00
return true ;
}
return false ;
} ;
2014-03-25 11:35:04 -03:00
$scope . signout = function ( ) {
2014-05-15 13:04:26 -07:00
logout ( ) ;
2014-04-30 19:50:13 -03:00
$scope . clearFlashMessage ( ) ;
} ;
$scope . refresh = function ( ) {
2014-05-06 16:21:56 -03:00
var w = $rootScope . wallet ;
2014-05-06 17:36:16 -03:00
w . connectToAll ( ) ;
2014-04-30 19:50:13 -03:00
controllerUtils . updateBalance ( function ( ) {
} ) ;
2014-03-25 11:35:04 -03:00
} ;
2014-04-09 11:05:25 -03:00
$scope . clearFlashMessage = function ( ) {
$rootScope . flashMessage = { } ;
} ;
2014-04-17 06:43:30 -03:00
2014-04-20 19:39:16 -03:00
$rootScope . isCollapsed = true ;
2014-05-15 13:04:26 -07:00
function logout ( ) {
var w = $rootScope . wallet ;
if ( w ) {
w . disconnect ( ) ;
controllerUtils . logout ( ) ;
}
}
// Ensures a graceful disconnect
window . onbeforeunload = logout ;
$scope . $on ( '$destroy' , function ( ) {
window . onbeforeunload = undefined ;
} ) ;
2014-03-25 11:35:04 -03:00
} ) ;