Commit beef00835e61880f922fec0382eb8356da412a92
1 parent
fec8c9a7
Exists in
master
and in
28 other branches
Encapsulate logic for manage_{communityes|enterprises}
Showing
4 changed files
with
19 additions
and
28 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -1113,25 +1113,24 @@ module ApplicationHelper |
1113 | 1113 | result |
1114 | 1114 | end |
1115 | 1115 | |
1116 | - def manage_enterprises | |
1117 | - return if not user | |
1118 | - if !user.enterprises.empty? | |
1119 | - enterprises_link = user.enterprises.map do |enterprise| | |
1120 | - link_to(content_tag('strong', [_('<span>Manage</span> %s') % enterprise.short_name(25)]), @environment.top_url + "/myprofile/#{enterprise.identifier}", :class => "icon-menu-"+enterprise.class.identification.underscore, :title => [_('Manage %s') % enterprise.short_name]) | |
1116 | + def manage_link(list, kind) | |
1117 | + if list.present? | |
1118 | + link = list.map do |element| | |
1119 | + link_to(content_tag('strong', [_('<span>Manage</span> %s') % element.short_name(25)]), @environment.top_url + "/myprofile/#{element.identifier}", :class => "icon-menu-"+element.class.identification.underscore, :title => [_('Manage %s') % element.short_name]) | |
1121 | 1120 | end |
1122 | - render :partial => 'shared/manage_enterprises', :locals => {:enterprises_link => enterprises_link} | |
1121 | + render :partial => "shared/manage_link", :locals => {:link => link, :kind => kind.to_s} | |
1123 | 1122 | end |
1124 | 1123 | end |
1125 | 1124 | |
1125 | + def manage_enterprises | |
1126 | + return if not user | |
1127 | + manage_link(user.enterprises, :enterprises) | |
1128 | + end | |
1129 | + | |
1126 | 1130 | def manage_communities |
1127 | 1131 | return if not user |
1128 | 1132 | administered_communities = user.communities.select {|c| c.admins.include? user} |
1129 | - if !administered_communities.empty? | |
1130 | - communities_link = administered_communities.map do |community| | |
1131 | - link_to(content_tag('strong', [_('<span>Manage</span> %s') % community.short_name(25)]), @environment.top_url + "/myprofile/#{community.identifier}", :class => "icon-menu-"+community.class.identification.underscore, :title => [_('Manage %s') % community.short_name]) | |
1132 | - end | |
1133 | - render :partial => 'shared/manage_communities', :locals => {:communities_link => communities_link} | |
1134 | - end | |
1133 | + manage_link(administered_communities, :communities) | |
1135 | 1134 | end |
1136 | 1135 | |
1137 | 1136 | def usermenu_logged_in | ... | ... |
app/views/shared/_manage_communities.rhtml
... | ... | @@ -1,8 +0,0 @@ |
1 | -<div id="manage-communities" class="manage-groups"> | |
2 | - <a href="#" id="manage-communities-link" class="simplemenu-trigger" title="<%= _('Manage communities') %>"><i class="icon-menu-community"></i><strong><%= ui_icon('ui-icon-triangle-1-s') + _('My communities') %></strong></a> | |
3 | - <ul class="simplemenu-submenu"> | |
4 | - <% communities_link.each do |link| %> | |
5 | - <li class="simplemenu-item"><%= link %></li> | |
6 | - <% end %> | |
7 | - </ul> | |
8 | -</div> |
app/views/shared/_manage_enterprises.rhtml
... | ... | @@ -1,8 +0,0 @@ |
1 | -<div id="manage-enterprises" class="manage-groups"> | |
2 | - <a href="#" id="manage-enterprises-link" class="simplemenu-trigger" title="<%= _('Manage enterprises') %>"><i class="icon-menu-enterprise"></i><strong><%= ui_icon('ui-icon-triangle-1-s') + _('My enterprises') %></strong></a> | |
3 | - <ul class="simplemenu-submenu"> | |
4 | - <% enterprises_link.each do |link| %> | |
5 | - <li class="simplemenu-item"><%= link %></li> | |
6 | - <% end %> | |
7 | - </ul> | |
8 | -</div> |
... | ... | @@ -0,0 +1,8 @@ |
1 | +<div id=<%= "manage-#{kind}" %> class="manage-groups"> | |
2 | + <a href="#" id=<%= "manage-#{kind}-link" %> class="simplemenu-trigger" title="<%= _('Manage %s') % kind %>"><i class=<%= "icon-menu-#{kind.singularize}" %>></i><strong><%= ui_icon('ui-icon-triangle-1-s') + _('My %s') % kind %></strong></a> | |
3 | + <ul class="simplemenu-submenu"> | |
4 | + <% link.each do |link| %> | |
5 | + <li class="simplemenu-item"><%= link %></li> | |
6 | + <% end %> | |
7 | + </ul> | |
8 | +</div> | ... | ... |