diaspora/app/assets/javascripts/app/collections/comments.js
2015-02-08 23:41:31 +01:00

27 lines
728 B
JavaScript

// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
app.collections.Comments = Backbone.Collection.extend({
model: app.models.Comment,
url: function() { return _.result(this.post, 'url') + '/comments'; },
initialize : function(models, options) {
this.post = options.post;
},
make : function(text){
var self = this;
var comment = new app.models.Comment({text: text });
var deferred = comment.save({}, {
url: '/posts/'+this.post.id+'/comments',
success: function() {
comment.set({author: app.currentUser.toJSON(), parent: self.post });
self.add(comment);
}
});
return deferred;
}
});
// @license-end