copay/js/controllers/sidebar.js

94 lines
2.3 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, $location, $timeout, identityService, isMobile, go) {
2014-12-04 15:43:27 -08:00
$scope.isMobile = isMobile.any()
2014-08-12 12:26:15 -07:00
$scope.menu = [{
2014-10-31 07:49:52 -07:00
'title': 'Home',
2014-11-28 11:27:21 -08:00
'icon': 'icon-home',
2014-10-31 07:49:52 -07:00
'link': 'homeWallet'
}, {
2014-08-12 12:26:15 -07:00
'title': 'Receive',
2014-11-28 11:27:21 -08:00
'icon': 'icon-receive',
2014-08-12 12:26:15 -07:00
'link': 'receive'
}, {
'title': 'Send',
2014-11-28 11:27:21 -08:00
'icon': 'icon-paperplane',
2014-08-12 12:26:15 -07:00
'link': 'send'
}, {
'title': 'History',
2014-11-28 11:27:21 -08:00
'icon': 'icon-history',
2014-08-12 12:26:15 -07:00
'link': 'history'
}, {
'title': 'Settings',
2014-11-28 11:27:21 -08:00
'icon': 'icon-gear',
2014-08-21 08:08:20 -07:00
'link': 'more'
2014-08-12 12:26:15 -07:00
}];
2014-10-28 08:37:15 -07:00
$scope.signout = function() {
2014-12-02 18:30:44 -08:00
identityService.signout();
2014-10-28 08:37:15 -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
$scope.switchWallet = function(wid) {
2014-11-29 20:02:18 -08:00
$scope.walletSelection = false;
2014-11-29 13:35:48 -08:00
identityService.setFocusedWallet(wid);
go.walletHome();
};
2014-10-20 06:29:43 -07:00
$scope.toggleWalletSelection = function() {
$scope.walletSelection = !$scope.walletSelection;
if (!$scope.walletSelection) return;
2014-11-29 13:35:48 -08:00
$scope.setWallets();
};
$scope.init = function() {
2014-11-30 06:08:51 -08:00
// This should be called only once.
2014-12-02 19:30:44 -08:00
2014-11-30 06:08:51 -08:00
// focused wallet change
2014-11-29 13:35:48 -08:00
if ($rootScope.wallet) {
$rootScope.$watch('wallet', function() {
$scope.walletSelection = false;
$scope.setWallets();
});
}
2014-12-04 12:50:04 -08:00
// wallet list change
2014-11-29 19:44:25 -08:00
if ($rootScope.iden) {
var iden = $rootScope.iden;
iden.on('newWallet', function() {
$scope.walletSelection = false;
$scope.setWallets();
});
2014-12-02 11:53:24 -08:00
iden.on('walletDeleted', function(wid) {
if (wid == $rootScope.wallet.id) {
copay.logger.debug('Deleted focused wallet:', wid);
// new focus
var newWid = $rootScope.iden.getLastFocusedWalletId();
if (newWid && $rootScope.iden.getWalletById(newWid)) {
identityService.setFocusedWallet(newWid);
} else {
2014-12-02 19:30:44 -08:00
copay.logger.debug('No wallets');
2014-12-02 11:53:24 -08:00
identityService.noFocusedWallet(newWid);
}
}
2014-11-29 19:44:25 -08:00
$scope.walletSelection = false;
$scope.setWallets();
});
}
};
2014-11-29 13:35:48 -08:00
$scope.setWallets = function() {
if (!$rootScope.iden) return;
2014-11-29 13:35:48 -08:00
var ret = _.filter($rootScope.iden.listWallets(), function(w) {
2014-12-04 15:43:27 -08:00
return w;
2014-10-20 06:29:43 -07:00
});
2014-12-04 15:43:27 -08:00
$scope.wallets = _.sortBy(ret, 'name');
};
2014-08-12 12:26:15 -07:00
});