copay/js/controllers/sidebar.js

97 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-03-25 07:35:04 -07:00
'use strict';
angular.module('copayApp.controllers').controller('SidebarController',
2014-07-31 18:49:11 -07:00
function($scope, $rootScope, $sce, $location, $http, notification, controllerUtils) {
$scope.version = copay.version;
$scope.networkName = config.networkName;
$scope.menu = [{
'title': 'Addresses',
'icon': 'fi-address-book',
'link': 'addresses'
2014-03-26 05:18:42 -07:00
}, {
'title': 'Transactions',
2014-06-23 06:34:40 -07:00
'icon': 'fi-clipboard-pencil',
'link': 'transactions'
2014-03-26 05:18:42 -07:00
}, {
'title': 'Send',
2014-04-15 08:33:00 -07:00
'icon': 'fi-arrow-right',
'link': 'send'
2014-03-26 05:18:42 -07:00
}, {
2014-07-21 12:25:47 -07:00
'title': 'More',
2014-07-08 06:48:56 -07:00
'icon': 'fi-download',
'link': 'backup'
2014-04-15 10:02:45 -07:00
}];
2014-03-25 07:35:04 -07:00
$scope.signout = function() {
2014-05-15 13:04:26 -07:00
logout();
2014-04-30 15:50:13 -07:00
};
// Ensures a graceful disconnect
window.onbeforeunload = logout;
$scope.$on('$destroy', function() {
window.onbeforeunload = undefined;
});
2014-04-30 15:50:13 -07:00
$scope.refresh = function() {
2014-05-06 12:21:56 -07:00
var w = $rootScope.wallet;
w.connectToAll();
if ($rootScope.addrInfos.length > 0) {
controllerUtils.updateBalance(function() {
$rootScope.$digest();
});
}
2014-03-25 07:35:04 -07:00
};
2014-04-09 07:05:25 -07:00
2014-07-18 11:23:01 -07:00
$scope.isActive = function(item) {
return item.link && item.link == $location.path().split('/')[1];
};
2014-05-15 13:04:26 -07:00
function logout() {
var w = $rootScope.wallet;
if (w) {
w.disconnect();
controllerUtils.logout();
}
}
2014-07-16 15:00:34 -07:00
// ng-repeat defined number of times instead of repeating over array?
$scope.getNumber = function(num) {
return new Array(num);
}
$http.get('https://api.github.com/repos/bitpay/copay/tags').success(function(data) {
var toInt = function(s) {
return parseInt(s);
};
var latestVersion = data[0].name.replace('v', '').split('.').map(toInt);
var currentVersion = copay.version.split('.').map(toInt);
var title = 'Copay ' + data[0].name + ' available.';
var content;
if (currentVersion[0] < latestVersion[0]) {
content = 'It\'s important that you update your wallet at https://copay.io';
notification.version(title, content, true);
} else if (currentVersion[0] == latestVersion[0] && currentVersion[1] < latestVersion[1]) {
var content = 'Please update your wallet at https://copay.io';
notification.version(title, content, false);
2014-07-08 11:26:20 -07:00
}
});
2014-07-08 11:26:20 -07:00
// Init socket handlers (with no wallet yet)
controllerUtils.setSocketHandlers();
2014-07-08 11:26:20 -07:00
if ($rootScope.wallet) {
$scope.$on('$idleStart', function(a) {
2014-08-01 06:51:26 -07:00
notification.warning('Session will be closed', 'Your session is about to expire due to inactivity');
});
$scope.$on('$idleTimeout', function() {
$scope.signout();
2014-08-01 06:44:33 -07:00
notification.warning('Session closed', 'Session closed because a long time of inactivity');
});
}
2014-03-25 07:35:04 -07:00
});