copay/js/controllers/header.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-03-25 07:35:04 -07:00
'use strict';
angular.module('copay.header').controller('HeaderController',
2014-05-14 22:13:25 -07:00
function($scope, $rootScope, $location, $notification, walletFactory, controllerUtils) {
2014-04-29 15:26:12 -07:00
$scope.menu = [
{
'title': 'Addresses',
'icon': 'fi-address-book',
'link': '#/addresses'
2014-03-26 05:18:42 -07:00
}, {
'title': 'Transactions',
2014-04-15 08:33:00 -07:00
'icon': 'fi-loop',
2014-03-26 05:18:42 -07:00
'link': '#/transactions'
}, {
'title': 'Send',
2014-04-15 08:33:00 -07:00
'icon': 'fi-arrow-right',
2014-03-26 05:18:42 -07:00
'link': '#/send'
}, {
'title': 'Backup',
2014-04-15 08:33:00 -07:00
'icon': 'fi-archive',
2014-03-26 05:18:42 -07:00
'link': '#/backup'
2014-04-15 10:02:45 -07:00
}];
2014-05-21 06:35:47 -07:00
var beep = new Audio('sound/transaction.mp3');
2014-03-25 07:35:04 -07:00
2014-05-14 22:13:25 -07:00
// Initialize alert notification (not show when init wallet)
2014-05-15 06:41:42 -07:00
$rootScope.txAlertCount = 0;
$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-14 22:13:25 -07:00
}
});
$rootScope.$watch('receivedFund', function(receivedFund) {
if (receivedFund) {
var currentAddr;
for(var i=0;i<$rootScope.addrInfos.length;i++) {
var addrinfo = $rootScope.addrInfos[i];
if (addrinfo.address.toString() == receivedFund[1] && !addrinfo.isChange) {
currentAddr = addrinfo.address.toString();
break;
}
}
if (currentAddr) {
$notification.funds('Received fund', currentAddr, receivedFund);
2014-05-20 15:47:16 -07:00
beep.play();
}
}
});
2014-03-26 05:18:42 -07:00
$scope.isActive = function(item) {
2014-04-15 10:02:45 -07:00
if (item.link && item.link.replace('#','') == $location.path()) {
2014-03-26 05:18:42 -07:00
return true;
}
return false;
};
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
$scope.clearFlashMessage();
};
$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
$scope.clearFlashMessage = function() {
2014-05-20 08:30:20 -07:00
$rootScope.$flashMessage = {};
2014-04-09 07:05:25 -07:00
};
2014-04-20 15:39:16 -07: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 07:35:04 -07:00
});