From b94b5240a8910db5acb8aeff26ccd76eab4988b0 Mon Sep 17 00:00:00 2001 From: danielgrippi <danielgrippi@gmail.com> Date: Thu, 15 Dec 2011 17:40:27 -0800 Subject: [PATCH] added block user functionality to the stream --- app/controllers/blocks_controller.rb | 14 ++++++++-- app/views/templates/comment.ujs | 5 +--- app/views/templates/stream_element.ujs | 20 +++++--------- public/javascripts/app/views/post_view.js | 26 ++++++++++++++++++- .../app/views/stream_object_view.js | 3 +-- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index 1065bd103f..7f7fa5891f 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -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 diff --git a/app/views/templates/comment.ujs b/app/views/templates/comment.ujs index 54062b689a..cb5e281f8f 100644 --- a/app/views/templates/comment.ujs +++ b/app/views/templates/comment.ujs @@ -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> diff --git a/app/views/templates/stream_element.ujs b/app/views/templates/stream_element.ujs index 3d63acb48f..1ad9f59912 100644 --- a/app/views/templates/stream_element.ujs +++ b/app/views/templates/stream_element.ujs @@ -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> <% } %> diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 73e310ce60..dd58bce846 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -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"); diff --git a/public/javascripts/app/views/stream_object_view.js b/public/javascripts/app/views/stream_object_view.js index 793dd35eaa..5ffad02c8f 100644 --- a/public/javascripts/app/views/stream_object_view.js +++ b/public/javascripts/app/views/stream_object_view.js @@ -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(); } - }); -- GitLab