passman/js/app/controllers/export.js
2016-10-08 14:00:07 +02:00

64 lines
No EOL
1.8 KiB
JavaScript

(function () {
'use strict';
/**
* @ngdoc function
* @name passmanApp.controller:ImportCtrl
* @description
* # ImportCtrl
* Controller of the passmanApp
*/
angular.module('passmanApp')
.controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', function ($scope, $window, CredentialService, VaultService) {
$scope.available_exporters = [];
$scope.active_vault = VaultService.getActiveVault();
$scope.$watch(function () {
return $window.PassmanExporter;
}, function (exporters) {
exporters = Object.keys(angular.copy(exporters));
for (var i = 0; i < exporters.length; i++) {
var exporter = exporters[i];
if ($window.PassmanExporter[exporter].hasOwnProperty('info')) {
$scope.available_exporters.push($window.PassmanExporter[exporter].info);
}
}
}, true);
$scope.log = [];
$scope.setExporter = function (exporter) {
exporter = JSON.parse(exporter);
$scope.selectedExporter = exporter;
};
var _log = function (str) {
$scope.log.push(str);
};
$scope.startExport = function () {
_log('Starting export');
var _credentials = [];
VaultService.getVault(VaultService.getActiveVault()).then(function (vault) {
_log('Decrypting credentials');
if (vault.hasOwnProperty('credentials')) {
if (vault.credentials.length > 0) {
for (var i = 0; i < vault.credentials.length; i++) {
var _credential = angular.copy(vault.credentials[i]);
if (_credential.hidden === 0) {
_credential = CredentialService.decryptCredential(_credential);
_credentials.push(_credential);
}
}
$window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () {
_log('Done');
});
}
}
});
};
}]);
}());