From 2a970145c811ba63b903c092f63f800af600b392 Mon Sep 17 00:00:00 2001 From: Andrej Kacian Date: Fri, 29 Jul 2011 18:00:37 +0200 Subject: [PATCH] Added icon to directly unfollow a tag to listing of followed tags. --- app/controllers/tag_followings_controller.rb | 18 +++++++++++++++--- app/views/aspects/index.html.haml | 2 +- app/views/tags/_followed_tags_listings.haml | 4 +++- app/views/tags/update.js.erb | 1 + config/assets.yml | 1 + config/locales/diaspora/en.yml | 1 + public/javascripts/tag-followings.js | 18 ++++++++++++++++++ public/stylesheets/sass/application.sass | 6 +++++- 8 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 app/views/tags/update.js.erb create mode 100644 public/javascripts/tag-followings.js diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index 61ba13a74..fab373942 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -22,11 +22,23 @@ class TagFollowingsController < ApplicationController @tag = ActsAsTaggableOn::Tag.find_by_name(params[:name]) @tag_following = current_user.tag_followings.where(:tag_id => @tag.id).first if @tag_following && @tag_following.destroy - flash[:notice] = I18n.t('tag_followings.destroy.success', :name => params[:name]) + @tag_unfollowed = true else - flash[:error] = I18n.t('tag_followings.destroy.failure', :name => params[:name]) + @tag_unfollowed = false end - redirect_to tag_path(:name => params[:name]) + if params[:remote] + respond_to do |format| + format.all{} + format.js{ render 'tags/update' } + end + else + if @tag_unfollowed + flash[:notice] = I18n.t('tag_followings.destroy.success', :name => params[:name]) + else + flash[:error] = I18n.t('tag_followings.destroy.failure', :name => params[:name]) + end + redirect_to tag_path(:name => params[:name]) + end end end diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index ddd0e747a..49b914991 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -21,7 +21,7 @@ .section = render 'aspects/aspect_listings' - .section + .section#followed_tags_listing = render 'tags/followed_tags_listings' .span-13.append-1 diff --git a/app/views/tags/_followed_tags_listings.haml b/app/views/tags/_followed_tags_listings.haml index 988d55bcb..cf3e6ce71 100644 --- a/app/views/tags/_followed_tags_listings.haml +++ b/app/views/tags/_followed_tags_listings.haml @@ -10,7 +10,9 @@ %ul.sub_nav - if current_user.followed_tags.size > 0 - for tg in current_user.followed_tags - %li + %li.unfollow{:id => tg.name} + .unfollow_icon.hidden + = link_to image_tag("icons/monotone_close_exit_delete.png", :height => 12), tag_tag_followings_path(:name => tg.name, :remote => true), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :id => "unfollow_" + tg.name =link_to "##{tg.name}", tag_path(:name => tg.name), :class => "tag_selector" - else %li diff --git a/app/views/tags/update.js.erb b/app/views/tags/update.js.erb new file mode 100644 index 000000000..84f8200dc --- /dev/null +++ b/app/views/tags/update.js.erb @@ -0,0 +1 @@ +$("#followed_tags_listing").first().html("<%= escape_javascript(render('tags/followed_tags_listings')) =%>"); diff --git a/config/assets.yml b/config/assets.yml index d8a16bd96..f45144dbf 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -70,6 +70,7 @@ javascripts: - public/javascripts/publisher.js - public/javascripts/aspect-filters.js - public/javascripts/aspect-edit-pane.js + - public/javascripts/tag-followings.js - public/javascripts/fileuploader-custom.js people: - public/javascripts/vendor/jquery.autoSuggest.custom.js diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 27510a19c..a700d4c30 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -158,6 +158,7 @@ en: your_aspects: "Your Aspects" tags_following: "Followed Tags" no_tags: "+ Find a tag to follow" + unfollow_tag: "Stop following #%{tag}" handle_explanation: "This is your diaspora id. Like an email address, you can give this to people to reach you." no_contacts: "No contacts" post_a_message: "post a message >>" diff --git a/public/javascripts/tag-followings.js b/public/javascripts/tag-followings.js new file mode 100644 index 000000000..e3d271855 --- /dev/null +++ b/public/javascripts/tag-followings.js @@ -0,0 +1,18 @@ +/* Copyright (c) 2011, Diaspora Inc. This file is +* licensed under the Affero General Public License version 3 or later. See +* the COPYRIGHT file. +*/ + +var TagFollowings = { + initialize: function(){ + $('.unfollow').live('mouseover', function(){ + $(this).find('.unfollow_icon').removeClass('hidden'); + }).live('mouseout', function(){ + $(this).find('.unfollow_icon').addClass('hidden'); + }); + } +}; + +$(document).ready(function() { + TagFollowings.initialize(); +}); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index f59519843..bd4bc65ae 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2902,9 +2902,13 @@ ul.left_nav :color #666 .contact_count, - .edit + .edit, + .unfollow_icon :float right + .unfollow_icon + :margin-top 4px + .edit :margin-top 4px :display none