Completed edit run functionality

This commit is contained in:
Ben Ramey
2014-07-04 13:51:27 -05:00
parent 65a3d36cd2
commit 1316b58ab2
6 changed files with 39 additions and 16 deletions

View File

@@ -8,7 +8,8 @@ lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 's
$scope.addInvitee = () -> $scope.addInvitee = () ->
$scope.invitees.push {} $scope.invitees.push {}
$scope.removeInvitee = (index) -> $scope.removeInvitee = (invitee) ->
index = $scope.invitees.indexOf invitee
$scope.invitees.splice index, 1 $scope.invitees.splice index, 1
$scope.create = (run,invitees) -> $scope.create = (run,invitees) ->

View File

@@ -1,7 +1,7 @@
lunchControllers = angular.module 'lunchControllers' lunchControllers = angular.module 'lunchControllers'
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce', lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce', '$location',
EditRunController = ($scope, socket, $routeParams, $sce) -> EditRunController = ($scope, socket, $routeParams, $sce, $location) ->
$scope.show = false $scope.show = false
socket.get '/run/' + $routeParams['id'], socket.get '/run/' + $routeParams['id'],
@@ -20,8 +20,18 @@ lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams',
$scope.addInvitee = () -> $scope.addInvitee = () ->
$scope.invitees.push {} $scope.invitees.push {}
$scope.removeInvitee = (index) -> $scope.removeInvitee = (invitee) ->
if invitee.id
socket.delete '/invitee/destroy/' + invitee.id, (deleteResponse) ->
console.log deleteResponse
$scope.spliceInvitee invitee
else
$scope.spliceInvitee invitee
$scope.spliceInvitee = (invitee) ->
index = $scope.invitees.indexOf invitee
$scope.invitees.splice index, 1 $scope.invitees.splice index, 1
$scope.$apply()
$scope.update = (run,invitees) -> $scope.update = (run,invitees) ->
runData = angular.copy run runData = angular.copy run
@@ -30,12 +40,22 @@ lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams',
creatorInvitee.name = runData.creatorName creatorInvitee.name = runData.creatorName
creatorInvitee.email = runData.creatorEmail creatorInvitee.email = runData.creatorEmail
socket.put '/run/update/' + runData.id, runData, (runResponse) -> socket.put '/run/' + runData.id, runData, (runResponse) ->
inviteesCreated = 0
inviteesUpdated = 0
for i in inviteeData for i in inviteeData
socket.put '/invitee/update/' + i.id, i, (inviteeResponse) -> if i.id
inviteesCreated++ socket.put '/invitee/' + i.id, i, (inviteeResponse) ->
if inviteesCreated is inviteeData.length inviteesUpdated++
$location.path '/run/' + runResponse.id $scope.redirectIfAllInviteesUpdated inviteesUpdated, inviteeData.length
$scope.$apply() else
i.run_id = runData.id
socket.post '/invitee', i, (inviteeResponse) ->
inviteesUpdated++
$scope.redirectIfAllInviteesUpdated inviteesUpdated, inviteeData.length
$scope.redirectIfAllInviteesUpdated = (updatedCount, inviteeCount) ->
if updatedCount is inviteeCount
$location.path '/run/' + $scope.run.id
$scope.$apply()
] ]

View File

@@ -21,7 +21,7 @@ form {
right: 5px; right: 5px;
} }
} }
.create-run-form { .edit-run-form, .create-run-form {
.invitees { .invitees {
.btn-default { .btn-default {
margin-top: 20px; margin-top: 20px;

View File

@@ -60,7 +60,7 @@
span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='inviteeForm.Name.$dirty && inviteeForm.Name.$valid') span.glyphicon.glyphicon-ok.form-control-feedback(ng-show='inviteeForm.Name.$dirty && inviteeForm.Name.$valid')
.col-xs-2.deletebtn-wrapper .col-xs-2.deletebtn-wrapper
button.btn.btn-block.btn-lg.btn-warning(ng-click='removeInvitee($index)') button.btn.btn-block.btn-lg.btn-warning(ng-click='removeInvitee(i)')
span.glyphicon.glyphicon-remove span.glyphicon.glyphicon-remove
.col-xs-10.email-wrapper .col-xs-10.email-wrapper

View File

@@ -5,7 +5,7 @@ block pagetitle
| update your lunch run | update your lunch run
block interiorcontent block interiorcontent
.create-run-form(ng-controller='EditRunCtrl') .edit-run-form(ng-controller='EditRunCtrl')
form.row(name='form',novalidate,role='form',ng-show="show") form.row(name='form',novalidate,role='form',ng-show="show")
include _form include _form
section.submit section.submit

View File

@@ -23,14 +23,16 @@ module.exports.policies = {
RunController: { RunController: {
'*': false, '*': false,
'find': true, 'find': true,
'create': true 'create': true,
'update': true
}, },
InviteeController: { InviteeController: {
'*': false, '*': false,
'find': true, 'find': true,
'create': true, 'create': true,
'update': true 'update': true,
'destroy': true
}, },
SessionController: { SessionController: {