merged email modal and wired up copay shell integration for it

This commit is contained in:
Gordon Hall 2014-06-03 16:51:44 -04:00
commit 47f9ade884
3 changed files with 56 additions and 29 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copay.backup').controller('BackupController',
function($scope, $rootScope, $location, $window, $timeout) {
function($scope, $rootScope, $location, $window, $timeout, $modal) {
$scope.title = 'Backup';
var _getEncryptedWallet = function() {
@ -27,29 +27,43 @@ angular.module('copay.backup').controller('BackupController',
saveAs(blob, filename);
};
$scope.email = function() {
var email = prompt('Please enter your email addres.');
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
$scope.openModal = function () {
var modalInstance = $modal.open({
templateUrl: 'backupModal.html',
controller: ModalInstanceCtrl,
});
if (email && email !== '') {
if (!email.match(mailformat)) {
alert('Enter a valid email address');
} else {
var body = _getEncryptedWallet();
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
var href = 'mailto:' + email + '?'
+ 'subject=[Copay Backup] ' + subject + '&'
+ 'body=' + body;
modalInstance.result.then(sendEmail);
};
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
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;
if (newWin) {
$timeout(function() {
newWin.close();
}, 1000);
}
}
}
};
if (window.cshell) {
return window.cshell.send('backup:email', href);
}
});
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);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};