diaspora/public/javascripts/app/views/post_view.js
danielgrippi b583a7a444 Put dennis's changes back in
Revert "Revert "refactoring backbone urls""

This reverts commit 838da1fd52.

Revert "revert 9b1d64bb76 as it is causing inf. scroll to break (stream model now has a post collection)"

This reverts commit 2a69c0ebd4.
2012-01-19 17:05:30 -08:00

97 lines
2.4 KiB
JavaScript

app.views.Post = app.views.StreamObject.extend({
template_name: "#stream-element-template",
className : "stream_element loaded",
events: {
"click .focus_comment_textarea": "focusCommentTextarea",
"click .shield a": "removeNsfwShield",
"click .remove_post": "destroyModel",
"click .hide_post": "hidePost",
"click .block_user": "blockUser"
},
subviews : {
".feedback" : "feedbackView",
".likes" : "likesInfoView",
".comments" : "commentStreamView",
".post-content" : "postContentView"
},
tooltipSelector : ".delete, .block_user, .post_scope",
initialize : function() {
$(this.el).attr("id", this.model.get("guid"));
this.model.bind('remove', this.remove, this);
//subviews
this.commentStreamView = new app.views.CommentStream({ model : this.model});
this.likesInfoView = new app.views.LikesInfo({ model : this.model});
return this;
},
feedbackView : function(){
if(!window.app.user().current_user ) { return null }
return new app.views.Feedback({model : this.model});
},
postContentView: function(){
var normalizedClass = this.model.get("post_type").replace(/::/, "__");
var postClass = app.views[normalizedClass] || app.views.StatusMessage;
return new postClass({ model : this.model });
},
removeNsfwShield: function(evt){
if(evt){ evt.preventDefault(); }
$(evt.target).parent(".shield").remove();
return this;
},
blockUser: function(evt){
if(evt) { evt.preventDefault(); }
if(!confirm("Ignore this user?")) { return }
var personId = this.model.get("author").id;
var block = new app.models.Block();
block.save({block : {person_id : personId}}, {
success : function(){
if(!app.stream) { return }
_.each(app.stream.posts.models, function(model){
if(model.get("author").id == personId) {
app.stream.posts.remove(model);
}
})
}
})
},
hidePost : function(evt) {
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t('confirm_dialog'))) { return }
$.ajax({
url : "/share_visibilities/42",
type : "PUT",
data : {
post_id : this.model.id
}
})
this.slideAndRemove();
},
focusCommentTextarea: function(evt){
evt.preventDefault();
this.$(".new_comment_form_wrapper").removeClass("hidden");
this.$(".comment_box").focus();
return this;
}
});