42 lines
1.6 KiB
CoffeeScript
42 lines
1.6 KiB
CoffeeScript
lunchControllers = angular.module 'lunchControllers'
|
|
|
|
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce',
|
|
EditRunController = ($scope, socket, $routeParams, $sce) ->
|
|
$scope.show = false
|
|
|
|
socket.get '/run/' + $routeParams['id'],
|
|
(response) ->
|
|
if response.status is 404
|
|
window.location = '/404'
|
|
return
|
|
|
|
$scope.show = true
|
|
$scope.run = response
|
|
|
|
socket.get '/invitee', run_id: response.id, (inviteeResponse) ->
|
|
$scope.invitees = inviteeResponse
|
|
$scope.$apply()
|
|
|
|
$scope.addInvitee = () ->
|
|
$scope.invitees.push {}
|
|
|
|
$scope.removeInvitee = (index) ->
|
|
$scope.invitees.splice index, 1
|
|
|
|
$scope.update = (run,invitees) ->
|
|
runData = angular.copy run
|
|
inviteeData = angular.copy invitees
|
|
creatorInvitee = _.find inviteeData, (i) -> return i.isCreator
|
|
creatorInvitee.name = runData.creatorName
|
|
creatorInvitee.email = runData.creatorEmail
|
|
|
|
socket.put '/run/update/' + runData.id, runData, (runResponse) ->
|
|
inviteesCreated = 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()
|
|
]
|