From 7afb8e5a75667f08932e8c27178229ac40ccad4f Mon Sep 17 00:00:00 2001 From: Moises Machado Date: Thu, 12 Mar 2009 16:48:32 -0300 Subject: [PATCH] ActionItem959: fixed the "join this group?" popup --- app/controllers/public/profile_controller.rb | 7 +++++++ app/helpers/application_helper.rb | 11 ++++++++++- app/models/person.rb | 1 + app/views/shared/join_community_popup.rhtml | 4 ++-- public/stylesheets/common.css | 9 +++++---- test/functional/profile_controller_test.rb | 16 ++++++++++++++++ test/unit/application_helper_test.rb | 12 ++++++++++++ test/unit/person_test.rb | 8 ++++++++ 8 files changed, 61 insertions(+), 7 deletions(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index a116966..1935ea0 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -62,6 +62,13 @@ class ProfileController < PublicController redirect_to profile.url end + def refuse_for_now + session[:no_asking] ||= [] + session[:no_asking].shift if session[:no_asking].size >= 10 + session[:no_asking] << profile.id + render :text => '', :layout => false + end + protected def check_access_to_profile diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6d5a93c..2e008bd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -245,6 +245,12 @@ module ApplicationHelper link_to_function(content_tag('span', label), js_code, html_options, &block) end + def button_to_remote(type, label, options, html_options = {}) + html_options[:class] = "button with-text" unless html_options[:class] + html_options[:class] << " icon-#{type}" + link_to_remote(label, options, html_options) + end + def button_to_remote_without_text(type, label, options, html_options = {}) html_options[:class] = "" unless html_options[:class] html_options[:class] << " button icon-#{type}" @@ -771,7 +777,10 @@ module ApplicationHelper def ask_to_join? return if environment.enabled?(:disable_join_community_popup) return unless profile && profile.kind_of?(Community) - return true unless logged_in? + unless logged_in? + return !session[:no_asking].include?(profile.id) if session[:no_asking] + return true + end user.ask_to_join?(profile) end diff --git a/app/models/person.rb b/app/models/person.rb index 7c59291..23dead7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -229,6 +229,7 @@ class Person < Profile def ask_to_join?(community) return false if memberships.include?(community) + return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) !refused_communities.include?(community) end diff --git a/app/views/shared/join_community_popup.rhtml b/app/views/shared/join_community_popup.rhtml index 2d72374..34952ae 100644 --- a/app/views/shared/join_community_popup.rhtml +++ b/app/views/shared/join_community_popup.rhtml @@ -7,8 +7,8 @@ <% else %> <%= button(:ok, _('Yes'), :controller => 'profile', :action => 'join', :profile => profile.identifier) %> <% end %> - <%= button_to_function(:cancel, _('Not now'), "$('join-community-popup').hide()") %> - <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) %> + <%= button_to_remote(:cancel, _('Not now'), :url => {:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}, :loaded => '$("join-community-popup").hide()') %> + <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> <% end %> <%= draggable_element('join-community-popup') %> diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index e525a27..52a6a8d 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -423,15 +423,12 @@ div.pending-tasks { #join-community-popup { z-index: 150; position: absolute; - width: 350px; + width: 405px; height: 180; right: 50px; top: 50px; background: white; border: 2px solid black; -} - -#join-community-popup { text-align: center; cursor: move; } @@ -439,6 +436,10 @@ div.pending-tasks { margin: 1em; } +#join-community-popup .button-bar .button { + float: none; +} + #content #not-found, #content #access-denied { padding: 20px; diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index c59f5d6..d41d1d4 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -483,4 +483,20 @@ class ProfileControllerTest < Test::Unit::TestCase assert_includes p.refused_communities, community end + should 'register in session join refusal' do + community = Community.create!(:name => 'my test community') + get :refuse_for_now, :profile => community.identifier + + assert_not_nil session[:no_asking] + assert_includes session[:no_asking], community.id + end + + should 'record only 10 communities in session' do + @request.session[:no_asking] = (1..10).to_a + community = Community.create!(:name => 'my test community') + get :refuse_for_now, :profile => community.identifier + + assert_equal ((2..10).to_a + [community.id]), @request.session[:no_asking] + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index ddb5828..c7ab7d9 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -420,6 +420,18 @@ class ApplicationHelperTest < Test::Unit::TestCase assert !ask_to_join? end + should 'not ask_to_join if its recorded in the session' do + e = Environment.default + e.stubs(:enabled?).with(:disable_join_community_popup).returns(false) + stubs(:environment).returns(e) + + c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + stubs(:profile).returns(c) + stubs(:logged_in?).returns(false) + stubs(:session).returns({:no_asking => [c.id]}) + + assert !ask_to_join? + end protected diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 487c84c..1e26eaa 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -526,4 +526,12 @@ class PersonTest < Test::Unit::TestCase assert !p.ask_to_join?(c) end + should 'not ask to join if already asked' do + p = create_user('test_user').person + c = Community.create!(:name => 'Test community', :identifier => 'test_community') + AddMember.create!(:person => p, :organization => c) + + assert !p.ask_to_join?(c) + end + end -- libgit2 0.21.2