diaspora/public/javascripts/app/views/stream_post_views.js
2012-03-27 14:54:27 -07:00

102 lines
No EOL
2.5 KiB
JavaScript

app.views.StreamPost = app.views.Post.extend({
templateName: "stream-element",
className : "stream_element loaded",
subviews : {
".feedback" : "feedbackView",
".likes" : "likesInfoView",
".comments" : "commentStreamView",
".post-content" : "postContentView"
},
events: {
"click .focus_comment_textarea": "focusCommentTextarea",
"click .show_nsfw_post": "removeNsfwShield",
"click .toggle_nsfw_state": "toggleNsfwState",
"click .remove_post": "destroyModel",
"click .hide_post": "hidePost",
"click .block_user": "blockUser"
},
tooltipSelector : ".delete, .block_user, .post_scope",
initialize : function(){
this.model.bind('remove', this.remove, this);
//subviews
this.commentStreamView = new app.views.CommentStream({ model : this.model});
},
likesInfoView : function(){
return new app.views.LikesInfo({ model : this.model});
},
feedbackView : function(){
if(!app.currentUser.authenticated()) { 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(); }
this.model.set({nsfw : false})
this.render();
},
toggleNsfwState: function(evt){
if(evt){ evt.preventDefault(); }
app.currentUser.toggleNsfwState();
},
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;
}
})