2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-03 13:42:36 -07:00
|
|
|
angular.module('copayApp.controllers').controller('BackupController',
|
2014-06-03 12:13:56 -07:00
|
|
|
function($scope, $rootScope, $location, $window, $timeout, $modal) {
|
2014-03-26 05:18:42 -07:00
|
|
|
$scope.title = 'Backup';
|
2014-04-17 14:02:20 -07:00
|
|
|
|
|
|
|
var _getEncryptedWallet = function() {
|
2014-05-01 14:33:36 -07:00
|
|
|
var wallet = $rootScope.wallet.toEncryptedObj();
|
2014-04-17 14:02:20 -07:00
|
|
|
return wallet;
|
|
|
|
};
|
|
|
|
|
2014-05-09 05:52:02 -07:00
|
|
|
$scope.download = function() {
|
|
|
|
var timestamp = +(new Date);
|
|
|
|
var walletName = ($rootScope.wallet.name ? $rootScope.wallet.name : '') + '-' + $rootScope.wallet.id ;
|
|
|
|
var filename = walletName + '-' + timestamp + '.json.aes';
|
2014-04-17 14:02:20 -07:00
|
|
|
var wallet = _getEncryptedWallet();
|
|
|
|
var blob = new Blob([wallet], {type: 'text/plain;charset=utf-8'});
|
2014-06-03 09:55:40 -07:00
|
|
|
// show a native save dialog if we are in the shell
|
|
|
|
// and pass the wallet to the shell to convert to node Buffer
|
|
|
|
if (window.cshell) {
|
|
|
|
return window.cshell.send('backup:download', {
|
|
|
|
name: walletName,
|
|
|
|
wallet: wallet
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// otherwise lean on the browser implementation
|
2014-04-17 14:02:20 -07:00
|
|
|
saveAs(blob, filename);
|
|
|
|
};
|
|
|
|
|
2014-06-03 12:13:56 -07:00
|
|
|
$scope.openModal = function () {
|
|
|
|
var modalInstance = $modal.open({
|
|
|
|
templateUrl: 'backupModal.html',
|
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
modalInstance.result.then(sendEmail);
|
|
|
|
};
|
|
|
|
|
|
|
|
var sendEmail = function(email) {
|
|
|
|
var body = _getEncryptedWallet();
|
|
|
|
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
|
|
|
|
var href = 'mailto:' + email + '?'
|
|
|
|
+ 'subject=[Copay Backup] ' + subject + '&'
|
|
|
|
+ 'body=' + body;
|
|
|
|
|
2014-06-03 13:51:44 -07:00
|
|
|
if (window.cshell) {
|
|
|
|
return window.cshell.send('backup:email', href);
|
|
|
|
}
|
|
|
|
|
2014-06-03 12:13:56 -07:00
|
|
|
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
|
|
|
|
|
|
|
if (newWin) {
|
|
|
|
$timeout(function() {
|
|
|
|
newWin.close();
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
var ModalInstanceCtrl = function ($scope, $modalInstance) {
|
|
|
|
|
|
|
|
$scope.submit = function (form) {
|
|
|
|
$modalInstance.close($scope.email);
|
|
|
|
};
|
2014-06-03 09:55:40 -07:00
|
|
|
|
2014-06-03 12:13:56 -07:00
|
|
|
$scope.cancel = function () {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
};
|