Commit 7afb8e5a75667f08932e8c27178229ac40ccad4f
Committed by
Antonio Terceiro
1 parent
622183ea
Exists in
master
and in
29 other branches
ActionItem959: fixed the "join this group?" popup
it doesn't show if the user already asked to join but was not approved yet it stores the "not now" option in the session and is limited to 10 communities the "no and don't ask again" button now only show to logged on users changed the css to centralize the buttons to box changed the css to not break the buttons in half
Showing
8 changed files
with
61 additions
and
7 deletions
Show diff stats
app/controllers/public/profile_controller.rb
... | ... | @@ -62,6 +62,13 @@ class ProfileController < PublicController |
62 | 62 | redirect_to profile.url |
63 | 63 | end |
64 | 64 | |
65 | + def refuse_for_now | |
66 | + session[:no_asking] ||= [] | |
67 | + session[:no_asking].shift if session[:no_asking].size >= 10 | |
68 | + session[:no_asking] << profile.id | |
69 | + render :text => '', :layout => false | |
70 | + end | |
71 | + | |
65 | 72 | protected |
66 | 73 | |
67 | 74 | def check_access_to_profile | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -245,6 +245,12 @@ module ApplicationHelper |
245 | 245 | link_to_function(content_tag('span', label), js_code, html_options, &block) |
246 | 246 | end |
247 | 247 | |
248 | + def button_to_remote(type, label, options, html_options = {}) | |
249 | + html_options[:class] = "button with-text" unless html_options[:class] | |
250 | + html_options[:class] << " icon-#{type}" | |
251 | + link_to_remote(label, options, html_options) | |
252 | + end | |
253 | + | |
248 | 254 | def button_to_remote_without_text(type, label, options, html_options = {}) |
249 | 255 | html_options[:class] = "" unless html_options[:class] |
250 | 256 | html_options[:class] << " button icon-#{type}" |
... | ... | @@ -771,7 +777,10 @@ module ApplicationHelper |
771 | 777 | def ask_to_join? |
772 | 778 | return if environment.enabled?(:disable_join_community_popup) |
773 | 779 | return unless profile && profile.kind_of?(Community) |
774 | - return true unless logged_in? | |
780 | + unless logged_in? | |
781 | + return !session[:no_asking].include?(profile.id) if session[:no_asking] | |
782 | + return true | |
783 | + end | |
775 | 784 | user.ask_to_join?(profile) |
776 | 785 | end |
777 | 786 | ... | ... |
app/models/person.rb
... | ... | @@ -229,6 +229,7 @@ class Person < Profile |
229 | 229 | |
230 | 230 | def ask_to_join?(community) |
231 | 231 | return false if memberships.include?(community) |
232 | + return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) | |
232 | 233 | !refused_communities.include?(community) |
233 | 234 | end |
234 | 235 | ... | ... |
app/views/shared/join_community_popup.rhtml
... | ... | @@ -7,8 +7,8 @@ |
7 | 7 | <% else %> |
8 | 8 | <%= button(:ok, _('Yes'), :controller => 'profile', :action => 'join', :profile => profile.identifier) %> |
9 | 9 | <% end %> |
10 | - <%= button_to_function(:cancel, _('Not now'), "$('join-community-popup').hide()") %> | |
11 | - <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) %> | |
10 | + <%= button_to_remote(:cancel, _('Not now'), :url => {:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}, :loaded => '$("join-community-popup").hide()') %> | |
11 | + <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> | |
12 | 12 | <% end %> |
13 | 13 | </div> |
14 | 14 | <%= draggable_element('join-community-popup') %> | ... | ... |
public/stylesheets/common.css
... | ... | @@ -423,15 +423,12 @@ div.pending-tasks { |
423 | 423 | #join-community-popup { |
424 | 424 | z-index: 150; |
425 | 425 | position: absolute; |
426 | - width: 350px; | |
426 | + width: 405px; | |
427 | 427 | height: 180; |
428 | 428 | right: 50px; |
429 | 429 | top: 50px; |
430 | 430 | background: white; |
431 | 431 | border: 2px solid black; |
432 | -} | |
433 | - | |
434 | -#join-community-popup { | |
435 | 432 | text-align: center; |
436 | 433 | cursor: move; |
437 | 434 | } |
... | ... | @@ -439,6 +436,10 @@ div.pending-tasks { |
439 | 436 | margin: 1em; |
440 | 437 | } |
441 | 438 | |
439 | +#join-community-popup .button-bar .button { | |
440 | + float: none; | |
441 | +} | |
442 | + | |
442 | 443 | #content #not-found, |
443 | 444 | #content #access-denied { |
444 | 445 | padding: 20px; | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -483,4 +483,20 @@ class ProfileControllerTest < Test::Unit::TestCase |
483 | 483 | assert_includes p.refused_communities, community |
484 | 484 | end |
485 | 485 | |
486 | + should 'register in session join refusal' do | |
487 | + community = Community.create!(:name => 'my test community') | |
488 | + get :refuse_for_now, :profile => community.identifier | |
489 | + | |
490 | + assert_not_nil session[:no_asking] | |
491 | + assert_includes session[:no_asking], community.id | |
492 | + end | |
493 | + | |
494 | + should 'record only 10 communities in session' do | |
495 | + @request.session[:no_asking] = (1..10).to_a | |
496 | + community = Community.create!(:name => 'my test community') | |
497 | + get :refuse_for_now, :profile => community.identifier | |
498 | + | |
499 | + assert_equal ((2..10).to_a + [community.id]), @request.session[:no_asking] | |
500 | + end | |
501 | + | |
486 | 502 | end | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -420,6 +420,18 @@ class ApplicationHelperTest < Test::Unit::TestCase |
420 | 420 | assert !ask_to_join? |
421 | 421 | end |
422 | 422 | |
423 | + should 'not ask_to_join if its recorded in the session' do | |
424 | + e = Environment.default | |
425 | + e.stubs(:enabled?).with(:disable_join_community_popup).returns(false) | |
426 | + stubs(:environment).returns(e) | |
427 | + | |
428 | + c = Community.create(:name => 'test_comm', :identifier => 'test_comm') | |
429 | + stubs(:profile).returns(c) | |
430 | + stubs(:logged_in?).returns(false) | |
431 | + stubs(:session).returns({:no_asking => [c.id]}) | |
432 | + | |
433 | + assert !ask_to_join? | |
434 | + end | |
423 | 435 | |
424 | 436 | protected |
425 | 437 | ... | ... |
test/unit/person_test.rb
... | ... | @@ -526,4 +526,12 @@ class PersonTest < Test::Unit::TestCase |
526 | 526 | assert !p.ask_to_join?(c) |
527 | 527 | end |
528 | 528 | |
529 | + should 'not ask to join if already asked' do | |
530 | + p = create_user('test_user').person | |
531 | + c = Community.create!(:name => 'Test community', :identifier => 'test_community') | |
532 | + AddMember.create!(:person => p, :organization => c) | |
533 | + | |
534 | + assert !p.ask_to_join?(c) | |
535 | + end | |
536 | + | |
529 | 537 | end | ... | ... |