Merge pull request #277 from cmgustavo/feature/backup-form

Feature/backup form
This commit is contained in:
Mario Colque 2014-05-06 17:55:04 -03:00
commit ad836250f5
3 changed files with 45 additions and 16 deletions

View File

@ -182,7 +182,7 @@
<span ng-show="wallets.length">
<a href="#/setup">Create a new wallet</a> &middot;
</span>
<a ng-href="#import">Import from file</a>
<a ng-href="#import">Import a backup</a>
</div>
</div>
</div> <!-- End !loading -->
@ -191,14 +191,23 @@
<script type="text/ng-template" id="import.html">
<div ng-controller="ImportController">
<h3>{{title}}</h3>
<div class="large-6 columns">
<input type="password" class="form-control" placeholder="Your wallet password" ng-model="password" autofocus required>
<h6>Select a backup file</h6>
<input type="file" class="form-control" placeholder="Select a backup file" ng-model="backupFile" ng-file-select>
<h6>Or just paste the backup text here</h6>
<textarea class="form-control" ng-model="backupText"></textarea>
<button class="button primary expand radius" ng-click="import()">Import backup</button>
<div class="large-6 large-centered medium-6 medium-centered columns" ng-init="choosefile=0; pastetext=0">
<h2>{{title}}</h2>
<form name="importForm" ng-submit="import(importForm)" novalidate>
<fieldset>
<legend>Select which method want to use to restore</legend>
<label for="backupFile" ng-click="choosefile=!choosefile" class="m10b"><i class="fi-upload"></i> Choose backup file from your computer</label>
<input type="file" class="form-control" placeholder="Select a backup file" name="backupFile" ng-model="backupFile" ng-file-select ng-show="choosefile">
<label for="backupText" ng-click="pastetext=!pastetext" class="m10b"><i class="fi-paperclip"></i> Paste backup plain text code</label>
<textarea class="form-control" name="backupText" ng-model="backupText" rows="5" ng-show="pastetext"></textarea>
</fieldset>
<label for="password">Password <small>Required</small></label>
<input type="password" class="form-control" placeholder="Your wallet password" name="password" ng-model="password" required>
<button type="submit" class="button primary radius" ng-disabled="importForm.$invalid" loading="Importing">
Import backup
</button>
</form>
</div>
</div>
</script>

View File

@ -21,13 +21,31 @@ angular.module('copay.import').controller('ImportController',
};
};
$scope.import = function() {
if ($scope.password) {
if ($scope.backupText) {
_importBackup($scope.backupText);
} else {
reader.readAsBinaryString($scope.file);
}
$scope.import = function(form) {
if (form.$invalid) {
$rootScope.flashMessage = { message: 'There is an error in the form. Please, try again', type: 'error'};
return;
}
var backupFile = $scope.file;
var backupText = form.backupText.$modelValue;
var password = form.password.$modelValue;
if (!backupFile && !backupText) {
$rootScope.flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'};
return;
}
$scope.loading = true;
if (backupFile) {
reader.readAsBinaryString(backupFile);
}
else {
_importBackup(backupText);
}
$scope.loading = false;
};
});

View File

@ -65,6 +65,8 @@ WalletFactory.prototype.fromObj = function(obj) {
}
this.log('### WALLET OPENED:', w.id);
// store imported wallet
w.store();
return w;
};