Commit 7ba0db117c922fa575ef846115e9d1e28d457ad8

Authored by Michel Felipe
1 parent ba467618

Modify invite friend to community feature for add member imediatly, if logged us…

…er is a admin of environment
app/controllers/public/invite_controller.rb
... ... @@ -62,11 +62,27 @@ class InviteController < PublicController
62 62 redirect_to :action => 'invite_friends'
63 63 end
64 64  
  65 + #Invite or add member without create a task
  66 + #if logged user is admin of environment
65 67 def invite_registered_friend
66 68 contacts_to_invite = params['q'].split(',')
67 69 if !contacts_to_invite.empty? && request.post?
68   - Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale)
69   - session[:notice] = _('Your invitations are being sent.')
  70 +
  71 + if user.is_admin?
  72 + person = Person.find(user.id)
  73 + session[:invited_members] = []
  74 +
  75 + Invitation.invite(person, contacts_to_invite, '', profile) do |added_member|
  76 + session[:invited_members] << added_member.id
  77 + end
  78 +
  79 + session[:notice] = _('This friends was added!')
  80 + else
  81 + Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale)
  82 + session[:notice] = _('Your invitations are being sent.')
  83 + end
  84 +
  85 +
70 86 if profile.person?
71 87 redirect_to :controller => 'profile', :action => 'friends'
72 88 else
... ...
app/controllers/public/profile_controller.rb
... ... @@ -64,8 +64,15 @@ class ProfileController &lt; PublicController
64 64 end
65 65  
66 66 def members
  67 + @profiles_focus = []
  68 +
67 69 if is_cache_expired?(profile.members_cache_key(params))
68 70 @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => profile.members.count)
  71 + if session[:invited_members]
  72 + @profiles_focus = session[:invited_members]
  73 +
  74 + session.delete :invited_members
  75 + end
69 76 end
70 77 end
71 78  
... ...
app/helpers/application_helper.rb
... ... @@ -589,14 +589,24 @@ module ApplicationHelper
589 589 trigger_class = 'enterprise-trigger'
590 590 end
591 591 end
592   - extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
  592 +
  593 + extra_info_tag = ''
  594 + img_class = 'profile-image'
  595 +
  596 + if extra_info.is_a? Hash
  597 + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
  598 + img_class +=' '+extra_info[:class]
  599 + else
  600 + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
  601 + end
  602 + #extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
593 603 links = links_for_balloon(profile)
594 604 content_tag('div', content_tag(tag,
595 605 (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") +
596 606 link_to(
597   - content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
  607 + content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
598 608 content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
599   - extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ),
  609 + extra_info_tag + profile_sex_icon( profile ) + profile_cat_icons( profile ),
600 610 profile.url,
601 611 :class => 'profile_link url',
602 612 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
... ...
app/models/invitation.rb
... ... @@ -47,6 +47,7 @@ class Invitation &lt; Task
47 47 end
48 48  
49 49 def self.invite(person, contacts_to_invite, message, profile)
  50 +
50 51 contacts_to_invite.each do |contact_to_invite|
51 52 next if contact_to_invite == _("Firstname Lastname <friend@email.com>")
52 53  
... ... @@ -79,7 +80,23 @@ class Invitation &lt; Task
79 80 if profile.person?
80 81 InviteFriend.create(task_args) if user.nil? || !user.person.is_a_friend?(person)
81 82 elsif profile.community?
82   - InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile)
  83 +
  84 + if person.is_admin?
  85 + unless user.person.is_member_of?(profile)
  86 +
  87 + profile.add_member(user.person)
  88 +
  89 + #Call after add member callback
  90 + yield user
  91 +
  92 + end
  93 + else
  94 +
  95 + InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile)
  96 +
  97 + #Call after create invite member task callback
  98 + yield user,task_args
  99 + end
83 100 else
84 101 raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s
85 102 end
... ...
app/views/profile/members.html.erb
... ... @@ -4,8 +4,12 @@
4 4  
5 5 <% cache_timeout(profile.members_cache_key(params), 4.hours) do %>
6 6 <ul class='profile-list'>
  7 + <!--
  8 + @todo Highlight visual for invited members
  9 + of a community
  10 + -->
7 11 <% @members.each do |member| %>
8   - <%= profile_image_link(member) %>
  12 + <%= profile_image_link(member, :portrait, 'li', @profiles_focus.include?(member.user_id) ? {:value =>_('New'), :class => 'new-profile'}:'') %>
9 13 <% end %>
10 14 </ul>
11 15  
... ...
public/stylesheets/application.css
... ... @@ -2205,6 +2205,21 @@ a.button.disabled, input.disabled {
2205 2205 .profile-list .extra_info {
2206 2206 font-size: 9px;
2207 2207 }
  2208 +
  2209 +/* New members of community added
  2210 +* by admin of environment feature
  2211 +* #issue 227
  2212 +*/
  2213 +.profile-list .extra_info.new-profile {
  2214 + margin-top: 5px;
  2215 + color: #0A0;
  2216 + font-weight: bold;
  2217 +}
  2218 +
  2219 +span.new-profile img{
  2220 + border-top: solid 2px #0A0;
  2221 + margin-top: -2px;
  2222 +}
2208 2223 /* ==> blocks/recent-documents-block.css <<= */
2209 2224  
2210 2225 #content .recent-documents-block {
... ...