mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
collection add/edit groups
This commit is contained in:
parent
96a91b97e9
commit
bfae8e7def
@ -4,6 +4,7 @@
|
||||
.controller('organizationCollectionsAddController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
|
||||
$analytics, authService) {
|
||||
$analytics.eventTrack('organizationCollectionsAddController', { category: 'Modal' });
|
||||
var groupsLength = 0;
|
||||
$scope.groups = [];
|
||||
$scope.selectedGroups = {};
|
||||
$scope.loading = true;
|
||||
@ -35,6 +36,10 @@
|
||||
name: groups.Data[i].Name,
|
||||
accessAll: groups.Data[i].AccessAll
|
||||
});
|
||||
|
||||
if (!groups.Data[i].AccessAll) {
|
||||
groupsLength++;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.groups = groupsArr;
|
||||
@ -45,7 +50,11 @@
|
||||
var groups = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
groups[$scope.groups[i].id] = true;
|
||||
groups[$scope.groups[i].id] = {
|
||||
id: $scope.groups[i].id,
|
||||
readOnly: ($scope.groups[i].id in $scope.selectedGroups) ?
|
||||
$scope.selectedGroups[$scope.groups[i].id].readOnly : false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +66,16 @@
|
||||
delete $scope.selectedGroups[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedGroups[id] = true;
|
||||
$scope.selectedGroups[id] = {
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$scope.toggleGroupReadOnlySelection = function (group) {
|
||||
if (group.id in $scope.selectedGroups) {
|
||||
$scope.selectedGroups[group.id].readOnly = !group.accessAll && !!!$scope.selectedGroups[group.id].readOnly;
|
||||
}
|
||||
};
|
||||
|
||||
@ -66,18 +84,25 @@
|
||||
};
|
||||
|
||||
$scope.allSelected = function () {
|
||||
return Object.keys($scope.selectedGroups).length === $scope.groups.length;
|
||||
return Object.keys($scope.selectedGroups).length >= groupsLength;
|
||||
};
|
||||
|
||||
$scope.submit = function (model) {
|
||||
var collection = cipherService.encryptCollection(model, $state.params.orgId);
|
||||
|
||||
if ($scope.useGroups) {
|
||||
collection.groupIds = [];
|
||||
collection.groups = [];
|
||||
|
||||
for (var groupId in $scope.selectedGroups) {
|
||||
if ($scope.selectedGroups.hasOwnProperty(groupId)) {
|
||||
collection.groupIds.push(groupId);
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
if ($scope.groups[i].id === $scope.selectedGroups[groupId].id) {
|
||||
if (!$scope.groups[i].accessAll) {
|
||||
collection.groups.push($scope.selectedGroups[groupId]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
.controller('organizationCollectionsEditController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
|
||||
$analytics, id, authService) {
|
||||
$analytics.eventTrack('organizationCollectionsEditController', { category: 'Modal' });
|
||||
var groupsLength = 0;
|
||||
$scope.collection = {};
|
||||
$scope.groups = [];
|
||||
$scope.selectedGroups = {};
|
||||
@ -16,9 +17,12 @@
|
||||
$scope.collection = cipherService.decryptCollection(collection);
|
||||
|
||||
var groups = {};
|
||||
if (collection.GroupIds) {
|
||||
for (var i = 0; i < collection.GroupIds.length; i++) {
|
||||
groups[collection.GroupIds[i]] = true;
|
||||
if (collection.Groups) {
|
||||
for (var i = 0; i < collection.Groups.length; i++) {
|
||||
groups[collection.Groups[i].Id] = {
|
||||
id: collection.Groups[i].Id,
|
||||
readOnly: collection.Groups[i].ReadOnly
|
||||
};
|
||||
}
|
||||
}
|
||||
$scope.selectedGroups = groups;
|
||||
@ -48,6 +52,10 @@
|
||||
name: groups.Data[i].Name,
|
||||
accessAll: groups.Data[i].AccessAll
|
||||
});
|
||||
|
||||
if (!groups.Data[i].AccessAll) {
|
||||
groupsLength++;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.groups = groupsArr;
|
||||
@ -58,7 +66,11 @@
|
||||
var groups = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
groups[$scope.groups[i].id] = true;
|
||||
groups[$scope.groups[i].id] = {
|
||||
id: $scope.groups[i].id,
|
||||
readOnly: ($scope.groups[i].id in $scope.selectedGroups) ?
|
||||
$scope.selectedGroups[$scope.groups[i].id].readOnly : false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +82,16 @@
|
||||
delete $scope.selectedGroups[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedGroups[id] = true;
|
||||
$scope.selectedGroups[id] = {
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$scope.toggleGroupReadOnlySelection = function (group) {
|
||||
if (group.id in $scope.selectedGroups) {
|
||||
$scope.selectedGroups[group.id].readOnly = !group.accessAll && !!!$scope.selectedGroups[group.id].readOnly;
|
||||
}
|
||||
};
|
||||
|
||||
@ -79,18 +100,25 @@
|
||||
};
|
||||
|
||||
$scope.allSelected = function () {
|
||||
return Object.keys($scope.selectedGroups).length === $scope.groups.length;
|
||||
return Object.keys($scope.selectedGroups).length >= groupsLength;
|
||||
};
|
||||
|
||||
$scope.submit = function (model) {
|
||||
var collection = cipherService.encryptCollection(model, $state.params.orgId);
|
||||
|
||||
if ($scope.useGroups) {
|
||||
collection.groupIds = [];
|
||||
collection.groups = [];
|
||||
|
||||
for (var groupId in $scope.selectedGroups) {
|
||||
if ($scope.selectedGroups.hasOwnProperty(groupId)) {
|
||||
collection.groupIds.push(groupId);
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
if ($scope.groups[i].id === $scope.selectedGroups[groupId].id) {
|
||||
if (!$scope.groups[i].accessAll) {
|
||||
collection.groups.push($scope.selectedGroups[groupId]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,11 @@
|
||||
var collections = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.collections.length; i++) {
|
||||
collections[$scope.collections[i].id] = true;
|
||||
collections[$scope.collections[i].id] = {
|
||||
id: $scope.collections[i].id,
|
||||
readOnly: ($scope.collections[i].id in $scope.selectedCollections) ?
|
||||
$scope.selectedCollections[$scope.collections[i].id].readOnly : false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +35,16 @@
|
||||
delete $scope.selectedCollections[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedCollections[id] = true;
|
||||
$scope.selectedCollections[id] = {
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$scope.toggleCollectionReadOnlySelection = function (id) {
|
||||
if (id in $scope.selectedCollections) {
|
||||
$scope.selectedCollections[id].readOnly = !!!$scope.selectedCollections[id].readOnly;
|
||||
}
|
||||
};
|
||||
|
||||
@ -50,10 +63,10 @@
|
||||
};
|
||||
|
||||
if (!group.accessAll) {
|
||||
group.collectionIds = [];
|
||||
for (var id in $scope.selectedCollections) {
|
||||
if ($scope.selectedCollections.hasOwnProperty(id)) {
|
||||
group.collectionIds.push(id);
|
||||
group.collections = [];
|
||||
for (var collectionId in $scope.selectedCollections) {
|
||||
if ($scope.selectedCollections.hasOwnProperty(collectionId)) {
|
||||
group.collections.push($scope.selectedCollections[collectionId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,12 @@
|
||||
};
|
||||
|
||||
var collections = {};
|
||||
if (group.CollectionIds) {
|
||||
for (var i = 0; i < group.CollectionIds.length; i++) {
|
||||
collections[group.CollectionIds[i]] = true;
|
||||
if (group.Collections) {
|
||||
for (var i = 0; i < group.Collections.length; i++) {
|
||||
collections[group.Collections[i].Id] = {
|
||||
id: group.Collections[i].Id,
|
||||
readOnly: group.Collections[i].ReadOnly
|
||||
};
|
||||
}
|
||||
}
|
||||
$scope.selectedCollections = collections;
|
||||
@ -35,7 +38,11 @@
|
||||
var collections = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.collections.length; i++) {
|
||||
collections[$scope.collections[i].id] = true;
|
||||
collections[$scope.collections[i].id] = {
|
||||
id: $scope.collections[i].id,
|
||||
readOnly: ($scope.collections[i].id in $scope.selectedCollections) ?
|
||||
$scope.selectedCollections[$scope.collections[i].id].readOnly : false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +54,16 @@
|
||||
delete $scope.selectedCollections[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedCollections[id] = true;
|
||||
$scope.selectedCollections[id] = {
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$scope.toggleCollectionReadOnlySelection = function (id) {
|
||||
if (id in $scope.selectedCollections) {
|
||||
$scope.selectedCollections[id].readOnly = !!!$scope.selectedCollections[id].readOnly;
|
||||
}
|
||||
};
|
||||
|
||||
@ -66,10 +82,10 @@
|
||||
};
|
||||
|
||||
if (!group.accessAll) {
|
||||
group.collectionIds = [];
|
||||
for (var collId in $scope.selectedCollections) {
|
||||
if ($scope.selectedCollections.hasOwnProperty(collId)) {
|
||||
group.collectionIds.push(collId);
|
||||
group.collections = [];
|
||||
for (var collectionId in $scope.selectedCollections) {
|
||||
if ($scope.selectedCollections.hasOwnProperty(collectionId)) {
|
||||
group.collections.push($scope.selectedCollections[collectionId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
if (user && user.Collections) {
|
||||
for (var i = 0; i < user.Collections.length; i++) {
|
||||
collections[user.Collections[i].Id] = {
|
||||
collectionId: user.Collections[i].Id,
|
||||
id: user.Collections[i].Id,
|
||||
readOnly: user.Collections[i].ReadOnly
|
||||
};
|
||||
}
|
||||
@ -37,7 +37,7 @@
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.collections.length; i++) {
|
||||
collections[$scope.collections[i].id] = {
|
||||
collectionId: $scope.collections[i].id,
|
||||
id: $scope.collections[i].id,
|
||||
readOnly: ($scope.collections[i].id in $scope.selectedCollections) ?
|
||||
$scope.selectedCollections[$scope.collections[i].id].readOnly : false
|
||||
};
|
||||
@ -53,7 +53,7 @@
|
||||
}
|
||||
else {
|
||||
$scope.selectedCollections[id] = {
|
||||
collectionId: id,
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.collections.length; i++) {
|
||||
collections[$scope.collections[i].id] = {
|
||||
collectionId: $scope.collections[i].id,
|
||||
id: $scope.collections[i].id,
|
||||
readOnly: ($scope.collections[i].id in $scope.selectedCollections) ?
|
||||
$scope.selectedCollections[$scope.collections[i].id].readOnly : false
|
||||
};
|
||||
@ -40,7 +40,7 @@
|
||||
}
|
||||
else {
|
||||
$scope.selectedCollections[id] = {
|
||||
collectionId: id,
|
||||
id: id,
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
ng-click="toggleGroupSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th style="width: 100px; text-align: center;">Read Only</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -59,6 +60,14 @@
|
||||
<i class="fa fa-unlock text-muted fa-fw" ng-show="group.accessAll"
|
||||
title="This group can access all items"></i>
|
||||
</td>
|
||||
<td style="width: 100px; text-align: center;" valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedGroupsReadonly[]"
|
||||
value="{{group.id}}"
|
||||
ng-disabled="!groupSelected(group) || group.accessAll"
|
||||
ng-checked="groupSelected(group) && selectedGroups[group.id].readOnly"
|
||||
ng-click="toggleGroupReadOnlySelection(group)">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -43,6 +43,7 @@
|
||||
ng-click="toggleGroupSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th style="width: 100px; text-align: center;">Read Only</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -60,6 +61,14 @@
|
||||
<i class="fa fa-unlock text-muted fa-fw" ng-show="group.accessAll"
|
||||
title="This group can access all items"></i>
|
||||
</td>
|
||||
<td style="width: 100px; text-align: center;" valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedGroupsReadonly[]"
|
||||
value="{{group.id}}"
|
||||
ng-disabled="!groupSelected(group) || group.accessAll"
|
||||
ng-checked="groupSelected(group) && selectedGroups[group.id].readOnly"
|
||||
ng-click="toggleGroupReadOnlySelection(group)">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -53,6 +53,7 @@
|
||||
ng-click="toggleCollectionSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th style="width: 100px; text-align: center;">Read Only</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -67,6 +68,14 @@
|
||||
<td valign="middle">
|
||||
{{collection.name}}
|
||||
</td>
|
||||
<td style="width: 100px; text-align: center;" valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedCollectionsReadonly[]"
|
||||
value="{{collection.id}}"
|
||||
ng-disabled="!collectionSelected(collection)"
|
||||
ng-checked="collectionSelected(collection) && selectedCollections[collection.id].readOnly"
|
||||
ng-click="toggleCollectionReadOnlySelection(collection.id)">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -53,6 +53,7 @@
|
||||
ng-click="toggleCollectionSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th style="width: 100px; text-align: center;">Read Only</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -67,6 +68,14 @@
|
||||
<td valign="middle">
|
||||
{{collection.name}}
|
||||
</td>
|
||||
<td style="width: 100px; text-align: center;" valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedCollectionsReadonly[]"
|
||||
value="{{collection.id}}"
|
||||
ng-disabled="!collectionSelected(collection)"
|
||||
ng-checked="collectionSelected(collection) && selectedCollections[collection.id].readOnly"
|
||||
ng-click="toggleCollectionReadOnlySelection(collection.id)">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user