copay/js/controllers/profile.js

90 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
2014-12-01 12:21:39 -08:00
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, backupService, identityService) {
2014-11-12 19:07:33 -08:00
$scope.username = $rootScope.iden.getName();
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
$rootScope.title = 'Profile';
2014-12-01 07:13:11 -08:00
$scope.hideAdv = true;
2014-10-27 12:13:06 -07:00
$scope.downloadProfileBackup = function() {
backupService.profileDownload($rootScope.iden);
};
$scope.viewProfileBackup = function() {
$scope.backupProfilePlainText = backupService.profileEncrypted($rootScope.iden);
$scope.hideViewProfileBackup = true;
};
2014-11-26 07:08:26 -08:00
2014-11-10 11:41:07 -08:00
$scope.deleteWallet = function(w) {
if (!w) return;
2014-11-30 18:08:16 -08:00
identityService.deleteWallet(w, function(err) {
2014-11-10 11:41:07 -08:00
$scope.loading = false;
2014-11-30 18:08:16 -08:00
if (err) {
2014-12-01 10:33:16 -08:00
copay.logger.warn(err);
2014-11-30 18:08:16 -08:00
}
2014-12-01 10:33:16 -08:00
$scope.setWallets();
2014-11-10 11:41:07 -08:00
});
};
2014-12-01 12:21:39 -08:00
$scope.init = function() {
if ($rootScope.quotaPerItem) {
2014-11-26 07:08:26 -08:00
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1);
$scope.nrWallets = parseInt($rootScope.quotaItems) - 1;
2014-12-01 12:21:39 -08:00
}
};
2014-11-29 23:03:23 -08:00
$scope.setWallets = function() {
if (!$rootScope.iden) return;
2014-12-01 12:21:39 -08:00
var wallets = $rootScope.iden.listWallets();
2014-11-26 07:08:26 -08:00
var max = $rootScope.quotaPerItem;
2014-12-01 12:21:39 -08:00
_.each(wallets, function(w) {
var bits = w.sizes().total;
2014-11-26 07:08:26 -08:00
w.kb = $filter('noFractionNumber')(bits / 1000, 1);
2014-12-01 12:21:39 -08:00
if (max) {
2014-11-26 07:08:26 -08:00
w.usage = $filter('noFractionNumber')(bits / max * 100, 0);
2014-12-01 12:21:39 -08:00
}
});
$scope.wallets = wallets;
};
2014-11-29 23:03:23 -08:00
$scope.downloadWalletBackup = function(w) {
if (!w) return;
backupService.walletDownload(w);
}
$scope.viewWalletBackup = function(w) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
if (!w) return;
$scope.backupWalletPlainText = backupService.walletEncrypted(w);
$scope.hideViewWalletBackup = true;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
$modal.open({
templateUrl: 'views/modals/backup-text.html',
windowClass: 'tiny',
controller: ModalInstanceCtrl
});
};
2014-11-26 07:08:26 -08:00
$scope.deleteProfile = function() {
identityService.deleteProfile(function(err, res) {
2014-12-01 09:44:36 -08:00
if (err) {
log.warn(err);
notification.error('Error', 'Could not delete profile');
return;
}
2014-11-26 07:08:26 -08:00
$location.path('/');
setTimeout(function() {
2014-12-01 09:44:36 -08:00
notification.error('Success', 'Profile successfully deleted');
}, 1);
});
2014-12-01 07:13:11 -08:00
};
});