Wallet/js/controllers/sidebar.js

121 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-03-25 11:35:04 -03:00
'use strict';
angular.module('copayApp.controllers').controller('SidebarController', function($scope, $rootScope, $location, $timeout, identityService, isMobile, isCordova, go) {
2014-12-04 20:43:27 -03:00
$scope.isMobile = isMobile.any();
$scope.isCordova = isCordova;
2015-02-04 12:30:12 -03:00
$scope.username = $rootScope.iden ? $rootScope.iden.getName() : '';
2014-08-12 15:26:15 -04:00
$scope.menu = [{
2014-10-31 11:49:52 -03:00
'title': 'Home',
2014-11-28 16:27:21 -03:00
'icon': 'icon-home',
2014-10-31 11:49:52 -03:00
'link': 'homeWallet'
}, {
2014-08-12 15:26:15 -04:00
'title': 'Receive',
2014-11-28 16:27:21 -03:00
'icon': 'icon-receive',
2014-08-12 15:26:15 -04:00
'link': 'receive'
}, {
'title': 'Send',
2014-11-28 16:27:21 -03:00
'icon': 'icon-paperplane',
2014-08-12 15:26:15 -04:00
'link': 'send'
}, {
'title': 'History',
2014-11-28 16:27:21 -03:00
'icon': 'icon-history',
2014-08-12 15:26:15 -04:00
'link': 'history'
}];
2014-10-28 12:37:15 -03:00
$scope.signout = function() {
2014-12-02 23:30:44 -03:00
identityService.signout();
2014-10-28 12:37:15 -03:00
};
2014-08-12 15:26:15 -04:00
$scope.isActive = function(item) {
return item.link && item.link == $location.path().split('/')[1];
};
2014-07-08 15:26:20 -03:00
$scope.switchWallet = function(wid) {
2014-11-30 01:02:18 -03:00
$scope.walletSelection = false;
2014-11-29 18:35:48 -03:00
identityService.setFocusedWallet(wid);
go.walletHome();
};
2014-10-20 10:29:43 -03:00
$scope.toggleWalletSelection = function() {
$scope.walletSelection = !$scope.walletSelection;
if (!$scope.walletSelection) return;
2014-11-29 18:35:48 -03:00
$scope.setWallets();
};
$scope.openScanner = function() {
window.ignoreMobilePause = true;
cordova.plugins.barcodeScanner.scan(
function onSuccess(result) {
$timeout(function() {
window.ignoreMobilePause = false;
}, 100);
if (result.cancelled) return;
$timeout(function() {
var data = result.text;
$scope.$apply(function() {
$rootScope.$emit('dataScanned', data);
});
}, 1000);
},
function onError(error) {
$timeout(function() {
window.ignoreMobilePause = false;
}, 100);
alert('Scanning error');
}
);
go.send();
};
2014-11-29 18:35:48 -03:00
$scope.init = function() {
2014-11-30 11:08:51 -03:00
// This should be called only once.
2014-12-03 00:30:44 -03:00
2014-11-30 11:08:51 -03:00
// focused wallet change
2014-11-29 18:35:48 -03:00
if ($rootScope.wallet) {
$rootScope.$watch('wallet', function() {
$scope.walletSelection = false;
$scope.setWallets();
});
}
2014-12-04 17:50:04 -03:00
// wallet list change
2014-11-30 00:44:25 -03:00
if ($rootScope.iden) {
var iden = $rootScope.iden;
iden.on('newWallet', function() {
$scope.walletSelection = false;
$scope.setWallets();
});
2014-12-02 16:53:24 -03: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-03 00:30:44 -03:00
copay.logger.debug('No wallets');
2014-12-02 16:53:24 -03:00
identityService.noFocusedWallet(newWid);
}
}
2014-11-30 00:44:25 -03:00
$scope.walletSelection = false;
$scope.setWallets();
});
}
};
2014-11-29 18:35:48 -03:00
$scope.setWallets = function() {
if (!$rootScope.iden) return;
2014-12-18 00:38:00 -03:00
var ret = _.filter($rootScope.iden.getWallets(), function(w) {
2014-12-04 20:43:27 -03:00
return w;
2014-10-20 10:29:43 -03:00
});
2014-12-04 20:43:27 -03:00
$scope.wallets = _.sortBy(ret, 'name');
};
$scope.openMenu = function() {
go.swipe(true);
};
2014-08-12 15:26:15 -04:00
});