diaspora/app/assets/javascripts/app/collections/comments.js
Florian Staudacher 1924c40d38 replace vendored backbone.js/underscore.js with 'backbone-on-rails' gem
- updates underscore to 1.5.2 and backbone to 1.1.0

backbone had some breaking changes:
- fix url/urlRoot handling in models & collections
- options are no longer attached to the view by default
- collections reset when 'fetch' is called, tell it to keep the existing
  models

other changes:
- fix some events triggering multiple times in connection with deleting
  a model
- use document fragments instead of an element array for stream entries
- adapt jasmine and cucumber specs to the changed code
  * no longer test the backbone router as part of our code
  * jasmine factory already returns model instances, no need to wrap
    that again
2014-01-16 23:23:30 +01:00

24 lines
603 B
JavaScript

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;
}
});