Files
dss/static/js/app/views/comment.js
2012-09-26 20:24:33 +01:00

55 lines
1.7 KiB
JavaScript

/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.CommentListItemView = Backbone.View.extend({
tagName:"li",
initialize:function () {
$(this.el).data("id", this.model.get("id"));
$(this.el).addClass("comment-entry");
},
render:function () {
$(this.el).html(this.template({"item":this.model.toJSON()}));
return this;
}
});
window.CommentListView = Backbone.View.extend({
initialize:function () {
//this.collection.bind('add', this.render);
},
events:{
"click #id-btn-add-comment":"addComment"
},
addComment:function (ev) {
var comment = $('textarea[name=new-comment]').val();
var view = this;
if (comment) {
this.collection.create({
mix:this.collection.mix,
comment:comment,
time_index:15
}, {
success:function () {
view.collection.sort();
view.render();
},
error:function () {
com.podnoms.utils.showAlert("Error", "Unable to save comment", "alert-error");
}});
$('textarea[name=new-comment]').val('');
}
return false;
},
render:function () {
$(this.el).html(this.template()).append('<ul class="comment-listing list-nostyle"></ul>');
this.collection.each(function (item) {
$('.comment-listing', this.el).append(new CommentListItemView({model:item}).render().el);
}, this);
return this;
}
});