Skip to content
Extraits de code Groupes Projets
Valider b94b5240 rédigé par danielgrippi's avatar danielgrippi Validation de Dennis Collinson
Parcourir les fichiers

added block user functionality to the stream

parent 6760e386
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
......
......@@ -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>
......
<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>
<% } %>
......
......@@ -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");
......
......@@ -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();
}
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter