diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 3eb0774..21f812b 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -8,18 +8,6 @@ class FriendsController < MyProfileController end end - def add - @friend = Person.find(params[:id]) - if request.post? && params[:confirmation] - # FIXME this shouldn't be in Person model? - AddFriend.create!(:person => profile, :friend => @friend, :group_for_person => params[:group]) - - session[:notice] = _('%s still needs to accept being your friend.') % @friend.name - # FIXME shouldn't redirect to the friend's page? - redirect_to :action => 'index' - end - end - def remove @friend = profile.friends.find(params[:id]) if request.post? && params[:confirmation] diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 45b83df..ac3ede9 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -1,9 +1,9 @@ class ProfileController < PublicController needs_profile - before_filter :check_access_to_profile, :except => [:join, :index] - before_filter :store_before_join, :only => [:join] - before_filter :login_required, :only => [:join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities] + before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index] + before_filter :store_before_join, :only => [:join, :join_not_logged] + before_filter :login_required, :only => [:join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities] helper TagsHelper @@ -82,18 +82,26 @@ class ProfileController < PublicController end def join - @wizard = params[:wizard] - if request.post? && params[:confirmation] - profile.add_member(current_user.person) - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? - if @wizard - redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + if !user.memberships.include?(profile) + profile.add_member(user) + if profile.closed? + render :text => _('%s administrator still needs to accept you as member.') % profile.name else - redirect_to_before_join + render :text => _('You just became a member of %s.') % profile.name end else - if current_user.person.memberships.include?(profile) - session[:notice] = _('You are already a member of "%s"') % profile.name + render :text => _('You are already a member of %s.') % profile.name + end + end + + def join_not_logged + if request.post? + profile.add_member(user) + session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? + redirect_to_before_join + else + if user.memberships.include?(profile) + session[:notice] = _('You are already a member of %s') % profile.name redirect_to profile.url return end @@ -104,20 +112,37 @@ class ProfileController < PublicController end def leave - @wizard = params[:wizard] - @back_to = params[:back_to] || request.referer - if request.post? && params[:confirmation] + if user.memberships.include?(profile) profile.remove_member(current_user.person) - if @wizard - redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true - else - back = @back_to || profile.url - redirect_to back - end + render :text => _('You just left %s.') % profile.name else - if request.xhr? - render :layout => false - end + render :text => _('You are already a member of %s.') % profile.name + end + end + + def check_membership + if user.memberships.include?(profile) + render :text => 'true' + else + render :text => 'false' + end + end + + def add + # FIXME this shouldn't be in Person model? + if !user.memberships.include?(profile) + AddFriend.create!(:person => user, :friend => profile) + render :text => _('%s still needs to accept being your friend.') % profile.name + else + render :text => _('You are already a friend of %s.') % profile.name + end + end + + def check_friendship + if user == profile || user.already_request_friendship?(profile) || user.is_a_friend?(profile) + render :text => 'true' + else + render :text => 'false' end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4107334..5585336 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -515,24 +515,27 @@ module ApplicationHelper if environment.enabled?(:show_balloon_with_profile_links_when_clicked) if profile.kind_of?(Person) [ - {_('Home Page') => url_for(profile.url)}, - {_('Wall') => url_for(profile.public_profile_url)}, - {_('Friends') => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}, - {_('Communities') => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)} + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, + {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}}, + {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}}, + {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend'}} ] elsif profile.kind_of?(Community) [ - {_('Home Page') => url_for(profile.url)}, - {_('Wall') => url_for(profile.public_profile_url)}, - {_('Members') => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}, - {_('Agenda') => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)} + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, + {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community'}}, + {_('Leave') => {:href => url_for(profile.leave_url), :class => 'leave-community'}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}} ] elsif profile.kind_of?(Enterprise) [ - {_('Home Page') => url_for(profile.url)}, - {_('Products') => catalog_path(profile.identifier)}, - {_('Members') => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}, - {_('Agenda') => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)} + {_('Products') => {:href => catalog_path(profile.identifier)}}, + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}}, ] else [] @@ -543,17 +546,24 @@ module ApplicationHelper # displays a link to the profile homepage with its image (as generated by # #profile_image) and its name below it. def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) - if profile.class == Person - name = profile.short_name + name = profile.short_name + if profile.person? city = content_tag 'span', content_tag( 'span', profile.city, :class => 'locality' ), :class => 'adr' + url = url_for(profile.check_friendship_url) + trigger_class = 'person-trigger' else - name = profile.short_name city = '' + url = url_for(profile.check_membership_url) + if profile.community? + trigger_class = 'community-trigger' + elsif profile.enterprise? + trigger_class = 'enterprise-trigger' + end end extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) links = links_for_balloon(profile) content_tag tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger' ) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + @@ -571,8 +581,9 @@ module ApplicationHelper def community_image_link( profile, size=:portrait, tag='li' ) name = h(profile.name) links = links_for_balloon(profile) + url = url_for(profile.check_membership_url) content_tag tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger' ) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger community-trigger', :url => url) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + content_tag( 'span', name, :class => 'org' ) + diff --git a/app/models/profile.rb b/app/models/profile.rb index 5fdb43a..72c74bb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -426,6 +426,22 @@ class Profile < ActiveRecord::Base { :profile => identifier, :controller => 'profile', :action => 'join' } end + def join_not_logged_url + { :profile => identifier, :controller => 'profile', :action => 'join_not_logged' } + end + + def check_membership_url + { :profile => identifier, :controller => 'profile', :action => 'check_membership' } + end + + def add_url + { :profile => identifier, :controller => 'profile', :action => 'add' } + end + + def check_friendship_url + { :profile => identifier, :controller => 'profile', :action => 'check_friendship' } + end + def public_profile_url generate_url(:profile => identifier, :controller => 'profile', :action => 'index') end diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml index 2629f8d..ce2a063 100644 --- a/app/views/blocks/profile_info_actions/community.rhtml +++ b/app/views/blocks/profile_info_actions/community.rhtml @@ -3,12 +3,14 @@ <% if profile.members.include?(user) %>
-<%= __('Are you sure you want to add %s as your friend?') % @friend.name %> -
- -- -<%= __('Note that %s will need to accept being added as your friend.') % @friend.name %> - -
- -<% form_tag do %> - <%= hidden_field_tag(:confirmation, 1) %> - - - - <%= submit_button(:ok, __("Yes, I want to add %s as my friend") % @friend.name) %> - <%= button(:cancel, _("No, I don't want"), :action => 'index') %> -<% end %> diff --git a/app/views/layouts/_javascript.rhtml b/app/views/layouts/_javascript.rhtml index 9039f0e..086a9c8 100644 --- a/app/views/layouts/_javascript.rhtml +++ b/app/views/layouts/_javascript.rhtml @@ -1 +1 @@ -<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', :cache => 'cache-general' %> +<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', 'add-and-join', :cache => 'cache-general' %> diff --git a/app/views/profile/_private_profile.rhtml b/app/views/profile/_private_profile.rhtml index 1bff167..1d5cae3 100644 --- a/app/views/profile/_private_profile.rhtml +++ b/app/views/profile/_private_profile.rhtml @@ -7,10 +7,10 @@ <% button_bar do %> <% if @action == :join && logged_in? %> - <%= lightbox_link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %> + <%= button(:add, content_tag('span', __('Join')), profile.join_url, :class => 'join-community', :title => _("Join community"), :style => 'position: relative;') %> <% end %> <% if @action == :add_friend && logged_in? && !user.already_request_friendship?(profile) %> - <%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %> + <%= button(:add, content_tag('span', __('Add friend')), profile.add_url, :class => 'add-friend', :title => _("Add friend"), :style => 'position: relative;') %> <% end %> <%= button :back, _('Go back'), :back %> <%= button :home, _("Go to %s home page") % environment.name, :controller => 'home' %> diff --git a/features/balloon.feature b/features/balloon.feature index 6f8dcf9..2a0aea7 100644 --- a/features/balloon.feature +++ b/features/balloon.feature @@ -38,7 +38,6 @@ Feature: balloon When I click ".menu-submenu-trigger" Then I should see "Profile" And I should see "Friends" - And I should see "Home Page" @selenium Scenario: I should see balloon when clicked on community block trigger @@ -71,4 +70,3 @@ Feature: balloon When I click ".menu-submenu-trigger" Then I should see "Members" And I should see "Agenda" - And I should see "Home Page" diff --git a/features/join_community.feature b/features/join_community.feature deleted file mode 100644 index 78d44aa..0000000 --- a/features/join_community.feature +++ /dev/null @@ -1,24 +0,0 @@ -Feature: join a community - As a user - I want to join a community - In order to interact with other people - - Background: - Given the following users - | login | name | - | joaosilva | Joao Silva | - Given the following communities - | identifier | name | - | sample-community | Sample Community | - - Scenario: ask confirmation before join community - Given I am logged in as "joaosilva" - And I am on Sample Community's homepage - When I follow "Join" - Then I should see "Are you sure you want to join Sample Community" - - Scenario: dont ask confirmation before join community if already member - Given joaosilva is member of sample-community - And I am logged in as "joaosilva" - When I go to /profile/sample-community - Then I should not see "Are you sure you want to join Community to join" diff --git a/features/my_network_block.feature b/features/my_network_block.feature index b5ef0fb..09c8e81 100644 --- a/features/my_network_block.feature +++ b/features/my_network_block.feature @@ -23,7 +23,6 @@ Feature: my_network_block Then I should see "2 communities" When I go to Public Community's homepage And I follow "Join" - And I press "Yes, I want to join." When I go to Joao Silva's homepage Then I should see "3 communities" @@ -37,7 +36,6 @@ Feature: my_network_block Then I should see "One community" When I go to Public Community's homepage And I follow "Join" - And I press "Yes, I want to join." When I go to Joao Silva's homepage Then I should see "2 communities" diff --git a/features/private_profile.feature b/features/private_profile.feature index bc6983b..cea107f 100644 --- a/features/private_profile.feature +++ b/features/private_profile.feature @@ -17,7 +17,6 @@ Feature: private profiles When I go to Safernet's homepage Then I should see "members only" When I follow "Join" - And I press "Yes, I want to join" And "joao" is accepted on community "Safernet" Then "joao" should be a member of "Safernet" When I go to Safernet's homepage @@ -27,5 +26,4 @@ Feature: private profiles Given I am logged in as "joao" When I go to shygirl's homepage Then I should see "friends only" - When I follow "Add friend" - And I press "Yes, I want" + And I follow "Add friend" diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js new file mode 100644 index 0000000..ddc4ee5 --- /dev/null +++ b/public/javascripts/add-and-join.js @@ -0,0 +1,94 @@ +jQuery(function($) { + + $(".add-friend").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(); + display_notice(data); + }); + return false; + }) + + $(".join-community").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(function(){ + clicked.css("display","none"); + clicked.parent().parent().find(".leave-community").fadeIn(); + clicked.parent().parent().find(".leave-community").css("display", ""); + }); + clicked.css("cursor",""); + $(".small-loading").remove(); + display_notice(data); + }); + return false; + }) + + $(".leave-community").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(function(){ + clicked.css("display","none"); + clicked.parent().parent().find(".join-community").fadeIn(); + clicked.parent().parent().find(".join-community").css("display", ""); + }); + clicked.css("cursor",""); + $(".small-loading").remove(); + display_notice(data); + }); + return false; + }) + + $(".person-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true"){ + clicked.parent().find(".add-friend").fadeOut(function(){ + clicked.parent().find(".send-an-email").fadeIn(); + }) + } + else if(data == "false"){ + clicked.parent().find(".send-an-email").fadeOut(function(){ + clicked.parent().find(".add-friend").fadeIn(); + }); + } + }) + }) + + $(".community-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true"){ + clicked.parent().find(".join-community").fadeOut(function(){ + clicked.parent().find(".leave-community").fadeIn(); + clicked.parent().find(".send-an-email").fadeIn(); + }); + } + else if(data == "false"){ + clicked.parent().find(".send-an-email").fadeOut(); + clicked.parent().find(".leave-community").fadeOut(function(){ + clicked.parent().find(".join-community").fadeIn(); + }); + } + }) + }) + + $(".enterprise-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true") + clicked.parent().find(".send-an-email").fadeIn(); + else if(data == "false") + clicked.parent().find(".send-an-email").fadeOut(); + }) + }) +}); diff --git a/public/javascripts/application.js b/public/javascripts/application.js index fdd6cda..c614f08 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -263,7 +263,11 @@ function toggleSubmenu(trigger, title, link_list) { content.append('