2017-05-08 22:01:36 +02:00
|
|
|
|
angular
|
|
|
|
|
.module('bit.organization')
|
|
|
|
|
|
2017-05-09 04:13:31 +02:00
|
|
|
|
.controller('organizationGroupsAddController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
|
2017-05-08 22:01:36 +02:00
|
|
|
|
$analytics) {
|
|
|
|
|
$analytics.eventTrack('organizationGroupsAddController', { category: 'Modal' });
|
2017-05-09 04:13:31 +02:00
|
|
|
|
$scope.collections = [];
|
|
|
|
|
$scope.selectedCollections = {};
|
|
|
|
|
$scope.loading = true;
|
|
|
|
|
|
|
|
|
|
$uibModalInstance.opened.then(function () {
|
|
|
|
|
return apiService.collections.listOrganization({ orgId: $state.params.orgId }).$promise;
|
|
|
|
|
}).then(function (collections) {
|
|
|
|
|
$scope.collections = cipherService.decryptCollections(collections.Data, $state.params.orgId, true);
|
|
|
|
|
$scope.loading = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
};
|
2017-05-08 22:01:36 +02:00
|
|
|
|
|
|
|
|
|
$scope.submit = function (model) {
|
|
|
|
|
var group = {
|
2017-05-09 04:13:31 +02:00
|
|
|
|
name: model.name,
|
2017-05-10 18:17:26 +02:00
|
|
|
|
accessAll: !!model.accessAll
|
2017-05-08 22:01:36 +02:00
|
|
|
|
};
|
2017-05-09 04:13:31 +02:00
|
|
|
|
|
2017-05-10 18:17:26 +02:00
|
|
|
|
if (!group.accessAll) {
|
|
|
|
|
group.collectionIds = [];
|
|
|
|
|
for (var id in $scope.selectedCollections) {
|
|
|
|
|
if ($scope.selectedCollections.hasOwnProperty(id)) {
|
|
|
|
|
group.collectionIds.push(id);
|
|
|
|
|
}
|
2017-05-09 04:13:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 22:01:36 +02:00
|
|
|
|
$scope.submitPromise = apiService.groups.post({ orgId: $state.params.orgId }, group, function (response) {
|
|
|
|
|
$analytics.eventTrack('Created Group');
|
|
|
|
|
$uibModalInstance.close({
|
|
|
|
|
id: response.Id,
|
|
|
|
|
name: response.Name
|
|
|
|
|
});
|
|
|
|
|
}).$promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.close = function () {
|
|
|
|
|
$uibModalInstance.dismiss('cancel');
|
|
|
|
|
};
|
|
|
|
|
});
|