copay/js/controllers/head.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-10-27 12:13:06 -07:00
'use strict';
2014-12-03 07:40:13 -08:00
angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService) {
$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() {
$rootScope.signingOut = true;
2014-11-29 19:31:17 -08:00
identityService.signout();
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;
2014-11-29 19:31:17 -08:00
if (w.isComplete()) {
2014-10-31 08:14:47 -07:00
w.sendWalletReady();
2014-11-29 13:35:48 -08:00
balanceService.clearBalanceCache(w);
balanceService.update(w, function() {
$rootScope.$digest();
}, true);
2014-10-31 08:14:47 -07:00
}
};
2014-10-27 12:13:06 -07:00
2014-12-01 06:19:18 -08:00
//mpando restore after solve some chrome app error
2014-10-27 12:13:06 -07:00
// Ensures a graceful disconnect
2014-12-01 06:19:18 -08:00
// window.onbeforeunload = function() {
// $scope.signout();
// };
2014-10-27 12:13:06 -07:00
2014-12-01 06:19:18 -08:00
// $scope.$on('$destroy', function() {
// window.onbeforeunload = undefined;
// });
2014-10-27 12:13:06 -07:00
2014-12-03 07:40:13 -08:00
$scope.init = function() {
if (!$rootScope.wallet) return;
2014-12-02 19:36:44 -08:00
2014-12-03 07:40:13 -08:00
$scope.$on('$idleStart', function() {});
2014-10-27 12:13:06 -07:00
$scope.$on('$idleWarn', function(a, countdown) {
$rootScope.countdown = countdown;
$rootScope.sessionExpired = true;
});
$scope.$on('$idleEnd', function() {
$timeout(function() {
$rootScope.sessionExpired = null;
}, 500);
2014-10-27 12:13:06 -07:00
});
$scope.$on('$idleTimeout', function() {
$rootScope.sessionExpired = null;
2014-10-27 12:13:06 -07:00
$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-12-03 07:40:13 -08:00
};
2014-10-27 12:13:06 -07:00
});