Skip to content

Instantly share code, notes, and snippets.

@nickw
Created December 21, 2012 00:15
Show Gist options
  • Save nickw/4349756 to your computer and use it in GitHub Desktop.
Save nickw/4349756 to your computer and use it in GitHub Desktop.
View
clickVote: (event)->
direction = event.direction
oppositeDirection = if direction is "up" then "down" else "up"
if currentUser.hasVoted(@model, direction)
@model.removeVote(direction)
else
if currentUser.hasVoted(@model, oppositeDirection)
@model.removeVote(oppositeDirection)
@model.addVote(direction)
Model
addVote: (direction) ->
if direction is "up"
up_voter_ids << currentUser.id
@incrementScore()
else if direction is "down"
down_voter_ids << currentUser.id
@decrementScore()
removeVote: (direction, silent=false) ->
if direction is "up"
up_voter_ids = up_voter_ids - currentUser.id
@decrementScore()
else if direction is "down"
down_voter_ids = down_voter_ids - currentUser.id
@incrementScore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment