diff --git a/src/app/organization/organizationCollectionsAddController.js b/src/app/organization/organizationCollectionsAddController.js index ce459eb029..a8516a9775 100644 --- a/src/app/organization/organizationCollectionsAddController.js +++ b/src/app/organization/organizationCollectionsAddController.js @@ -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; + } + } } } } diff --git a/src/app/organization/organizationCollectionsEditController.js b/src/app/organization/organizationCollectionsEditController.js index 7e35d9283e..26bb0f224c 100644 --- a/src/app/organization/organizationCollectionsEditController.js +++ b/src/app/organization/organizationCollectionsEditController.js @@ -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; + } + } } } } diff --git a/src/app/organization/organizationGroupsAddController.js b/src/app/organization/organizationGroupsAddController.js index 4f20c126d6..011d90f1af 100644 --- a/src/app/organization/organizationGroupsAddController.js +++ b/src/app/organization/organizationGroupsAddController.js @@ -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]); } } } diff --git a/src/app/organization/organizationGroupsEditController.js b/src/app/organization/organizationGroupsEditController.js index b37540c87c..adb81e2101 100644 --- a/src/app/organization/organizationGroupsEditController.js +++ b/src/app/organization/organizationGroupsEditController.js @@ -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]); } } } diff --git a/src/app/organization/organizationPeopleEditController.js b/src/app/organization/organizationPeopleEditController.js index dafa76ec5d..c35a8d3801 100644 --- a/src/app/organization/organizationPeopleEditController.js +++ b/src/app/organization/organizationPeopleEditController.js @@ -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 }; } diff --git a/src/app/organization/organizationPeopleInviteController.js b/src/app/organization/organizationPeopleInviteController.js index f0b0e2e63a..d41c6c6625 100644 --- a/src/app/organization/organizationPeopleInviteController.js +++ b/src/app/organization/organizationPeopleInviteController.js @@ -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 }; } diff --git a/src/app/organization/views/organizationCollectionsAdd.html b/src/app/organization/views/organizationCollectionsAdd.html index 1c2a1a7450..cfb9e2c524 100644 --- a/src/app/organization/views/organizationCollectionsAdd.html +++ b/src/app/organization/views/organizationCollectionsAdd.html @@ -42,6 +42,7 @@ ng-click="toggleGroupSelectionAll($event)"> Name + Read Only @@ -59,6 +60,14 @@ + + + diff --git a/src/app/organization/views/organizationCollectionsEdit.html b/src/app/organization/views/organizationCollectionsEdit.html index 88a6b1003f..05fa8546f9 100644 --- a/src/app/organization/views/organizationCollectionsEdit.html +++ b/src/app/organization/views/organizationCollectionsEdit.html @@ -43,6 +43,7 @@ ng-click="toggleGroupSelectionAll($event)"> Name + Read Only @@ -60,6 +61,14 @@ + + + diff --git a/src/app/organization/views/organizationGroupsAdd.html b/src/app/organization/views/organizationGroupsAdd.html index cf0d406f61..8581e71103 100644 --- a/src/app/organization/views/organizationGroupsAdd.html +++ b/src/app/organization/views/organizationGroupsAdd.html @@ -53,6 +53,7 @@ ng-click="toggleCollectionSelectionAll($event)"> Name + Read Only @@ -67,6 +68,14 @@ {{collection.name}} + + + diff --git a/src/app/organization/views/organizationGroupsEdit.html b/src/app/organization/views/organizationGroupsEdit.html index 8ec71103df..af9f1b80b7 100644 --- a/src/app/organization/views/organizationGroupsEdit.html +++ b/src/app/organization/views/organizationGroupsEdit.html @@ -53,6 +53,7 @@ ng-click="toggleCollectionSelectionAll($event)"> Name + Read Only @@ -67,6 +68,14 @@ {{collection.name}} + + +