copay/js/controllers/profile.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
2015-01-14 10:33:19 -08:00
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, $timeout, backupService, identityService, isMobile, isCordova, notification) {
2014-11-12 19:07:33 -08:00
$scope.username = $rootScope.iden.getName();
2014-12-09 07:48:03 -08:00
$scope.isSafari = isMobile.Safari();
$scope.isCordova = isCordova;
$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.loading = true;
$timeout(function() {
$scope.backupProfilePlainText = backupService.profileEncrypted($rootScope.iden);
}, 100);
2014-12-09 07:48:03 -08:00
};
$scope.copyProfileBackup = function() {
var ep = backupService.profileEncrypted($rootScope.iden);
window.cordova.plugins.clipboard.copy(ep);
window.plugins.toast.showShortCenter('Copied to clipboard');
};
$scope.sendProfileBackup = function() {
2015-02-03 11:27:11 -08:00
if (isMobile.Android() || isMobile.Windows()) {
2015-01-29 10:22:15 -08:00
window.ignoreMobilePause = true;
}
window.plugins.toast.showShortCenter('Preparing backup...');
var name = $rootScope.iden.fullName;
var ep = backupService.profileEncrypted($rootScope.iden);
var properties = {
subject: 'Copay Profile Backup: ' + name,
body: 'Here is the encrypted backup of the profile '
+ name + ': \n\n' + ep
+ '\n\n To import this backup, copy all text between {...}, including the symbols {}',
isHtml: false
};
window.plugin.email.open(properties);
};
2014-12-02 11:53:24 -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-12-02 11:53:24 -08:00
// no need to add event handlers here. Wallet deletion is handle by callback.
2014-12-01 12:21:39 -08:00
};
2014-11-26 07:08:26 -08:00
$scope.deleteProfile = function() {
2015-01-14 10:33:19 -08:00
$scope.loading = true;
2014-11-26 07:08:26 -08:00
identityService.deleteProfile(function(err, res) {
2015-01-14 10:33:19 -08:00
$scope.loading = false;
2014-12-01 09:44:36 -08:00
if (err) {
log.warn(err);
notification.error('Error', 'Could not delete profile');
2015-01-14 10:33:19 -08:00
$timeout(function () { $scope.$digest(); });
}
else {
$location.path('/');
$timeout(function() {
notification.success('Success', 'Profile successfully deleted');
});
2014-12-01 09:44:36 -08:00
}
});
2014-12-01 07:13:11 -08:00
};
});