1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-20 07:40:57 +02:00
bitwarden-browser/src/popup/app/vault/vaultController.js

124 lines
4.0 KiB
JavaScript
Raw Normal View History

angular
.module('bit.vault')
.controller('vaultController', function ($scope, $ionicModal, siteService, folderService, $q, cipherService) {
$scope.parentScope = $scope;
$scope.sites = [];
$scope.folders = [];
$scope.focusedSiteId = null;
2016-09-07 05:30:49 +02:00
$scope.$on('$ionicView.enter', function (event, data) {
2016-09-06 05:30:45 +02:00
loadVault();
});
2016-09-06 05:30:45 +02:00
function loadVault() {
var decSites = [];
var decFolders = [{
id: null,
name: '(none)'
}];
2016-09-05 17:05:27 +02:00
2016-09-06 05:30:45 +02:00
folderService.getAll(function (folders) {
siteService.getAll(function (sites) {
var promises = [];
2016-09-07 05:30:49 +02:00
for (var i = 1; i < folders.length; i++) {
2016-09-06 05:30:45 +02:00
decFolders.push({
id: folders[i].id
});
2016-09-05 17:05:27 +02:00
2016-09-07 05:30:49 +02:00
var folderNamePromise = cipherService.decrypt(folders[i].name, i);
2016-09-06 05:30:45 +02:00
promises.push(folderNamePromise);
folderNamePromise.then(function (obj) {
decFolders[obj.index].name = obj.val;
});
}
2016-09-06 04:27:32 +02:00
2016-09-06 05:30:45 +02:00
for (var j = 0; j < sites.length; j++) {
decSites.push({
id: sites[j].id,
folderId: sites[j].folderId,
favorite: sites[j].favorite
});
var namePromise = cipherService.decrypt(sites[j].name, j);
2016-09-06 05:30:45 +02:00
promises.push(namePromise);
namePromise.then(function (obj) {
decSites[obj.index].name = obj.val;
});
var usernamePromise = cipherService.decrypt(sites[j].username, j);
2016-09-06 05:30:45 +02:00
promises.push(usernamePromise);
usernamePromise.then(function (obj) {
decSites[obj.index].username = obj.val;
});
}
$q.all(promises).then(function () {
$scope.sites = decSites;
$scope.folders = decFolders;
});
2016-09-06 04:27:32 +02:00
});
});
2016-09-06 05:30:45 +02:00
}
2016-09-07 05:30:49 +02:00
$scope.folderSort = function (item) {
if (!item.id) {
return '';
}
return item.name.toLowerCase();
};
2016-09-06 05:43:56 +02:00
$scope.viewSite = function (site) {
$scope.focusedSiteId = site.id;
2016-09-06 05:43:56 +02:00
$ionicModal.fromTemplateUrl('app/vault/views/vaultViewSite.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.viewSiteModal = modal;
modal.show();
});
};
$scope.editSite = function (site) {
$scope.focusedSiteId = site.id;
2016-09-06 05:43:56 +02:00
$ionicModal.fromTemplateUrl('app/vault/views/vaultEditSite.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.editSiteModal = modal;
modal.show();
});
};
2016-09-03 22:48:39 +02:00
$scope.addSite = function () {
2016-09-04 03:45:45 +02:00
$ionicModal.fromTemplateUrl('app/vault/views/vaultAddSite.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.addSiteModal = modal;
modal.show();
});
2016-09-03 22:48:39 +02:00
};
$scope.closeAddSite = function () {
$scope.addSiteModal.hide();
};
2016-09-06 05:43:56 +02:00
$scope.closeViewSite = function () {
$scope.viewSiteModal.hide();
$scope.focusedSiteId = null;
2016-09-06 05:43:56 +02:00
};
$scope.closeEditSite = function () {
$scope.editSiteModal.hide();
$scope.focusedSiteId = null;
2016-09-06 05:43:56 +02:00
};
2016-09-07 05:30:49 +02:00
$scope.$on('closeViewSite.hidden', function () {
2016-09-04 03:45:45 +02:00
console.log('modal hidden');
2016-09-06 05:30:45 +02:00
loadVault();
2016-09-03 22:48:39 +02:00
});
});