Skip to content

Instantly share code, notes, and snippets.

@mplatts
Created November 27, 2014 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mplatts/7a7728e6cea7d98b4898 to your computer and use it in GitHub Desktop.
Save mplatts/7a7728e6cea7d98b4898 to your computer and use it in GitHub Desktop.
templates 2 - edit games
# client/views/game.coffee
Template.game.events
"click .finish-game": (e, tpl) ->
e.preventDefault()
Games.update({_id: @_id}, {$set: {completed: true}})
"click .delete-game": (e, tpl) ->
Games.remove(@_id)
"click .one-plus": (e, tpl) ->
e.preventDefault()
@teams[0].score += 1
Games.update({_id: @_id}, {$set: {teams: @teams}})
"click .two-plus": (e, tpl) ->
e.preventDefault()
@teams[1].score += 1
Games.update({_id: @_id}, {$set: {teams: @teams}})
"click .one-minus": (e, tpl) ->
e.preventDefault()
@teams[0].score -= 1
Games.update({_id: @_id}, {$set: {teams: @teams}})
"click .two-minus": (e, tpl) ->
e.preventDefault()
@teams[1].score -= 1
Games.update({_id: @_id}, {$set: {teams: @teams}})
<!-- client/views/game.html -->
<template name="game">
<li>
{{#if completed}}
{{teams.[0].name}} ({{teams.[0].score}})
vs
{{teams.[1].name}} ({{teams.[1].score}})
{{else}}
{{teams.[0].name}} (<a class="one-minus" href="#">-</a> {{teams.[0].score}} <a class="one-plus" href="#">+</a>)
vs
{{teams.[1].name}} (<a class="two-minus" href="#">-</a> {{teams.[1].score}} <a class="two-plus" href="#">+</a>)
<a href="#" class="finish-game">Finish</a>
<a href="#" class="delete-game">Delete</a>
{{/if}}
</li>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment