copay/js/controllers/sidebar.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

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