Commit 7a649238fb5c72f1d29e47fcc91a32a17300d29f
1 parent
601cc6ba
Exists in
federation_followers
Changes category option on profile following
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Showing
7 changed files
with
51 additions
and
21 deletions
Show diff stats
app/controllers/my_profile/followers_controller.rb
... | ... | @@ -8,7 +8,9 @@ class FollowersController < MyProfileController |
8 | 8 | if request.method == "GET" |
9 | 9 | render :partial => "set_category_modal", :locals => { :followed_profile_id => params[:followed_profile_id] } |
10 | 10 | elsif request.method == "POST" |
11 | + params[:followed_profile_id] ||= profile.id | |
11 | 12 | follower = ProfileFollower.find_by(follower_id: current_person.id, profile_id: params[:followed_profile_id]) |
13 | + | |
12 | 14 | follower.update_attributes(:group => params[:category_name]) if follower |
13 | 15 | redirect_to url_for(:controller => "followers", :action => "index") |
14 | 16 | end | ... | ... |
app/controllers/public/profile_controller.rb
... | ... | @@ -159,8 +159,13 @@ class ProfileController < PublicController |
159 | 159 | if !current_person.follows?(profile) |
160 | 160 | group = params['follow'] ? params['follow']['category'] : '' |
161 | 161 | current_person.follow(profile, group) |
162 | + | |
163 | + categories = ["Friends", "Family", "Work", "Interesting"] | |
164 | + render :partial => 'blocks/profile_info_actions/follow_categories', :locals => { :categories => categories } | |
165 | + else | |
166 | + # TODO return error | |
167 | + return "error" | |
162 | 168 | end |
163 | - redirect_to profile.url | |
164 | 169 | end |
165 | 170 | |
166 | 171 | def unfollow | ... | ... |
app/views/blocks/profile_info_actions/_follow_categories.html.erb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +<div class="follow-categories"> | |
2 | +<p><%= _("You can set a category for %s") % profile.name %></p> | |
3 | + <% categories.each do |category| %> | |
4 | + <div class="category"> | |
5 | + <a href="<%= url_for(:controller => 'followers', :action => 'set_category') %>" class="action-change-category"> | |
6 | + <span><%= category %></span> | |
7 | + </a> | |
8 | + </div> | |
9 | + <% end %> | |
10 | +</div> | ... | ... |
app/views/blocks/profile_info_actions/_person.html.erb
... | ... | @@ -11,12 +11,9 @@ |
11 | 11 | <% if user.follows?(profile) %> |
12 | 12 | <%= button(:unfollow, content_tag('span', _('Unfollow')), {:profile => profile.identifier, :controller => 'profile', :action => 'unfollow'}) %> |
13 | 13 | <% else %> |
14 | - <form id="follower-container" action="<%= url_for({:profile => profile.identifier, :controller => 'profile', :action => 'follow'}) %>"> | |
15 | - <div id="category-form" style="display: none;"> | |
16 | - <%= labelled_text_field _("Choose a category: "), "follow[category]" %> | |
17 | - </div> | |
18 | - <%= submit_button('follow', _('Follow')) %> | |
19 | - </form> | |
14 | + <%= button(:follow, content_tag('span', _('Follow')), {:profile => profile.identifier, :controller => 'profile', :action => 'follow'}, :class => 'action-follow') %> | |
15 | + <div id="follow-categories-container" style="display: none;"> | |
16 | + </div> | |
20 | 17 | <% end %> |
21 | 18 | </li> |
22 | 19 | ... | ... |
public/javascripts/followers.js
1 | -$("#follower-container").live("mouseenter", function() { | |
2 | - $("#category-form").fadeIn(); | |
3 | -}).live("mouseleave", function() { | |
4 | - $("#category-form").fadeOut(); | |
1 | +$(".action-follow").live("click", function() { | |
2 | + var button = $(this); | |
3 | + var url = button.attr("href"); | |
4 | + | |
5 | + // TODO: add progress cursor and error handling | |
6 | + $.post(url, function(data) { | |
7 | + button.fadeOut('fast', function() { | |
8 | + $("#follow-categories-container").html(data); | |
9 | + $("#follow-categories-container").fadeIn(); | |
10 | + }); | |
11 | + }); | |
12 | + | |
13 | + return false; | |
14 | +}); | |
15 | + | |
16 | +$(".action-change-category").live("click", function() { | |
17 | + var category = $(this).text().trim(); | |
18 | + var url = $(this).attr("href"); | |
19 | + | |
20 | + // TODO: add progress cursor and error handling | |
21 | + $.post(url, { 'category_name': category }, function(data) { | |
22 | + $("#follow-categories-container").fadeOut(); | |
23 | + }); | |
24 | + | |
25 | + return false; | |
5 | 26 | }); | ... | ... |
public/stylesheets/blocks/profile-info.scss
... | ... | @@ -99,16 +99,11 @@ |
99 | 99 | margin: 0px 0px 5px 0px; |
100 | 100 | padding: 2px; |
101 | 101 | } |
102 | -#follower-container:hover { | |
102 | +#follow-categories-container { | |
103 | 103 | background-color: #eee; |
104 | - -o-transition:.5s; | |
105 | - -ms-transition:.5s; | |
106 | - -moz-transition:.5s; | |
107 | - -webkit-transition:.5s; | |
108 | - transition:.5s; | |
109 | - padding-top: 5px; | |
110 | - padding-bottom: 5px; | |
104 | + padding: 5px; | |
111 | 105 | } |
112 | -#follower-container #category-form { | |
106 | +#follow-categories-container p { | |
107 | + font-size: 12px; | |
113 | 108 | margin-bottom: 5px; |
114 | 109 | } | ... | ... |
test/functional/followers_controller_test.rb
... | ... | @@ -12,7 +12,7 @@ class FollowersControllerTest < ActionController::TestCase |
12 | 12 | fast_create(ProfileFollower, :profile_id => person.id, :follower_id => @profile.id) |
13 | 13 | |
14 | 14 | get :index, :profile => @profile.identifier |
15 | - assert_includes assigns(:followed_people), person | |
15 | + assert_includes assigns(:followed_people), person | |
16 | 16 | end |
17 | 17 | |
18 | 18 | should 'redirect to login page if not logged in' do | ... | ... |