Skip to content

Commit

Permalink
skip vote #127
Browse files Browse the repository at this point in the history
Hours of sleep: 25
Cups of coffee: 0
Cans of soda: 0
Cans of redbull: 0
  • Loading branch information
Gerad Suyderhoud committed Aug 30, 2011
1 parent 606acd6 commit 04e2c08
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions controllers/people.coffee
Expand Up @@ -54,6 +54,11 @@ app.get '/people/:id/edit', [m.loadPerson, m.ensureAccess], (req, res, next) ->
app.put '/people/:id', [m.loadPerson, m.ensureAccess], (req, res) ->
unless req.user.admin
delete req.body[attr] for attr in ['role', 'admin', 'technical']

if skip = req.body.skipTeamId
req.person.skippedTeamIds.push skip
delete req.body.skipTeamId

_.extend req.person, req.body
req.person.save (err) ->
return next err if err && err.name != 'ValidationError'
Expand Down
7 changes: 5 additions & 2 deletions models/person.coffee
Expand Up @@ -19,6 +19,7 @@ PersonSchema = module.exports = new mongoose.Schema
slug:
type: String
index: true
skippedTeamIds: [ mongoose.Schema.ObjectId ]
PersonSchema.plugin require('mongoose-types').useTimestamps
PersonSchema.plugin auth,
everymodule:
Expand Down Expand Up @@ -130,9 +131,11 @@ PersonSchema.method 'nextTeam', (next) ->

Vote = mongoose.model 'Vote'
Team = mongoose.model 'Team'
Vote.distinct 'teamId', personId: @id, (err, votedOn) ->
Vote.distinct 'teamId', personId: @id, (err, votedOn) =>
next err if err
filter._id = $nin: votedOn # not already voted

# not already voted on or skipped
filter._id = $nin: votedOn.concat @skippedTeamIds
Team.find filter, {}, { sort: sort, limit: 1 }, (err, teams) ->
# findOne doesn't seem to work with sort
next err if err
Expand Down
4 changes: 4 additions & 0 deletions public/javascripts/people.coffee
Expand Up @@ -37,6 +37,10 @@ $('form.person .twitter input').live('blur', ->
).change()

load = ->
$('#page.people-show .next-vote form.vote a.skip').click (e) ->
e.preventDefault()
$('#page.people-show .next-vote .skip-vote').submit()

# editing votes on your page does an ajax submit
$('#page.people-show .votes form.vote').submit (e) ->
$form = $(this)
Expand Down
2 changes: 2 additions & 0 deletions public/stylesheets/application.styl
Expand Up @@ -897,6 +897,8 @@ form.vote
margin 0
padding 0
margin-bottom 1em
.skip-vote
display none

#page.errors-404 #inner
.troll
Expand Down
5 changes: 5 additions & 0 deletions views/people/show.jade
Expand Up @@ -50,6 +50,11 @@ h1.name= title(person.name)
!= markdown(nextVote.team.entry.instructions)

!= partial('votes/form', { vote: nextVote })
form.skip-vote( action: '/people/' + user, method: 'POST' )
input( type: 'hidden', name: '_method', value: 'PUT' )
!= _csrf
input( type: 'hidden', name: 'skipTeamId', value: nextVote.team.id)
input( type: 'submit', value: 'Skip Entry' )

- if (votes.length)
- if (req.user && (req.user.id === req.person.id))
Expand Down
4 changes: 4 additions & 0 deletions views/votes/form-judge.jade
Expand Up @@ -18,3 +18,7 @@ table
a.edit.change( href: '#' ) Cancel
- else
input.scary( type: 'submit', value: 'Vote' )
- if (vote.nextVote)
| or
a.skip( href: '#' ) skip this entry
| .

0 comments on commit 04e2c08

Please sign in to comment.