Created
March 7, 2012 17:20
-
-
Save ku1ik/1994471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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