diff --git a/app/helpers/box_organizer_helper.rb b/app/helpers/box_organizer_helper.rb index cccdcd7..ba05552 100644 --- a/app/helpers/box_organizer_helper.rb +++ b/app/helpers/box_organizer_helper.rb @@ -4,4 +4,10 @@ module BoxOrganizerHelper render :partial => 'icon_selector', :locals => { :icon => icon } end -end + def extra_option_checkbox(option) + if [:human_name, :name, :value, :checked, :options].all? {|k| option.key? k} + labelled_check_box(option[:human_name], option[:name], option[:value], option[:checked], option[:options]) + end + end + +end \ No newline at end of file diff --git a/app/models/members_block.rb b/app/models/members_block.rb index f13dfc0..c0dbcd5 100644 --- a/app/models/members_block.rb +++ b/app/models/members_block.rb @@ -1,4 +1,5 @@ class MembersBlock < ProfileListBlock + settings_items :show_join_leave_button, :type => :boolean, :default => false def self.description _('Members') @@ -14,8 +15,15 @@ class MembersBlock < ProfileListBlock def footer profile = self.owner + show_button_block = show_join_leave_button + lambda do - link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' + if show_button_block + @view_all = link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' + render "blocks/profile_info_actions/join_leave_community" + else + link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' + end end end @@ -23,4 +31,14 @@ class MembersBlock < ProfileListBlock owner.members end -end + def extra_option + data = { + :human_name => _("Show join leave button"), + :name => 'block[show_join_leave_button]', + :value => true, + :checked => show_join_leave_button, + :options => {} + } + end + +end \ No newline at end of file diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index 4316c90..36ed38f 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -62,4 +62,8 @@ class ProfileListBlock < Block title.gsub('{#}', profile_count.to_s) end + # override in subclasses! See MembersBlock for exemple + def extra_option + {} + end end diff --git a/app/views/blocks/profile_info_actions/_join_leave_community.rhtml b/app/views/blocks/profile_info_actions/_join_leave_community.rhtml new file mode 100644 index 0000000..b8b52e1 --- /dev/null +++ b/app/views/blocks/profile_info_actions/_join_leave_community.rhtml @@ -0,0 +1,29 @@ +<%= @view_all unless @view_all.nil? %> + +<% if logged_in? %> + <% if profile.members.include?(user) %> + <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, + :class => 'leave-community', + :title => _("Leave community"), + :style => 'position: relative;') %> + <%= button(:add, content_tag('span', __('Join')), profile.join_url, + :class => 'join-community', + :title => _("Join community"), + :style => 'position: relative; display: none;') %> + <% else %> + <% unless profile.already_request_membership?(user) %> + <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, + :class => 'leave-community', + :title => _("Leave community"), + :style => 'position: relative; display: none;') %> + <%= button(:add, content_tag('span', __('Join')), profile.join_url, + :class => 'join-community', + :title => _("Join community"), + :style => 'position: relative;') %> + <% end %> + <% end %> +<% else %> + <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, + :class => 'button with-text icon-add', + :title => _('Join this community') %> +<% end %> \ No newline at end of file diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml index 96cb8f7..d92bf90 100644 --- a/app/views/blocks/profile_info_actions/community.rhtml +++ b/app/views/blocks/profile_info_actions/community.rhtml @@ -1,31 +1,8 @@ + \ No newline at end of file diff --git a/app/views/box_organizer/_profile_list_block.rhtml b/app/views/box_organizer/_profile_list_block.rhtml index 21c1511..5ca4958 100644 --- a/app/views/box_organizer/_profile_list_block.rhtml +++ b/app/views/box_organizer/_profile_list_block.rhtml @@ -2,5 +2,8 @@ <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> <%= check_box(:block, :prioritize_profiles_with_image) %> - +
+ <%= extra_option_checkbox(@block.extra_option) %> +
+ \ No newline at end of file diff --git a/features/members_block.feature b/features/members_block.feature new file mode 100644 index 0000000..b595d5c --- /dev/null +++ b/features/members_block.feature @@ -0,0 +1,55 @@ +Feature: + In order to enter in a community + As a logged user + I want to enter in a community by 'join leave' button in members block + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + | mariasilva | Maria Silva | + And the following communities + | owner | identifier | name | + | joaosilva | sample-community | Sample Community | + And the following blocks + | owner | type | + | sample-community | MembersBlock | + And I am logged in as "joaosilva" + And I go to sample-community's control panel + And I follow "Edit sideboxes" + And I follow "Edit" within ".members-block" + And I check "Show join leave button" + And I press "Save" + + Scenario: a user can join in a community by members block's button + Given I am logged in as "mariasilva" + And I go to sample-community's homepage + When I follow "Join" within ".members-block" + And I go to mariasilva's control panel + And I follow "Manage my groups" + Then I should see "Sample Community" + + Scenario: a user can leave a community by members block's button + Given "Maria Silva" is a member of "Sample Community" + And I am logged in as "mariasilva" + When I go to sample-community's homepage + And I follow "Leave community" within ".members-block" + And I go to mariasilva's control panel + And I follow "Manage my groups" + Then I should not see "Sample Community" + + Scenario: a not logged in user can log in by members block's button + Given I am not logged in + When I go to sample-community's homepage + And I follow "Join" within ".members-block" + Then I should see "Username / Email" + + Scenario: the join-leave button do not appear if the checkbox show-join-leave-button is not checked + And I go to sample-community's control panel + And I follow "Edit sideboxes" + And I follow "Edit" within ".members-block" + And I uncheck "Show join leave button" + And I press "Save" + When I go to sample-community's homepage + Then I should not see "Join" within ".members-block" + And I should not see "Leave community" within ".members-block" diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index 0108560..5234410 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -506,7 +506,6 @@ div#notice { #content .people-block .block-footer-content a, #content .profile-list-block .block-footer-content a, #content .enterprises-block .block-footer-content a, -#content .members-block .block-footer-content a, #content .communities-block .block-footer-content a, #content .friends-block .block-footer-content a { position: absolute; @@ -518,6 +517,32 @@ div#notice { padding-right: 15px; background: url(imgs/arrow-right-p.png) 100% 50% no-repeat; } +#content .members-block .block-footer-content a { + position: absolute; + top: 2px; + right: 0px; + font-size: 11px; + color: #000; + text-decoration: none; + padding-right: 15px; +} +#content .members-block .block-footer-content a.button { + position: relative; + padding-left: 10px; + background-color: #EEE; + border: 1px solid #CCC; + color: #555; +} +#content .members-block .block-footer-content a.button:hover { + color: #FFF; + background-color: #555; + border: 1px solid #2e3436; + text-decoration: none; +} +#content .members-block .block-footer-content a.button span { + margin: 0px; + padding: 0px 0px 0px 7px; +} #content .profile-list-block .block-title { text-align: left; diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js index db5a4b9..551ec8d 100644 --- a/public/javascripts/add-and-join.js +++ b/public/javascripts/add-and-join.js @@ -12,7 +12,7 @@ jQuery(function($) { }) $(".join-community").live('click', function(){ - clicked = $(this) + clicked = $(".join-community"); url = clicked.attr("href"); loading_for_button(this); $.post(url, function(data){ @@ -29,7 +29,7 @@ jQuery(function($) { }) $(".leave-community").live('click', function(){ - clicked = $(this) + clicked = $(".leave-community"); url = clicked.attr("href"); loading_for_button(this); $.post(url, function(data){ diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb index d4e877a..854720f 100644 --- a/test/unit/members_block_test.rb +++ b/test/unit/members_block_test.rb @@ -39,4 +39,3 @@ class MembersBlockTest < ActiveSupport::TestCase end end - -- libgit2 0.21.2