Commit fec8c9a75a96a97cea1dedc2eb8eb7c6cd6c4b4e

Authored by Rodrigo Souto
2 parents fc5eba87 7a74b579

Merge commit 'refs/merge-requests/295' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/295
app/helpers/application_helper.rb
... ... @@ -1114,7 +1114,8 @@ module ApplicationHelper
1114 1114 end
1115 1115  
1116 1116 def manage_enterprises
1117   - if user && !user.enterprises.empty?
  1117 + return if not user
  1118 + if !user.enterprises.empty?
1118 1119 enterprises_link = user.enterprises.map do |enterprise|
1119 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])
1120 1121 end
... ... @@ -1122,6 +1123,17 @@ module ApplicationHelper
1122 1123 end
1123 1124 end
1124 1125  
  1126 + def manage_communities
  1127 + return if not user
  1128 + 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
  1135 + end
  1136 +
1125 1137 def usermenu_logged_in
1126 1138 pending_tasks_count = ''
1127 1139 count = user ? Task.to(user).pending.count : -1
... ... @@ -1133,6 +1145,7 @@ module ApplicationHelper
1133 1145 render_environment_features(:usermenu) +
1134 1146 link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.top_url + '/admin', :id => "controlpanel", :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') +
1135 1147 manage_enterprises.to_s +
  1148 + manage_communities.to_s +
1136 1149 link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', @environment.top_url + '/myprofile/{login}', :id => "controlpanel", :title => _("Configure your personal account and content")) +
1137 1150 pending_tasks_count +
1138 1151 link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system"))
... ...
app/views/shared/_manage_communities.rhtml 0 → 100644
... ... @@ -0,0 +1,8 @@
  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   -<div id='manage-enterprises'>
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'>
  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 4 <% enterprises_link.each do |link| %>
5   - <li class='simplemenu-item'><%= link %></li>
  5 + <li class="simplemenu-item"><%= link %></li>
6 6 <% end %>
7 7 </ul>
8 8 </div>
... ...
public/designs/themes/base/style.css
... ... @@ -89,7 +89,7 @@ body, th, td, input {
89 89 color: #555753;
90 90 }
91 91  
92   -#controlpanel, #logout, #openchat, #manage-enterprises {
  92 +#controlpanel, #logout, #openchat, .manage-groups {
93 93 margin-left: 25px;
94 94 }
95 95  
... ...
public/javascripts/application.js
... ... @@ -709,7 +709,7 @@ jQuery(function($) {
709 709 document.location.href = this.href;
710 710 })
711 711 }
712   - $('#manage-enterprises-link').live('click', function() {
  712 + $('.manage-groups > a').live('click', function() {
713 713 toggleMenu(this);
714 714 return false;
715 715 });
... ...
public/stylesheets/application.css
... ... @@ -882,6 +882,40 @@ code input {
882 882 .webkit #manage-enterprises .simplemenu-submenu {
883 883 top: 20px;
884 884 }
  885 +#manage-communities {
  886 + display: inline-block;
  887 + margin-right: 5px;
  888 + position: relative;
  889 +}
  890 +#manage-communities .ui-icon {
  891 + position: absolute;
  892 + top: 0;
  893 + right: -20px;
  894 +}
  895 +#manage-communities .simplemenu-submenu {
  896 + text-align: left;
  897 + left: -20px;
  898 + width: 200px;
  899 +}
  900 +#manage-communities .simplemenu-item {
  901 + padding: 5px 0;
  902 +}
  903 +#manage-communities .simplemenu-item a {
  904 + background-repeat: no-repeat;
  905 + padding-left: 20px;
  906 +}
  907 +#manage-communities .simplemenu-item a span {
  908 + display: none;
  909 +}
  910 +.msie8 #manage-communities-link { /* IE8 hack */
  911 + border: 0px solid;
  912 +}
  913 +.msie8 #manage-communities .simplemenu-submenu {
  914 + top: 16px;
  915 +}
  916 +.webkit #manage-communities .simplemenu-submenu {
  917 + top: 20px;
  918 +}
