Merge pull request #538 from yemel/feature/backup-modal-input

Add modal to email backup
This commit is contained in:
Manuel Aráoz 2014-06-03 17:30:30 -03:00
commit 77e7d8d46d
2 changed files with 48 additions and 28 deletions

View file

@ -669,7 +669,7 @@
</a> </a>
</div> </div>
<div class="large-6 medium-6 columns"> <div class="large-6 medium-6 columns">
<a class="panel radius box-backup" ng-click="email()"> <a class="panel radius box-backup" ng-click="openModal()">
<i class="fi-mail size-72"></i> <i class="fi-mail size-72"></i>
<p> Backup to email </p> <p> Backup to email </p>
</a> </a>
@ -678,6 +678,15 @@
</div> </div>
</script> </script>
<script type="text/ng-template" id="backupModal.html">
<h3>Insert your email</h3>
<form name="emailForm" ng-submit="submit(emailForm)">
<p><input type="email" ng-model="$parent.email" placeholder="your@email.com" required/></p>
<input type="submit" class="button" value="Send" ng-disabled="emailForm.$invalid"/>
</form>
<a class="close-reveal-modal" ng-click="cancel()">&#215;</a>
</script>
<!-- CONFIG --> <!-- CONFIG -->
<script type="text/ng-template" id="settings.html"> <script type="text/ng-template" id="settings.html">
<div class="settings" ng-controller="SettingsController"> <div class="settings" ng-controller="SettingsController">

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copay.backup').controller('BackupController', angular.module('copay.backup').controller('BackupController',
function($scope, $rootScope, $location, $window, $timeout) { function($scope, $rootScope, $location, $window, $timeout, $modal) {
$scope.title = 'Backup'; $scope.title = 'Backup';
var _getEncryptedWallet = function() { var _getEncryptedWallet = function() {
@ -18,14 +18,17 @@ angular.module('copay.backup').controller('BackupController',
saveAs(blob, filename); saveAs(blob, filename);
}; };
$scope.email = function() {
var email = prompt('Please enter your email addres.');
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (email && email !== '') { $scope.openModal = function () {
if (!email.match(mailformat)) { var modalInstance = $modal.open({
alert('Enter a valid email address'); templateUrl: 'backupModal.html',
} else { controller: ModalInstanceCtrl,
});
modalInstance.result.then(sendEmail);
};
var sendEmail = function(email) {
var body = _getEncryptedWallet(); var body = _getEncryptedWallet();
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id; var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
var href = 'mailto:' + email + '?' var href = 'mailto:' + email + '?'
@ -39,8 +42,16 @@ angular.module('copay.backup').controller('BackupController',
newWin.close(); newWin.close();
}, 1000); }, 1000);
} }
} };
} });
var ModalInstanceCtrl = function ($scope, $modalInstance) {
$scope.submit = function (form) {
$modalInstance.close($scope.email);
}; };
}); $scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};