edit logins from subvaults page

This commit is contained in:
Kyle Spearrin 2017-04-05 11:37:22 -04:00
parent 157875f7d5
commit 83c232ecb5
5 changed files with 102 additions and 6 deletions

View File

@ -72,7 +72,7 @@
controller: 'vaultEditLoginController',
resolve: {
loginId: function () { return login.id; },
folders: function () { return $scope.folders; }
folders: getFoldersPromise()
}
});
@ -116,7 +116,7 @@
templateUrl: 'app/vault/views/vaultAddLogin.html',
controller: 'vaultAddLoginController',
resolve: {
folders: function () { return $scope.folders; },
folders: getFoldersPromise(),
selectedFolder: function () { return folder; },
checkedFavorite: function () { return favorite; }
}
@ -227,4 +227,10 @@
});
};
function getFoldersPromise() {
var deferred = $q.defer();
deferred.resolve($scope.folders);
return deferred.promise;
}
});

View File

@ -9,6 +9,7 @@
$scope.loadingLogin = true;
$scope.loadingSubvaults = true;
$scope.selectedSubvaults = {};
$scope.subvaults = [];
$uibModalInstance.opened.then(function () {
apiService.ciphers.getFullDetails({ id: loginId }).$promise.then(function (cipher) {
@ -82,12 +83,12 @@
return Object.keys($scope.selectedSubvaults).length === $scope.subvaults.length;
};
$scope.save = function (model) {
$scope.submit = function (model) {
var request = {
subvaultIds: model.subvaultIds
};
$scope.savePromise = apiService.ciphers.putSubvaults({ id: loginId }, request, function (response) {
$scope.submitPromise = apiService.ciphers.putSubvaults({ id: loginId }, request, function (response) {
$analytics.eventTrack('Edited Login Subvaults');
$uibModalInstance.close({
action: 'subvaultsEdit'

View File

@ -1,9 +1,11 @@
angular
.module('bit.vault')
.controller('vaultSubvaultsController', function ($scope, apiService, cipherService, $analytics, $q, $localStorage) {
.controller('vaultSubvaultsController', function ($scope, apiService, cipherService, $analytics, $q, $localStorage,
$uibModal, $filter) {
$scope.logins = [];
$scope.subvaults = [];
$scope.folders = [];
$scope.loading = true;
$scope.$on('$viewContentLoaded', function () {
@ -56,4 +58,71 @@
$localStorage.collapsedSubvaults[subvault.id] = true;
}
};
$scope.editLogin = function (login) {
var editModel = $uibModal.open({
animation: true,
templateUrl: 'app/vault/views/vaultEditLogin.html',
controller: 'vaultEditLoginController',
resolve: {
loginId: function () { return login.id; },
folders: getFoldersPromise()
}
});
editModel.result.then(function (returnVal) {
var loginToUpdate;
if (returnVal.action === 'edit') {
loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true);
if (loginToUpdate && loginToUpdate.length > 0) {
loginToUpdate[0].folderId = returnVal.data.folderId;
loginToUpdate[0].name = returnVal.data.name;
loginToUpdate[0].username = returnVal.data.username;
loginToUpdate[0].favorite = returnVal.data.favorite;
}
}
else if (returnVal.action === 'partialEdit') {
loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true);
if (loginToUpdate && loginToUpdate.length > 0) {
loginToUpdate[0].folderId = returnVal.data.folderId;
loginToUpdate[0].favorite = returnVal.data.favorite;
}
}
else if (returnVal.action === 'delete') {
var loginToDelete = $filter('filter')($scope.logins, { id: returnVal.data }, true);
if (loginToDelete && loginToDelete.length > 0) {
var index = $scope.logins.indexOf(loginToDelete[0]);
if (index > -1) {
$scope.logins.splice(index, 1);
}
}
}
});
};
function getFoldersPromise() {
var deferred = $q.defer();
if (!$scope.folders || !$scope.folders.length) {
apiService.folders.list({}).$promise.then(function (folders) {
var decFolders = [{
id: null,
name: 'No Folder'
}];
for (var i = 0; i < folders.Data.length; i++) {
var decFolder = cipherService.decryptFolderPreview(folders.Data[i]);
decFolders.push(decFolder);
}
$scope.folders = decFolders;
deferred.resolve($scope.folders);
});
}
else {
deferred.resolve($scope.folders);
}
return deferred.promise;
}
});

View File

@ -51,6 +51,11 @@
<i class="fa fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<li>
<a href="javascript:void(0)" ng-click="editLogin(login)">
<i class="fa fa-fw fa-pencil"></i> Edit
</a>
</li>
<li ng-show="!login.organizationId">
<a href="javascript:void(0)" ng-click="share(login)">
<i class="fa fa-fw fa-share-alt"></i> Share
@ -133,6 +138,11 @@
<i class="fa fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<li>
<a href="javascript:void(0)" ng-click="editLogin(login)">
<i class="fa fa-fw fa-pencil"></i> Edit
</a>
</li>
<li ng-show="!login.organizationId">
<a href="javascript:void(0)" ng-click="share(login)">
<i class="fa fa-fw fa-share-alt"></i> Share

View File

@ -41,9 +41,19 @@
<i class="fa fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<li>
<a href="javascript:void(0)" ng-click="editLogin(login)">
<i class="fa fa-fw fa-pencil"></i> Edit
</a>
</li>
<li>
<a href="javascript:void(0)" ng-click="subvaults(login)">
<i class="fa fa-fw fa-share-alt"></i> Subvaults
</a>
</li>
<li>
<a href="javascript:void(0)" ng-click="deleteLogin(login)" class="text-red">
<i class="fa fa-fw fa-trash"></i> Delete
<i class="fa fa-fw fa-remove"></i> Remove
</a>
</li>
</ul>