885 919 #article {
886 920 position: relative;
887 921 text-align: justify;
... ...
test/functional/profile_controller_test.rb
... ... @@ -96,7 +96,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
96 96 end
97 97  
98 98 should 'not show enterprises link to enterprise' do
99   - ent = fast_create(Enterprise, :identifier => 'test_enterprise1', :name => 'Test enteprise1')
  99 + ent = fast_create(Enterprise, :identifier => 'test_enterprise1', :name => 'Test enterprise1')
100 100 get :index, :profile => ent.identifier
101 101 assert_no_tag :tag => 'a', :content => 'Enterprises', :attributes => { :href => /profile\/#{ent.identifier}\/enterprises$/ }
102 102 end
... ... @@ -561,7 +561,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
561 561 assert_response 403
562 562 end
563 563  
564   - should 'allow environment admin to unblock enteprises' do
  564 + should 'allow environment admin to unblock enterprises' do
565 565 login_as(profile.identifier)
566 566 enterprise = fast_create(Enterprise)
567 567 enterprise.environment.add_admin(profile)
... ... @@ -882,7 +882,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
882 882 assert_template 'index'
883 883 end
884 884  
885   - should 'the network activity be visible to uses not logged in on communities and enteprises' do
  885 + should 'the network activity be visible to uses not logged in on communities and enterprises' do
886 886 p1= Person.first
887 887 community = fast_create(Community)
888 888 p2= fast_create(Person)
... ... @@ -1550,4 +1550,60 @@ class ProfileControllerTest &lt; ActionController::TestCase
1550 1550 assert_tag :tag => 'td', :content => 'e-Mail:'
1551 1551 end
1552 1552  
  1553 + should 'build menu to the community panel' do
  1554 + u = create_user('other_other_ze').person
  1555 + u2 = create_user('guy_that_will_be_admin_of_all').person # because the first member of each community is an admin
  1556 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1557 + u.data = { :email => 'test@test.com', :fields_privacy => { } }
  1558 + u.save!
  1559 + c1 = Community.create!(:name => 'community_1')
  1560 + c2 = Community.create!(:name => 'community_2')
  1561 + c3 = Community.create!(:name => 'community_3')
  1562 + c4 = Community.create!(:name => 'community_4')
  1563 +
  1564 + c1.add_admin(u2)
  1565 + c2.add_admin(u2)
  1566 + c3.add_admin(u2)
  1567 +
  1568 + c1.add_member(u)
  1569 + c2.add_member(u)
  1570 + c3.add_member(u)
  1571 + c1.add_admin(u)
  1572 + c2.add_admin(u)
  1573 +
  1574 + login_as(u.identifier)
  1575 +
  1576 + get :index
  1577 +
  1578 + assert_tag :tag => 'div', :attributes => {:id => 'manage-communities'}
  1579 + assert_select '#manage-communities li > a' do |links|
  1580 + assert_equal 2, links.length
  1581 + assert_match /community_1/, links.to_s
  1582 + assert_match /community_2/, links.to_s
  1583 + assert_no_match /community_3/, links.to_s
  1584 + assert_no_match /community_4/, links.to_s
  1585 + end
  1586 + end
  1587 +
  1588 + should 'build menu to the enterprise panel' do
  1589 + u = create_user('other_other_ze').person
  1590 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1591 + u.data = { :email => 'test@test.com', :fields_privacy => { } }
  1592 + u.save!
  1593 + e1 = fast_create(Enterprise, :identifier => 'test_enterprise1', :name => 'Test enterprise1')
  1594 + e2 = fast_create(Enterprise, :identifier => 'test_enterprise2', :name => 'Test enterprise2')
  1595 +
  1596 + e1.add_member(u)
  1597 +
  1598 + login_as(u.identifier)
  1599 +
  1600 + get :index
  1601 +
  1602 + assert_tag :tag => 'div', :attributes => {:id => 'manage-enterprises'}
  1603 + assert_select '#manage-enterprises li > a' do |links|
  1604 + assert_equal 1, links.length
  1605 + assert_match /Test enterprise1/, links.to_s
  1606 + assert_no_match /Test enterprise_2/, links.to_s
  1607 + end
  1608 + end
1553 1609 end
... ...