Change order url to invitee ID, add invitee model
This commit is contained in:
@@ -2,23 +2,31 @@ lunchControllers = angular.module 'lunchControllers'
|
||||
|
||||
lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 'socket',
|
||||
CreateRunController = ($scope, $http, $location, socket) ->
|
||||
$scope.run =
|
||||
invitees: []
|
||||
$scope.run = {}
|
||||
$scope.invitees = []
|
||||
|
||||
$scope.addInvitee = () ->
|
||||
$scope.run.invitees.push {}
|
||||
$scope.invitees.push {}
|
||||
|
||||
$scope.removeInvitee = (index) ->
|
||||
$scope.run.invitees.splice index, 1
|
||||
$scope.invitees.splice index, 1
|
||||
|
||||
$scope.create = (run) ->
|
||||
data = angular.copy run
|
||||
data.invitees.push
|
||||
name: data.creatorName
|
||||
email: data.creatorEmail
|
||||
socket.post '/run', data, (response) ->
|
||||
$location.path '/run/' + response.id
|
||||
$scope.$apply()
|
||||
$scope.create = (run,invitees) ->
|
||||
runData = angular.copy run
|
||||
inviteeData = angular.copy invitees
|
||||
inviteeData.push
|
||||
name: runData.creatorName
|
||||
email: runData.creatorEmail
|
||||
|
||||
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()
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user