mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
import via textarea
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
angular
|
||||
.module('bit.tools')
|
||||
|
||||
.controller('toolsImportController', function ($scope, $state, apiService, $uibModalInstance, cryptoService, cipherService, toastr, importService, $analytics, $sce) {
|
||||
.controller('toolsImportController', function ($scope, $state, apiService, $uibModalInstance, cryptoService, cipherService,
|
||||
toastr, importService, $analytics, $sce, validationService) {
|
||||
$analytics.eventTrack('toolsImportController', { category: 'Modal' });
|
||||
$scope.model = { source: 'bitwardencsv' };
|
||||
$scope.model = { source: '' };
|
||||
$scope.source = {};
|
||||
|
||||
$scope.options = [
|
||||
@@ -202,10 +203,20 @@
|
||||
};
|
||||
$scope.setSource();
|
||||
|
||||
$scope.import = function (model) {
|
||||
$scope.processing = true;
|
||||
$scope.import = function (model, form) {
|
||||
if (!model.source || model.source === '') {
|
||||
validationService.addError(form, 'source', 'Select the format of the import file.', true);
|
||||
return;
|
||||
}
|
||||
|
||||
var file = document.getElementById('file').files[0];
|
||||
importService.import(model.source, file, importSuccess, importError);
|
||||
if (!file && (!model.fileContents || model.fileContents === '')) {
|
||||
validationService.addError(form, 'file', 'Select the import file or copy/paste the import file contents.', true);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.processing = true;
|
||||
importService.import(model.source, file || model.fileContents, importSuccess, importError);
|
||||
};
|
||||
|
||||
function importSuccess(folders, logins, folderRelationships) {
|
||||
|
||||
@@ -2,21 +2,33 @@
|
||||
<button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="importModelLabel"><i class="fa fa-cloud-upload"></i> Import</h4>
|
||||
</div>
|
||||
<form name="importForm" ng-submit="importForm.$valid && import(model)" ng-show="!processing">
|
||||
<form name="importForm" ng-submit="importForm.$valid && import(model, importForm)" ng-show="!processing">
|
||||
<div class="modal-body">
|
||||
<div class="callout callout-danger validation-errors" ng-show="importForm.$errors">
|
||||
<h4>Errors have occured</h4>
|
||||
<ul>
|
||||
<li ng-repeat="e in importForm.$errors">{{e}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="source">1. Select the source of this import file</label>
|
||||
<select id="source" name="source" class="form-control" ng-model="model.source" ng-change="setSource()">
|
||||
<label for="source">1. Select the format of the import file</label>
|
||||
<select id="source" name="source" class="form-control" ng-model="model.source" ng-change="setSource()" required>
|
||||
<option value="">-- Select --</option>
|
||||
<option ng-repeat="option in options" value="{{option.id}}">{{option.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="callout callout-default">
|
||||
<div class="callout callout-default" ng-show="model.source">
|
||||
<h4><i class="fa fa-info-circle"></i> {{source.name}} Instructions</h4>
|
||||
<div ng-bind-html="source.instructions"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="file">2. Select the import file</label>
|
||||
<input type="file" id="file" name="file" required />
|
||||
<input type="file" id="file" name="file" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="fileContents">or copy/paste the import file contents</label>
|
||||
<textarea id="fileContents" class="form-control" name="fileContents" ng-model="model.fileContents"
|
||||
style="height: 150px;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
Reference in New Issue
Block a user