Edit controller, template, styles

This commit is contained in:
Ben Ramey
2014-06-24 21:47:00 -05:00
parent 0c5b53459f
commit 0609c52fbc
7 changed files with 153 additions and 4 deletions

View File

@@ -16,6 +16,9 @@ lunchApp.config ['$routeProvider',
.when '/run/:id',
templateUrl: 'templates/run/show.html',
controller: 'RunCtrl'
.when '/run/:id',
templateUrl: 'templates/run/edit.html',
controller: 'EditRunCtrl'
.when '/order/:inviteeId',
templateUrl: 'templates/invitee/update-order.html',
controller: 'UpdateOrderCtrl'

View File

@@ -0,0 +1,51 @@
lunchControllers = angular.module 'lunchControllers'
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce',
EditRunController = ($scope, socket, $routeParams, $sce) ->
$scope.show = false
$scope.progress = 0
$scope.numOrders = 0
$scope.progressClass = 'progress-bar-danger'
$scope.showMenuUrl = false
socket.get '/run/' + $routeParams['id'],
(response) ->
if response.status is 404
window.location = '/404'
return
$scope.show = true
$scope.run = response
$scope.showMenuUrl = response.menuUrl
$scope.menuUrl = $sce.trustAsResourceUrl(response.menuUrl)
socket.get '/invitee', run_id: response.id, (inviteeResponse) ->
$scope.invitees = inviteeResponse
$scope.numOrders = $scope.invitees.length
$scope.setStatusClasses()
$scope.setProgress()
$scope.$apply()
socket.on 'message', (m) ->
if m.verb is 'update' and m.data.run_id is $routeParams.id
invitee = _.findWhere $scope.invitees, id: m.data.id
_.extend invitee, m.data
$scope.setProgress()
$scope.setStatusClasses()
$scope.$apply()
$scope.setStatusClasses = () ->
for i in $scope.invitees
if i.order
i.statusClass = 'done'
else
i.statusClass = 'incomplete'
$scope.setProgress = () ->
numFilledOrders = _.filter($scope.invitees, (i) -> i.order).length
$scope.progress = (numFilledOrders / $scope.numOrders) * 100
if $scope.progress >= 100
$scope.progressClass = 'progress-bar-success'
else
$scope.progressClass = 'progress-bar-danger'
]