copay/js/controllers/head.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-10-27 12:13:06 -07:00
'use strict';
angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, notification, controllerUtils) {
$scope.username = $rootScope.iden.getName();
2014-10-27 12:13:06 -07:00
$scope.hoverMenu = false;
$scope.hoverIn = function() {
2014-10-27 12:13:06 -07:00
this.hoverMenu = true;
};
$scope.hoverOut = function() {
2014-10-27 12:13:06 -07:00
this.hoverMenu = false;
};
$scope.signout = function() {
2014-10-29 19:23:16 -07:00
controllerUtils.logout();
2014-10-27 12:13:06 -07:00
};
2014-10-31 08:14:47 -07:00
$scope.refresh = function() {
var w = $rootScope.wallet;
if (!w) return;
if (w.isReady()) {
w.sendWalletReady();
if ($rootScope.addrInfos.length > 0) {
controllerUtils.clearBalanceCache(w);
controllerUtils.updateBalance(w, function() {
$rootScope.$digest();
});
}
}
};
2014-10-27 12:13:06 -07:00
// Ensures a graceful disconnect
window.onbeforeunload = function() {
controllerUtils.logout();
};
$scope.$on('$destroy', function() {
window.onbeforeunload = undefined;
});
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'));
});
$scope.$on('$idleTimeout', function() {
$scope.signout();
notification.warning('Session closed', 'Session closed because a long time of inactivity');
});
$scope.$on('$keepalive', function() {
if ($rootScope.wallet) {
$rootScope.wallet.keepAlive();
}
});
$rootScope.$watch('title', function(newTitle, oldTitle) {
$scope.title = newTitle;
});
2014-10-28 08:37:15 -07:00
$rootScope.$on('signout', function() {
2014-10-29 19:23:16 -07:00
controllerUtils.logout();
2014-10-28 08:37:15 -07:00
});
2014-10-27 12:13:06 -07:00
}
});