added block user functionality to the stream

This commit is contained in:
danielgrippi 2011-12-15 17:40:27 -08:00 committed by Dennis Collinson
parent 6760e3868d
commit b94b5240a8
5 changed files with 45 additions and 23 deletions

View file

@ -1,6 +1,8 @@
class BlocksController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json
def create
block = current_user.blocks.new(params[:block])
@ -10,7 +12,11 @@ class BlocksController < ApplicationController
else
notice = {:error => t('blocks.create.failure')}
end
redirect_to :back, notice
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end
def destroy
@ -19,7 +25,11 @@ class BlocksController < ApplicationController
else
notice = {:error => t('blocks.destroy.failure')}
end
redirect_to :back, notice
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end
protected

View file

@ -2,10 +2,7 @@
<div class="right controls">
<!-- need access to post -->
<% if(author.id === current_user.id) { %>
<!-- LINK BROKEN FOR NOW -->
<a href="/posts/<%= id %>/comments/<%= id %>" class="delete comment_delete" data-original-title="Delete">
<img alt="Deletelabel" src="/images/deletelabel.png">
</a>
<img alt="Deletelabel" src="/images/deletelabel.png" class="delete comment_delete" data-original-title="Delete" />
<% } %>
</div>

View file

@ -1,23 +1,16 @@
<div id="<%= guid %>" class="stream_element">
<div class="right controls">
<% if(author.id != current_user.id) { %>
<a href="/blocks?block[person_id]=<%= author.id %>" class="block_user control_icon" data-confirm="Ignore and remove user from all aspects?" data-method="post" rel="nofollow" title="Ignore">
<img alt="Ignoreuser" src="/images/icons/ignoreuser.png"/>
</a>
<img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "Ignore" data-person_id="<%= author.id %>" />
<% } %>
<a href="#" class="delete control_icon remove_post" title="Delete">
<img src="/images/deletelabel.png"/>
</a>
<img src="/images/deletelabel.png" class="delete control_icon remove_post" title="Delete" />
<img src="/images/ajax-loader.gif" class="hide_loader hidden"/>
</div>
<div class="sm_body">
<a href="/people/<%= author.id %>">
<img src="<%= author.avatar.small %>" class="avatar" data-person-id="<%= author.id %>"/>
<img src="<%= author.avatar.small %>" class="avatar" data-person_id="<%= author.id %>"/>
</a>
<div class="content">
@ -80,8 +73,7 @@
<% if(public && author.id != current_user.id) { %>
<% if(root) {
var rootGuid = root.guid;
}
else {
} else {
var rootGuid = guid;
} %>
<a href="/reshares?root_guid=<%= rootGuid %>" class="reshare_action" data-confirm="Reshare Bob Grimm's post?" data-method="post" data-remote="true" rel="nofollow">
@ -98,8 +90,8 @@
<div class="likes on_post">
<div class="likes_container">
<% if(likes_count > 0){ %>
<img alt="Heart" src="/images/icons/heart.png?1322618579">
<a href="/posts/<%= id %>/likes" class="expand_likes">
<img alt="Heart" src="/images/icons/heart.png">
<a href="#" class="expand_likes">
<%= likes_count %> like
</a>
<% } %>

View file

@ -8,7 +8,8 @@ App.Views.Post = App.Views.StreamObject.extend({
"click .shield a": "removeNsfwShield",
"click .remove_post": "destroyModel",
"click .like_action": "toggleLike",
"click .expand_likes": "expandLikes"
"click .expand_likes": "expandLikes",
"click .block_user": "blockUser"
},
render: function() {
@ -123,6 +124,29 @@ App.Views.Post = App.Views.StreamObject.extend({
return this;
},
blockUser: function(evt){
if(evt) { evt.preventDefault(); }
if(confirm('Ignore this user?')) {
var person_id = $(evt.target).data('person_id');
var self = this;
$.post('/blocks', {block : {"person_id" : person_id}}, function(data){
var models_to_remove = [];
_.each(self.model.collection.models, function(model){
if(model.get("author")["id"] == person_id) {
models_to_remove.push(model);
}
})
self.model.collection.remove(models_to_remove);
}, "json");
}
return this;
},
focusCommentTextarea: function(evt){
evt.preventDefault();
this.$(".new_comment_form_wrapper").removeClass("hidden");

View file

@ -3,7 +3,7 @@ App.Views.StreamObject = Backbone.View.extend({
this.model = options.model;
this.template = _.template($(this.template_name).html());
this.model.bind('destroy', this.remove, this);
this.model.bind('remove', this.remove, this);
},
destroyModel: function(evt){
@ -14,5 +14,4 @@ App.Views.StreamObject = Backbone.View.extend({
remove: function() {
$(this.el).remove();
}
});