Support adding groups to projects via share modal

This commit is contained in:
James Allen 2015-10-15 13:53:46 +01:00
parent d996ed6e47
commit b0895cc6aa
2 changed files with 32 additions and 16 deletions

View file

@ -4,7 +4,7 @@ define [
App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, $modal, $http) -> App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, $modal, $http) ->
$scope.inputs = { $scope.inputs = {
privileges: "readAndWrite" privileges: "readAndWrite"
email: "" contacts: []
} }
$scope.state = { $scope.state = {
error: null error: null
@ -54,32 +54,40 @@ define [
$timeout -> # Give email list a chance to update $timeout -> # Give email list a chance to update
return if $scope.inputs.contacts.length == 0 return if $scope.inputs.contacts.length == 0
console.warn "Ignoring groups for now" members = $scope.inputs.contacts
emails = $scope.inputs.contacts.filter (contact) -> contact.type == "user"
emails = emails.map (contact) -> contact.email
$scope.inputs.contacts = [] $scope.inputs.contacts = []
$scope.state.error = null $scope.state.error = null
$scope.state.inflight = true $scope.state.inflight = true
console.log "Adding emails", emails console.log "Adding members", members
do addNextMember = () -> do addNextMember = () ->
if emails.length == 0 or !$scope.canAddCollaborators if members.length == 0 or !$scope.canAddCollaborators
$scope.state.inflight = false $scope.state.inflight = false
$scope.$apply() $scope.$apply()
return return
email = emails.shift() member = members.shift()
projectMembers if member.type == "user"
.addMember(email, $scope.inputs.privileges) request = projectMembers.addMember(member.email, $scope.inputs.privileges)
else if member.type == "group"
request = projectMembers.addGroup(member.id, $scope.inputs.privileges)
request
.success (data) -> .success (data) ->
if data?.user # data.user is false if collaborator limit is hit. if data.users?
$scope.project.members.push data.user users = data.users
setTimeout () -> else if data.user?
# Give $scope a chance to update $scope.canAddCollaborators users = [data.user]
# with new collaborator information. else
addNextMember() users = []
, 0
$scope.project.members.push users...
setTimeout () ->
# Give $scope a chance to update $scope.canAddCollaborators
# with new collaborator information.
addNextMember()
, 0
.error () -> .error () ->
$scope.state.inflight = false $scope.state.inflight = false
$scope.state.error = "Sorry, something went wrong :(" $scope.state.error = "Sorry, something went wrong :("

View file

@ -17,5 +17,13 @@ define [
privileges: privileges privileges: privileges
_csrf: window.csrfToken _csrf: window.csrfToken
}) })
addGroup: (group_id, privileges) ->
$http.post("/project/#{ide.project_id}/group", {
group_id: group_id
privileges: privileges
_csrf: window.csrfToken
})
} }
] ]