Files
lunchrun.me/public/linker/js/controllers/create-order-controller.js
2014-03-22 20:19:01 -05:00

36 lines
1.1 KiB
JavaScript

var CreateOrderController, lunchControllers;
lunchControllers = angular.module('lunchControllers');
lunchControllers.controller('CreateOrderCtrl', [
'$scope', 'socket', '$routeParams', '$location', CreateOrderController = function($scope, socket, $routeParams, $location) {
$scope.show = false;
$scope.showMenuUrl = false;
socket.get('/run/' + $routeParams['id'], function(response) {
$scope.show = true;
$scope.showMenuUrl = response.menuUrl !== '';
$scope.run = response;
$scope.invitee = _.find(response.invitees, function(i) {
return i.name.toLowerCase() === $routeParams['inviteeName'];
});
$scope.invitees = response.invitees;
return $scope.$apply();
});
return $scope.submit = function(invitee) {
var invitees;
invitees = _.map($scope.invitees, function(i) {
if (i.name === invitee.name) {
return invitee;
}
return i;
});
return socket.put('/run/' + $routeParams['id'], {
invitees: invitees
}, function(response) {
$location.path('/run/' + response.id);
return $scope.$apply();
});
};
}
]);