From 26e5b3d6c63c9359dae7d95ac195ac5f5e008789 Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Wed, 4 May 2016 17:44:48 -0300 Subject: [PATCH] Confirmation modal on join community buttons --- app/controllers/public/profile_controller.rb | 3 +-- app/helpers/memberships_helper.rb | 11 ++++++++--- app/helpers/profile_image_helper.rb | 4 +++- app/views/blocks/profile_info_actions/_join_leave_community.html.erb | 4 ++-- app/views/profile/_private_profile.html.erb | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 6f196d6..cccc352 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -94,8 +94,7 @@ class ProfileController < PublicController def join if !user.memberships.include?(profile) - return if profile.community? && profile.requires_email && - current_person && !current_person.public_fields.include?("email") + return if profile.community? && show_confirmation_modal?(profile) profile.add_member(user) if !profile.members.include?(user) diff --git a/app/helpers/memberships_helper.rb b/app/helpers/memberships_helper.rb index 0d83749..3777871 100644 --- a/app/helpers/memberships_helper.rb +++ b/app/helpers/memberships_helper.rb @@ -1,12 +1,17 @@ module MembershipsHelper - def join_community_button(logged) - url = logged ? profile.join_url : profile.join_not_logged_url + def join_community_button options={:logged => false} + url = options[:logged] ? profile.join_url : profile.join_not_logged_url - if profile.requires_email? && current_person && !current_person.public_fields.include?("email") + if show_confirmation_modal? profile modal_button :add, _('Join this community'), url, class: 'join-community' else button :add, _('Join this community'), url, class: 'join-community' end end + + def show_confirmation_modal? profile + profile.requires_email? && current_person && !current_person.public_fields.include?("email") + end + end diff --git a/app/helpers/profile_image_helper.rb b/app/helpers/profile_image_helper.rb index 7889bcb..8763644 100644 --- a/app/helpers/profile_image_helper.rb +++ b/app/helpers/profile_image_helper.rb @@ -61,6 +61,8 @@ module ProfileImageHelper image_tag(profile_icon(profile, size), opt ) end + include MembershipsHelper + def links_for_balloon(profile) if environment.enabled?(:show_balloon_with_profile_links_when_clicked) if profile.kind_of?(Person) @@ -76,7 +78,7 @@ module ProfileImageHelper {_('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', :style => 'display: none'}}, + {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community'+ (show_confirmation_modal?(profile) ? ' modal-toggle' : '') , :style => 'display: none'}}, {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}}, {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}} ] diff --git a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb index 6933e7b..4c2bfcf 100644 --- a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb +++ b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb @@ -8,11 +8,11 @@ class: 'leave-community', style: 'position: relative;' %> <% else %> - <%= join_community_button(true) %> + <%= join_community_button({:logged => true}) %> <% end %> <% end %> <% else %> - <%= join_community_button(false) %> + <%= join_community_button %> <% end %> diff --git a/app/views/profile/_private_profile.html.erb b/app/views/profile/_private_profile.html.erb index 1f0205c..730cd22 100644 --- a/app/views/profile/_private_profile.html.erb +++ b/app/views/profile/_private_profile.html.erb @@ -7,7 +7,7 @@ <% button_bar do %> <% if @action == :join && logged_in? %> - <%= button(:add, content_tag('span', _('Join')), profile.join_url, :class => 'join-community', :title => _("Join community"), :style => 'position: relative;') %> + <%= join_community_button({:logged => true}) %> <% end %> <% if @action == :add_friend && logged_in? && !user.already_request_friendship?(profile) %> <%= button(:add, content_tag('span', _('Add friend')), profile.add_url, :class => 'add-friend', :title => _("Add friend"), :style => 'position: relative;') %> -- libgit2 0.21.2