Completed edit run functionality
This commit is contained in:
@@ -8,7 +8,8 @@ lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 's
|
||||
$scope.addInvitee = () ->
|
||||
$scope.invitees.push {}
|
||||
|
||||
$scope.removeInvitee = (index) ->
|
||||
$scope.removeInvitee = (invitee) ->
|
||||
index = $scope.invitees.indexOf invitee
|
||||
$scope.invitees.splice index, 1
|
||||
|
||||
$scope.create = (run,invitees) ->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
lunchControllers = angular.module 'lunchControllers'
|
||||
|
||||
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce',
|
||||
EditRunController = ($scope, socket, $routeParams, $sce) ->
|
||||
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce', '$location',
|
||||
EditRunController = ($scope, socket, $routeParams, $sce, $location) ->
|
||||
$scope.show = false
|
||||
|
||||
socket.get '/run/' + $routeParams['id'],
|
||||
@@ -20,8 +20,18 @@ lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams',
|
||||
$scope.addInvitee = () ->
|
||||
$scope.invitees.push {}
|
||||
|
||||
$scope.removeInvitee = (index) ->
|
||||
$scope.removeInvitee = (invitee) ->
|
||||
if invitee.id
|
||||
socket.delete '/invitee/destroy/' + invitee.id, (deleteResponse) ->
|
||||
console.log deleteResponse
|
||||
$scope.spliceInvitee invitee
|
||||
else
|
||||
$scope.spliceInvitee invitee
|
||||
|
||||
$scope.spliceInvitee = (invitee) ->
|
||||
index = $scope.invitees.indexOf invitee
|
||||
$scope.invitees.splice index, 1
|
||||
$scope.$apply()
|
||||
|
||||
$scope.update = (run,invitees) ->
|
||||
runData = angular.copy run
|
||||
@@ -30,12 +40,22 @@ lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams',
|
||||
creatorInvitee.name = runData.creatorName
|
||||
creatorInvitee.email = runData.creatorEmail
|
||||
|
||||
socket.put '/run/update/' + runData.id, runData, (runResponse) ->
|
||||
inviteesCreated = 0
|
||||
socket.put '/run/' + runData.id, runData, (runResponse) ->
|
||||
|
||||
inviteesUpdated = 0
|
||||
for i in inviteeData
|
||||
socket.put '/invitee/update/' + i.id, i, (inviteeResponse) ->
|
||||
inviteesCreated++
|
||||
if inviteesCreated is inviteeData.length
|
||||
$location.path '/run/' + runResponse.id
|
||||
$scope.$apply()
|
||||
if i.id
|
||||
socket.put '/invitee/' + i.id, i, (inviteeResponse) ->
|
||||
inviteesUpdated++
|
||||
$scope.redirectIfAllInviteesUpdated inviteesUpdated, inviteeData.length
|
||||
else
|
||||
i.run_id = runData.id
|
||||
socket.post '/invitee', i, (inviteeResponse) ->
|
||||
inviteesUpdated++
|
||||
$scope.redirectIfAllInviteesUpdated inviteesUpdated, inviteeData.length
|
||||
|
||||
$scope.redirectIfAllInviteesUpdated = (updatedCount, inviteeCount) ->
|
||||
if updatedCount is inviteeCount
|
||||
$location.path '/run/' + $scope.run.id
|
||||
$scope.$apply()
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user