Commit 86e1fd79ce8ff8b3cd8c3d685dc2444b99144508

Authored by Antonio Terceiro
1 parent 7af94bbc

Add back support for managing enterprises directly from menu

(ActionItem1608)
app/models/user.rb
... ... @@ -216,6 +216,7 @@ class User < ActiveRecord::Base
216 216  
217 217 def data_hash
218 218 friends_list = {}
  219 + enterprises = person.enterprises.map { |e| { 'name' => e.short_name, 'identifier' => e.identifier } }
219 220 self.person.friends.online.map do |person|
220 221 friends_list[person.identifier] = {
221 222 'avatar' => person.profile_custom_icon,
... ... @@ -231,6 +232,7 @@ class User < ActiveRecord::Base
231 232 'since_year' => self.person.created_at.year,
232 233 'email_domain' => self.enable_email ? self.email_domain : nil,
233 234 'friends_list' => friends_list,
  235 + 'enterprises' => enterprises,
234 236 'amount_of_friends' => friends_list.count
235 237 }
236 238 end
... ...
app/views/shared/user_menu.rhtml
... ... @@ -23,9 +23,7 @@
23 23 <%= lightbox_link_to('<span class="icon-new"></span>' + _('New article'), '/myprofile/{login}/cms/new') %>
24 24 </li>
25 25  
26   - <%# for enterprise in user.enterprises %>
27   - <li><%# link_to('<span class="icon-menu-enterprise"></span>' + (_('Manage %s') % enterprise.short_name), { :controller => 'profile_editor', :profile => enterprise.identifier, :action => 'index' }) #%></li>
28   - <%# end %>
  26 + <li id='manage-enterprises-link-template' style='display: none'><a href='/myprofile/{identifier}'><span class="icon-menu-enterprise"></span><%= _('Manage %s') % '{name}' %></a></li>
29 27  
30 28 <!-- li><a href="#"><span class="icon-menu-blog"></span> Meu Blog</a></li -->
31 29  
... ...
public/javascripts/application.js
... ... @@ -455,6 +455,7 @@ jQuery(function($) {
455 455 if (data.login) {
456 456 // logged in
457 457 loggedInDataCallBack(data);
  458 + addManageEnterprisesToOldStyleMenu(data);
458 459 chatOnlineUsersDataCallBack(data);
459 460 } else {
460 461 // not logged in
... ... @@ -487,6 +488,19 @@ jQuery(function($) {
487 488 });
488 489 }
489 490  
  491 + function addManageEnterprisesToOldStyleMenu(data) {
  492 + if ($('#manage-enterprises-link-template').length > 0) {
  493 + $.each(data.enterprises, function(index, enterprise) {
  494 + var item = $('<li>' + $('#manage-enterprises-link-template').html() + '</li>');
  495 + item.find('a[href]').each(function() {
  496 + $(this).attr('href', '/myprofile/' + enterprise.identifier);
  497 + });
  498 + item.html(item.html().replace('{name}', enterprise.name));
  499 + item.insertAfter('#manage-enterprises-link-template');
  500 + });
  501 + }
  502 + }
  503 +
490 504 function chatOnlineUsersDataCallBack(data) {
491 505 var content = '';
492 506 $('#chat-online-users').html($('#chat-online-users').html().replace(/%{amount}/g, data['amount_of_friends']));
... ...