lunchControllers = angular.module 'lunchControllers'

lunchControllers.controller 'CreateOrderCtrl', ['$scope','socket','$routeParams','$location',
    CreateOrderController = ($scope, socket, $routeParams, $location) ->
        $scope.show = false
        $scope.showMenuUrl = false

        socket.get '/invitee/findOne', id: $routeParams['inviteeId'], (inviteeResponse) ->
            $scope.invitee = inviteeResponse

            socket.get '/run/' + inviteeResponse.run_id,
                (runResponse) ->
                    $scope.show = true
                    $scope.showMenuUrl = runResponse.menuUrl
                    $scope.run = runResponse
                    $scope.$apply()

        $scope.submit = (invitee) ->
            socket.put '/invitee/' + $routeParams['inviteeId'], { order: invitee.order }, (response) ->
                $location.path '/run/' + $scope.run.id
                $scope.$apply()
]
