2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller "ShareProjectModalController", ["$scope", "$modalInstance", "$timeout", "projectMembers", "$modal", ($scope, $modalInstance, $timeout, projectMembers, $modal) ->
|
|
|
|
$scope.inputs = {
|
|
|
|
privileges: "readAndWrite"
|
|
|
|
email: ""
|
|
|
|
}
|
|
|
|
$scope.state = {
|
|
|
|
error: null
|
|
|
|
inflight: false
|
|
|
|
startedFreeTrial: false
|
|
|
|
}
|
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
INFINITE_COLLABORATORS = -1
|
|
|
|
$scope.$watch "project.members.length", (noOfMembers) ->
|
|
|
|
allowedNoOfMembers = $scope.project.features.collaborators
|
|
|
|
$scope.canAddCollaborators = noOfMembers < allowedNoOfMembers or allowedNoOfMembers == INFINITE_COLLABORATORS
|
|
|
|
|
|
|
|
$scope.addMember = () ->
|
|
|
|
return if !$scope.inputs.email? or $scope.inputs.email == ""
|
|
|
|
$scope.state.error = null
|
|
|
|
$scope.state.inflight = true
|
|
|
|
projectMembers
|
|
|
|
.addMember($scope.inputs.email, $scope.inputs.privileges)
|
2014-11-06 06:53:59 -05:00
|
|
|
.success (data) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
$scope.inputs.email = ""
|
2014-11-06 06:53:59 -05:00
|
|
|
$scope.project.members.push data?.user
|
|
|
|
.error () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
$scope.state.error = "Sorry, something went wrong :("
|
|
|
|
|
|
|
|
|
|
|
|
$scope.removeMember = (member) ->
|
|
|
|
$scope.state.error = null
|
|
|
|
$scope.state.inflight = true
|
|
|
|
projectMembers
|
|
|
|
.removeMember(member)
|
2014-11-06 06:53:59 -05:00
|
|
|
.success () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
index = $scope.project.members.indexOf(member)
|
|
|
|
return if index == -1
|
|
|
|
$scope.project.members.splice(index, 1)
|
2014-11-06 06:53:59 -05:00
|
|
|
.error () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
$scope.state.error = "Sorry, something went wrong :("
|
|
|
|
|
|
|
|
$scope.openMakePublicModal = () ->
|
|
|
|
$modal.open {
|
|
|
|
templateUrl: "makePublicModalTemplate"
|
|
|
|
controller: "MakePublicModalController"
|
|
|
|
scope: $scope
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openMakePrivateModal = () ->
|
|
|
|
$modal.open {
|
|
|
|
templateUrl: "makePrivateModalTemplate"
|
|
|
|
controller: "MakePrivateModalController"
|
|
|
|
scope: $scope
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.done = () ->
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss()
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "MakePublicModalController", ["$scope", "$modalInstance", "settings", ($scope, $modalInstance, settings) ->
|
|
|
|
$scope.inputs = {
|
|
|
|
privileges: "readAndWrite"
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.makePublic = () ->
|
|
|
|
$scope.project.publicAccesLevel = $scope.inputs.privileges
|
|
|
|
settings.saveProjectSettings({publicAccessLevel: $scope.inputs.privileges})
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss()
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "MakePrivateModalController", ["$scope", "$modalInstance", "settings", ($scope, $modalInstance, settings) ->
|
|
|
|
$scope.makePrivate = () ->
|
|
|
|
$scope.project.publicAccesLevel = "private"
|
|
|
|
settings.saveProjectSettings({publicAccessLevel: "private"})
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss()
|
|
|
|
]
|