Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created March 7, 2012 17:20
Show Gist options
  • Save ku1ik/1994471 to your computer and use it in GitHub Desktop.
Save ku1ik/1994471 to your computer and use it in GitHub Desktop.
class AsciiIo.Views.CommentsIndex extends AsciiIo.Views.Base
el: '#comments'
events:
'submit #new-comment': 'createComment'
initialize: ->
@collection.on('reset', @addAll, this)
@collection.on('add', @addOne, this)
addAll: ->
@collection.each (comment) =>
@addOne(comment)
this
addOne:(comment) ->
view = new AsciiIo.Views.CommentEntry({ model: comment, collection: @collection})
$(this.el).append view.render().el
this
createComment: (event) ->
attrs = body: $('#comment-body').val()
@collection.create attrs,
success: -> $('#new-comment')[0].reset()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment