35 lines
1.2 KiB
CoffeeScript
35 lines
1.2 KiB
CoffeeScript
lunchControllers = angular.module 'lunchControllers'
|
|
|
|
lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 'socket',
|
|
CreateRunController = ($scope, $http, $location, socket) ->
|
|
$scope.run = {}
|
|
$scope.invitees = []
|
|
|
|
$scope.addInvitee = () ->
|
|
$scope.invitees.push {}
|
|
|
|
$scope.removeInvitee = (invitee) ->
|
|
index = $scope.invitees.indexOf invitee
|
|
$scope.invitees.splice index, 1
|
|
|
|
$scope.create = (run,invitees) ->
|
|
runData = angular.copy run
|
|
inviteeData = angular.copy invitees
|
|
inviteeData.push
|
|
name: runData.creatorName
|
|
email: runData.creatorEmail
|
|
isCreator: true
|
|
|
|
socket.post '/run', runData, (runResponse) ->
|
|
inviteesCreated = 0
|
|
for i in inviteeData
|
|
i.run_id = runResponse.id
|
|
socket.post '/invitee', i, (inviteeResponse) ->
|
|
inviteesCreated++
|
|
if inviteesCreated is inviteeData.length
|
|
$location.path '/run/' + runResponse.id
|
|
$scope.$apply()
|
|
|
|
$scope.addInvitee()
|
|
]
|