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 class BlocksController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html, :json
def create def create
block = current_user.blocks.new(params[:block]) block = current_user.blocks.new(params[:block])
...@@ -10,7 +12,11 @@ class BlocksController < ApplicationController ...@@ -10,7 +12,11 @@ class BlocksController < ApplicationController
else else
notice = {:error => t('blocks.create.failure')} notice = {:error => t('blocks.create.failure')}
end end
redirect_to :back, notice
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end end
def destroy def destroy
...@@ -19,7 +25,11 @@ class BlocksController < ApplicationController ...@@ -19,7 +25,11 @@ class BlocksController < ApplicationController
else else
notice = {:error => t('blocks.destroy.failure')} notice = {:error => t('blocks.destroy.failure')}
end end
redirect_to :back, notice
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end end
protected protected
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
<div class="right controls"> <div class="right controls">
<!-- need access to post --> <!-- need access to post -->
<% if(author.id === current_user.id) { %> <% if(author.id === current_user.id) { %>
<!-- LINK BROKEN FOR NOW --> <img alt="Deletelabel" src="/images/deletelabel.png" class="delete comment_delete" data-original-title="Delete" />
<a href="/posts/<%= id %>/comments/<%= id %>" class="delete comment_delete" data-original-title="Delete">
<img alt="Deletelabel" src="/images/deletelabel.png">
</a>
<% } %> <% } %>
</div> </div>
......
<div id="<%= guid %>" class="stream_element"> <div id="<%= guid %>" class="stream_element">
<div class="right controls"> <div class="right controls">
<% if(author.id != current_user.id) { %> <% 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 src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "Ignore" data-person_id="<%= author.id %>" />
<img alt="Ignoreuser" src="/images/icons/ignoreuser.png"/>
</a>
<% } %> <% } %>
<img src="/images/deletelabel.png" class="delete control_icon remove_post" title="Delete" />
<a href="#" class="delete control_icon remove_post" title="Delete">
<img src="/images/deletelabel.png"/>
</a>
<img src="/images/ajax-loader.gif" class="hide_loader hidden"/> <img src="/images/ajax-loader.gif" class="hide_loader hidden"/>
</div> </div>
<div class="sm_body"> <div class="sm_body">
<a href="/people/<%= author.id %>"> <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> </a>
<div class="content"> <div class="content">
...@@ -80,8 +73,7 @@ ...@@ -80,8 +73,7 @@
<% if(public && author.id != current_user.id) { %> <% if(public && author.id != current_user.id) { %>
<% if(root) { <% if(root) {
var rootGuid = root.guid; var rootGuid = root.guid;
} } else {
else {
var rootGuid = guid; 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"> <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 @@ ...@@ -98,8 +90,8 @@
<div class="likes on_post"> <div class="likes on_post">
<div class="likes_container"> <div class="likes_container">
<% if(likes_count > 0){ %> <% if(likes_count > 0){ %>
<img alt="Heart" src="/images/icons/heart.png?1322618579"> <img alt="Heart" src="/images/icons/heart.png">
<a href="/posts/<%= id %>/likes" class="expand_likes"> <a href="#" class="expand_likes">
<%= likes_count %> like <%= likes_count %> like
</a> </a>
<% } %> <% } %>
......
...@@ -8,7 +8,8 @@ App.Views.Post = App.Views.StreamObject.extend({ ...@@ -8,7 +8,8 @@ App.Views.Post = App.Views.StreamObject.extend({
"click .shield a": "removeNsfwShield", "click .shield a": "removeNsfwShield",
"click .remove_post": "destroyModel", "click .remove_post": "destroyModel",
"click .like_action": "toggleLike", "click .like_action": "toggleLike",
"click .expand_likes": "expandLikes" "click .expand_likes": "expandLikes",
"click .block_user": "blockUser"
}, },
render: function() { render: function() {
...@@ -123,6 +124,29 @@ App.Views.Post = App.Views.StreamObject.extend({ ...@@ -123,6 +124,29 @@ App.Views.Post = App.Views.StreamObject.extend({
return this; 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){ focusCommentTextarea: function(evt){
evt.preventDefault(); evt.preventDefault();
this.$(".new_comment_form_wrapper").removeClass("hidden"); this.$(".new_comment_form_wrapper").removeClass("hidden");
......
...@@ -3,7 +3,7 @@ App.Views.StreamObject = Backbone.View.extend({ ...@@ -3,7 +3,7 @@ App.Views.StreamObject = Backbone.View.extend({
this.model = options.model; this.model = options.model;
this.template = _.template($(this.template_name).html()); this.template = _.template($(this.template_name).html());
this.model.bind('destroy', this.remove, this); this.model.bind('remove', this.remove, this);
}, },
destroyModel: function(evt){ destroyModel: function(evt){
...@@ -14,5 +14,4 @@ App.Views.StreamObject = Backbone.View.extend({ ...@@ -14,5 +14,4 @@ App.Views.StreamObject = Backbone.View.extend({
remove: function() { remove: function() {
$(this.el).remove(); $(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