mirror of
https://github.com/bitwarden/web
synced 2025-12-23 11:43:15 +00:00
more logins to cipher renames
This commit is contained in:
121
src/app/vault/vaultCipherCollectionsController.js
Normal file
121
src/app/vault/vaultCipherCollectionsController.js
Normal file
@@ -0,0 +1,121 @@
|
||||
angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultCipherCollectionsController', function ($scope, apiService, $uibModalInstance, cipherService,
|
||||
cipherId, $analytics) {
|
||||
$analytics.eventTrack('vaultCipherCollectionsController', { category: 'Modal' });
|
||||
$scope.cipher = {};
|
||||
$scope.readOnly = false;
|
||||
$scope.loadingCipher = true;
|
||||
$scope.loadingCollections = true;
|
||||
$scope.selectedCollections = {};
|
||||
$scope.collections = [];
|
||||
|
||||
$uibModalInstance.opened.then(function () {
|
||||
apiService.ciphers.getDetails({ id: cipherId }).$promise.then(function (cipher) {
|
||||
$scope.loadingCipher = false;
|
||||
|
||||
$scope.readOnly = !cipher.Edit;
|
||||
if (cipher.Edit && cipher.OrganizationId) {
|
||||
if (cipher.Type === 1) {
|
||||
$scope.cipher = cipherService.decryptCipherPreview(cipher);
|
||||
}
|
||||
|
||||
var collections = {};
|
||||
if (cipher.CollectionIds) {
|
||||
for (var i = 0; i < cipher.CollectionIds.length; i++) {
|
||||
collections[cipher.CollectionIds[i]] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
cipher: cipher,
|
||||
cipherCollections: collections
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}).then(function (cipherAndCols) {
|
||||
if (!cipherAndCols) {
|
||||
$scope.loadingCollections = false;
|
||||
return;
|
||||
}
|
||||
|
||||
apiService.collections.listMe({ writeOnly: true }, function (response) {
|
||||
var collections = [];
|
||||
var selectedCollections = {};
|
||||
|
||||
for (var i = 0; i < response.Data.length; i++) {
|
||||
// clean out selectCollections that aren't from this organization or read only
|
||||
if (response.Data[i].Id in cipherAndCols.cipherCollections &&
|
||||
response.Data[i].OrganizationId === cipherAndCols.cipher.OrganizationId) {
|
||||
selectedCollections[response.Data[i].Id] = true;
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
var decCollection = cipherService.decryptCollection(response.Data[i]);
|
||||
collections.push(decCollection);
|
||||
}
|
||||
|
||||
$scope.loadingCollections = false;
|
||||
$scope.collections = collections;
|
||||
$scope.selectedCollections = selectedCollections;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$scope.toggleCollectionSelectionAll = function ($event) {
|
||||
var collections = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.collections.length; i++) {
|
||||
collections[$scope.collections[i].id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.selectedCollections = collections;
|
||||
};
|
||||
|
||||
$scope.toggleCollectionSelection = function (id) {
|
||||
if (id in $scope.selectedCollections) {
|
||||
delete $scope.selectedCollections[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedCollections[id] = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.collectionSelected = function (collection) {
|
||||
return collection.id in $scope.selectedCollections;
|
||||
};
|
||||
|
||||
$scope.allSelected = function () {
|
||||
return Object.keys($scope.selectedCollections).length === $scope.collections.length;
|
||||
};
|
||||
|
||||
$scope.submit = function () {
|
||||
var request = {
|
||||
collectionIds: []
|
||||
};
|
||||
|
||||
for (var id in $scope.selectedCollections) {
|
||||
if ($scope.selectedCollections.hasOwnProperty(id)) {
|
||||
request.collectionIds.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.submitPromise = apiService.ciphers.putCollections({ id: cipherId }, request)
|
||||
.$promise.then(function (response) {
|
||||
$analytics.eventTrack('Edited Cipher Collections');
|
||||
$uibModalInstance.close({
|
||||
action: 'collectionsEdit',
|
||||
collectionIds: request.collectionIds
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.close = function () {
|
||||
$uibModalInstance.dismiss('cancel');
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user