diaspora/public/javascripts/app/views/commment_stream_view.js
danielgrippi ae6fa5bebb don't use Diaspora widget system or stream.js when backbone is active;
migrating like actions over to backbone; some cleanup; bump jquery to
1.7.1
2012-01-07 14:23:22 -08:00

45 lines
956 B
JavaScript

App.Views.CommentStream = Backbone.View.extend({
events: {
"submit form": "createComment"
},
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#comment-stream-template").html());
_.bindAll(this, "appendComment");
this.model.comments.bind("add", this.appendComment);
},
render: function() {
$(this.el).html(this.template($.extend(
this.model.toJSON(),
App.user()
)));
this.$("label").inFieldLabels();
this.model.comments.each(this.appendComment);
return this;
},
createComment: function(evt) {
evt.preventDefault();
this.model.comments.create({
"text" : this.$(".comment_box").val(),
"post_id" : this.model.id
});
this.$(".comment_box").val("");
return this;
},
appendComment: function(comment) {
this.$("ul.comments").append(new App.Views.Comment({
model: comment
}).render().el);
}
});