copay/js/controllers/sidebar.js

104 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-03-25 07:35:04 -07:00
'use strict';
angular.module('copayApp.controllers').controller('SidebarController', function($scope, $rootScope, $sce, $location, $http, $filter, notification, controllerUtils) {
2014-08-12 12:26:15 -07:00
$scope.menu = [{
'title': 'Receive',
'icon': 'fi-download',
2014-08-12 12:26:15 -07:00
'link': 'receive'
}, {
'title': 'Send',
'icon': 'fi-arrow-right',
'link': 'send'
}, {
'title': 'History',
'icon': 'fi-clipboard-pencil',
'link': 'history'
}, {
'title': 'Settings',
'icon': 'fi-widget',
2014-08-21 08:08:20 -07:00
'link': 'more'
2014-08-12 12:26:15 -07:00
}];
$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;
2014-10-10 13:58:19 -07:00
if (w.isReady()) {
w.sendWalletReady();
if ($rootScope.addrInfos.length > 0) {
2014-10-16 12:02:32 -07:00
controllerUtils.clearBalanceCache(w);
controllerUtils.updateBalance(w, function() {
2014-10-10 13:58:19 -07:00
$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() {
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
if ($rootScope.wallet) {
$scope.$on('$idleWarn', function(a, countdown) {
if (!(countdown % 5))
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 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
}
$scope.switchWallet = function(wid) {
$scope.walletSelection = false;
controllerUtils.setFocusedWallet(wid);
};
2014-10-20 06:29:43 -07:00
$scope.toggleWalletSelection = function() {
$scope.walletSelection = !$scope.walletSelection;
if (!$scope.walletSelection) return;
2014-10-20 06:29:43 -07:00
$scope.wallets = [];
var wids = _.pluck($rootScope.iden.listWallets(), 'id');
_.each(wids, function(wid) {
if (controllerUtils.isFocusedWallet(wid)) return;
var w = $rootScope.iden.getOpenWallet(wid);
$scope.wallets.push(w);
controllerUtils.updateBalance(w, function(err, res) {
if (err) return;
setTimeout(function() {
$scope.$digest();
}, 1);
2014-10-20 06:29:43 -07:00
});
});
};
2014-08-12 12:26:15 -07:00
});