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', .when '/run/:id',
templateUrl: 'templates/run/show.html', templateUrl: 'templates/run/show.html',
controller: 'RunCtrl' controller: 'RunCtrl'
.when '/run/:id',
templateUrl: 'templates/run/edit.html',
controller: 'EditRunCtrl'
.when '/order/:inviteeId', .when '/order/:inviteeId',
templateUrl: 'templates/invitee/update-order.html', templateUrl: 'templates/invitee/update-order.html',
controller: 'UpdateOrderCtrl' 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'
]

View File

@@ -13,6 +13,12 @@
margin-right: 2px; margin-right: 2px;
padding: 5px 20px; padding: 5px 20px;
} }
.run-show-actions a.back-to-run {
display: none;
}
.update-order-actions a.edit-run {
display: none;
}
} }
} }

View File

@@ -30,9 +30,6 @@
} }
} }
.run-show-actions a.back-to-run {
display: none;
}
.invitee { .invitee {
.deletebtn-wrapper { .deletebtn-wrapper {

View File

@@ -6,7 +6,8 @@ block pagetitle
a(href='/#/run/{{ run.id }}') {{ run.name }} a(href='/#/run/{{ run.id }}') {{ run.name }}
block pageactions block pageactions
include ../includes/run-actions .update-order-actions
include ../includes/run-actions
block interiorcontent block interiorcontent
div(ng-show='show') div(ng-show='show')

View File

@@ -0,0 +1,90 @@
extends ../layouts/interior-page
block pagetitle
span.glyphicon.glyphicon-chevron-right.title-icon
| start a new lunch run
block interiorcontent
.create-run-form(ng-controller='CreateRunCtrl')
form.row(name='form',novalidate,role='form')
.col-xs-12.col-sm-6
section.name.row
.col-xs-12.col-lg-2.step-num
span.glyphicon.glyphicon-info-sign(title='Lunch Run Info')
.col-xs-12.col-lg-10
.form-group(ng-class="{'has-error has-feedback': form.Name.$dirty && form.Name.$invalid, 'has-success has-feedback': form.Name.$dirty && form.Name.$valid}")
input#name.form-control.input-lg(type='text',ng-model='run.name',required,placeholder='Name your run',name='Name')
div(ng-show='form.Name.$dirty && form.Name.$invalid')
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='form.Name.$error.required') What should we call you lunch run?
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show="form.Name.$dirty && form.Name.$valid")
section.row
.col-xs-12.col-lg-2.step-num
span.glyphicon.glyphicon-user(title='Your Info')
.col-xs-12.col-lg-10
.form-group(ng-class="{'has-error has-feedback': form.CreatorName.$dirty && form.CreatorName.$invalid, 'has-success has-feedback': form.CreatorName.$dirty && form.CreatorName.$valid}")
input#creatorName.form-control.input-lg(type='text',ng-model='run.creatorName',required,placeholder='Your name',name='CreatorName')
div(ng-show="form.CreatorName.$dirty && form.CreatorName.$invalid")
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='form.CreatorName.$error.required') What's your name?
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='form.CreatorName.$dirty && form.CreatorName.$valid')
.form-group(ng-class="{'has-error has-feedback': form.Email.$dirty && form.Email.$invalid, 'has-success has-feedback': form.Email.$dirty && form.Email.$valid}")
input#creatorEmail.form-control.input-lg(type='email',ng-model='run.creatorEmail',required,placeholder='Your email',name='Email')
div(ng-show='form.Email.$dirty && form.Email.$invalid')
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='form.Email.$error.required') What's your email address?
span(ng-show='form.Email.$error.email') That doesn't look like a valid email address.
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='form.Email.$dirty && form.Email.$valid')
section.row
.col-xs-12.col-lg-2.step-num
span.glyphicon.glyphicon-map-marker(title='Lunch Location')
.col-xs-12.col-lg-10
.form-group(ng-class="{'has-error has-feedback': form.Restaurant.$dirty && form.Restaurant.$invalid, 'has-success has-feedback': form.Restaurant.$dirty && form.Restaurant.$valid}")
input#restaurant.form-control.input-lg(type='text',ng-model='run.restaurant',placeholder='Restaurant',name='Restaurant',required)
div(ng-show="form.Restaurant.$dirty && form.Restaurant.$invalid")
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='form.Restaurant.$error.required') Where are you going to eat?
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='form.Restaurant.$dirty && form.Restaurant.$valid')
.form-group
input#menuUrl.form-control.input-lg(type='url',ng-model='run.menuUrl',placeholder='Menu URL')
.col-xs-12.col-sm-6
section.invitees.row
.col-xs-12.col-lg-2.step-num
span.glyphicon.glyphicon-list(title='Lunch Invitees')
.col-xs-12.col-lg-10
.invitee.clearfix(ng-repeat='i in invitees')
ng-form(name='inviteeForm')
.row
.col-xs-10.name-wrapper
.form-group(ng-class="{'has-error has-feedback': inviteeForm.Name.$dirty && inviteeForm.Name.$invalid, 'has-success has-feedback': inviteeForm.Name.$dirty && inviteeForm.Name.$valid}")
input.form-control.input-lg(ng-model='i.name',required,placeholder='Name',name="Name")
div(ng-show='inviteeForm.Name.$dirty && inviteeForm.Name.$invalid')
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='inviteeForm.Name.$error.required') Give this person a name
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='inviteeForm.Name.$dirty && inviteeForm.Name.$valid')
.col-xs-2.deletebtn-wrapper
button.btn.btn-block.btn-lg.btn-warning(ng-click='removeInvitee($index)')
span.glyphicon.glyphicon-remove
.col-xs-10.email-wrapper
.form-group(ng-class="{'has-error has-feedback': inviteeForm.Email.$dirty && inviteeForm.Email.$invalid, 'has-success has-feedback': inviteeForm.Email.$dirty && inviteeForm.Email.$valid}")
input.form-control.input-lg(type='email',ng-model='i.email',required,placeholder='Email',name="Email")
div(ng-show='inviteeForm.Email.$dirty && inviteeForm.Email.$invalid')
span.glyphicon.glyphicon-remove.form-control-feedback
span(ng-show='inviteeForm.Email.$error.required') What's this person's email address?
span(ng-show='inviteeForm.Email.$error.email') That doesn't look like a valid email address.
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='inviteeForm.Email.$dirty && inviteeForm.Email.$valid')
button.btn.btn-default.btn-lg.btn-block(ng-click='addInvitee()')
span.glyphicon.glyphicon-plus
|  Invite another!
section.submit
button.btn.btn-lg.btn-success.btn-block(ng-click="create(run,invitees)",ng-disabled="form.$invalid")
| Create

View File

@@ -30,6 +30,7 @@ html(lang="en",ng-app="lunchApp")
script(type="text/javascript", src="/linker/js/analytics.js") script(type="text/javascript", src="/linker/js/analytics.js")
script(type="text/javascript", src="/linker/js/controllers/body-controller.js") script(type="text/javascript", src="/linker/js/controllers/body-controller.js")
script(type="text/javascript", src="/linker/js/controllers/create-run-controller.js") script(type="text/javascript", src="/linker/js/controllers/create-run-controller.js")
script(type="text/javascript", src="/linker/js/controllers/edit-run-controller.js")
script(type="text/javascript", src="/linker/js/controllers/home-controller.js") script(type="text/javascript", src="/linker/js/controllers/home-controller.js")
script(type="text/javascript", src="/linker/js/controllers/run-controller.js") script(type="text/javascript", src="/linker/js/controllers/run-controller.js")
script(type="text/javascript", src="/linker/js/controllers/update-order-controller.js") script(type="text/javascript", src="/linker/js/controllers/update-order-controller.js")