Commit 1d891d1953e684b8f5f7dc537df6c3031061c9b6
1 parent
3497a5fb
Exists in
master
and in
22 other branches
user-menu: loading user menu on the server-side instead of on the client-side
There is no reason for the user menu to load on the client-side. The only reason, that would be plausible is if it varnish was providing cached pages for logged users. Since this is not happening, there is no need to load it on the client-side.
Showing
6 changed files
with
52 additions
and
78 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -1091,10 +1091,10 @@ module ApplicationHelper |
1091 | 1091 | link_to_all = nil |
1092 | 1092 | if list.count > 5 |
1093 | 1093 | list = list.first(5) |
1094 | - link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => current_user.login) | |
1094 | + link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => user.identifier) | |
1095 | 1095 | end |
1096 | 1096 | link = list.map do |element| |
1097 | - 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]) | |
1097 | + link_to(content_tag('strong', _('<span>Manage</span> %s') % element.short_name(25)), element.admin_url, :class => "icon-menu-"+element.class.identification.underscore, :title => _('Manage %s') % element.short_name) | |
1098 | 1098 | end |
1099 | 1099 | if link_to_all |
1100 | 1100 | link << link_to_all |
... | ... | @@ -1118,15 +1118,15 @@ module ApplicationHelper |
1118 | 1118 | pending_tasks_count = '' |
1119 | 1119 | count = user ? Task.to(user).pending.count : -1 |
1120 | 1120 | if count > 0 |
1121 | - pending_tasks_count = link_to(count.to_s, @environment.top_url + '/myprofile/{login}/tasks', :id => 'pending-tasks-count', :title => _("Manage your pending tasks")) | |
1121 | + pending_tasks_count = link_to(count.to_s, user.tasks_url, :id => 'pending-tasks-count', :title => _("Manage your pending tasks")) | |
1122 | 1122 | end |
1123 | 1123 | |
1124 | - (_("<span class='welcome'>Welcome,</span> %s") % link_to('<i style="background-image:url({avatar})"></i><strong>{login}</strong>', @environment.top_url + '/{login}', :id => "homepage-link", :title => _('Go to your homepage'))) + | |
1124 | + (_("<span class='welcome'>Welcome,</span> %s") % link_to("<i style='background-image:url(#{user.profile_custom_icon(gravatar_default)})'></i><strong>#{user.identifier}</strong>", user.public_profile_url, :id => "homepage-link", :title => _('Go to your homepage'))) + | |
1125 | 1125 | render_environment_features(:usermenu) + |
1126 | - link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.top_url + '/admin', :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') + | |
1126 | + link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') + | |
1127 | 1127 | manage_enterprises.to_s + |
1128 | 1128 | manage_communities.to_s + |
1129 | - link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', @environment.top_url + '/myprofile/{login}', :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + | |
1129 | + link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + | |
1130 | 1130 | pending_tasks_count + |
1131 | 1131 | link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) |
1132 | 1132 | end | ... | ... |
app/models/environment.rb
... | ... | @@ -637,6 +637,10 @@ class Environment < ActiveRecord::Base |
637 | 637 | domain |
638 | 638 | end |
639 | 639 | |
640 | + def admin_url | |
641 | + { :controller => 'admin_panel', :action => 'index' } | |
642 | + end | |
643 | + | |
640 | 644 | def top_url |
641 | 645 | url = 'http://' |
642 | 646 | url << (Noosfero.url_options.key?(:host) ? Noosfero.url_options[:host] : default_hostname) | ... | ... |
app/views/account/accept_terms.html.erb
... | ... | @@ -19,10 +19,18 @@ |
19 | 19 | <%= hidden_field_tag :enterprise_code, params[:enterprise_code] %> |
20 | 20 | <%= hidden_field_tag :answer, params[:answer] %> |
21 | 21 | |
22 | - <%= labelled_check_box(environment.terms_of_use_acceptance_text.blank? ? _('I read the terms of use and accepted them') : environment.terms_of_use_acceptance_text, :terms_accepted, '1', false, :onclick => 'toggle_submit_button("submit-accept-terms", this.checked)') %> | |
22 | + <%= labelled_check_box(environment.terms_of_use_acceptance_text.blank? ? _('I read the terms of use and accepted them') : environment.terms_of_use_acceptance_text, :terms_accepted, '1', false, :id => 'accept-terms') %> | |
23 | 23 | <% button_bar do %> |
24 | 24 | <%= button 'cancel', _('Cancel'), :controller => 'home', :action => 'index' %> |
25 | 25 | <%= submit_button 'forward', _('Continue'), {:disabled => true, :class => 'disabled', :id => 'submit-accept-terms'} %> |
26 | 26 | <% end %> |
27 | 27 | <% end %> |
28 | 28 | </div> |
29 | + | |
30 | +<script type="text/javascript"> | |
31 | + jQuery('#accept-terms').change(function(){ | |
32 | + jQuery("#submit-accept-terms").toggleClass("disabled"); | |
33 | + jQuery("#submit-accept-terms").prop("disabled", !jQuery("#submit-accept-terms").prop("disabled")); | |
34 | + }); | |
35 | +</script> | |
36 | + | ... | ... |
app/views/blocks/login_block.html.erb
1 | -<div class="logged-user-info" style='display: none;'> | |
2 | - <h2><%= _('Logged in as %s') % '{login}' %></h2> | |
3 | - <ul> | |
4 | - <li><%= _('User since {year}/{month}') %></li> | |
5 | - <li><%= link_to _('Homepage'), '/{login}' %></li> | |
6 | - </ul> | |
7 | - <div class="user-actions"> | |
8 | - <%= link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout' }, :class => 'button with-text icon-menu-logout' %> | |
1 | +<% if user.present? %> | |
2 | + <div class="logged-user-info"> | |
3 | + <h2><%= _('Logged in as %s') % user.identifier %></h2> | |
4 | + <ul> | |
5 | + <li><%= _('User since %s/%s') % [user.created_at.month, user.created_at.year] %></li> | |
6 | + <li><%= link_to _('Homepage'), user.public_profile_url %></li> | |
7 | + </ul> | |
8 | + <div class="user-actions"> | |
9 | + <%= link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout' }, :class => 'button with-text icon-menu-logout' %> | |
10 | + </div> | |
9 | 11 | </div> |
10 | -</div> | |
11 | -<div class='not-logged-user' style='display: none;'> | |
12 | - <%= render :file => 'account/login_block' %> | |
13 | -</div> | |
12 | +<% else %> | |
13 | + <div class='not-logged-user'> | |
14 | + <%= render :file => 'account/login_block' %> | |
15 | + </div> | |
16 | +<% end%> | ... | ... |
app/views/layouts/_user.html.erb
1 | 1 | <div id="user"> |
2 | - <span class='logged-in' style='display: none;'> | |
3 | - <%= usermenu_logged_in %> | |
4 | - </span> | |
5 | - <span class='not-logged-in' style='display: none'> | |
2 | + <% user = (session[:user] && User.find_by_id(session[:user])) || nil %> | |
3 | + <% if user.present? %> | |
4 | + <% user = user.person %> | |
5 | + <span class='logged-in'> | |
6 | + <%= usermenu_logged_in %> | |
7 | + </span> | |
8 | + <% else %> | |
9 | + <span class='not-logged-in'> | |
10 | + <%= _("<span class='login'>%s</span>") % thickbox_inline_popup_link('<i class="icon-menu-login"></i><strong>' + _('Login') + '</strong>', login_url, 'inlineLoginBox', :id => 'link_login') %> | |
11 | + <%= @plugins.dispatch(:alternative_authentication_link).collect { |content| instance_exec(&content) }.join("") %> | |
6 | 12 | |
7 | - <%= _("<span class='login'>%s</span>") % thickbox_inline_popup_link('<i class="icon-menu-login"></i><strong>' + _('Login') + '</strong>', login_url, 'inlineLoginBox', :id => 'link_login') %> | |
8 | - <%= @plugins.dispatch(:alternative_authentication_link).collect { |content| instance_exec(&content) }.join("") %> | |
13 | + <div id='inlineLoginBox' style='display: none;'> | |
14 | + <%= render :file => 'account/login', :locals => { :is_thickbox => true } %> | |
15 | + </div> | |
9 | 16 | |
10 | - <div id='inlineLoginBox' style='display: none;'> | |
11 | - <%= render :file => 'account/login', :locals => { :is_thickbox => true } %> | |
12 | - </div> | |
13 | - | |
14 | - <% unless @plugins.dispatch(:allow_user_registration).include?(false) %> | |
15 | - <%= _("<span class='or'>or</span> <span class='signup'>%s</span>") % link_to('<strong>' + _('Sign up') + '</strong>', :controller => 'account', :action => 'signup')%> | |
16 | - <% end %> | |
17 | - | |
18 | - </span> | |
17 | + <% unless @plugins.dispatch(:allow_user_registration).include?(false) %> | |
18 | + <%= _("<span class='or'>or</span> <span class='signup'>%s</span>") % link_to('<strong>' + _('Sign up') + '</strong>', :controller => 'account', :action => 'signup')%> | |
19 | + <% end %> | |
20 | + </span> | |
21 | + <% end %> | |
19 | 22 | <form action="/search" id="top-search" class="search_form clean" method="get"> |
20 | 23 | <input name="query" size="15" title="<%=_('Search...')%>" onfocus="this.form.className='focused';" onblur="this.form.className=''" /> |
21 | 24 | <div><%=_('Press <strong>Enter</strong> to send the search query.')%></div> | ... | ... |
public/javascripts/application.js
... | ... | @@ -518,16 +518,11 @@ jQuery(function($) { |
518 | 518 | $.getJSON('/account/user_data', function userDataCallBack(data) { |
519 | 519 | if (data.login) { |
520 | 520 | // logged in |
521 | - loggedInDataCallBack(data); | |
522 | - addManageEnterprisesToOldStyleMenu(data); | |
523 | 521 | if (data.chat_enabled) { |
524 | 522 | setInterval(function(){ $.getJSON('/account/user_data', chatOnlineUsersDataCallBack)}, 10000); |
525 | 523 | } |
526 | 524 | $('head').append('<meta content="authenticity_token" name="csrf-param" />'); |
527 | 525 | $('head').append('<meta content="'+$.cookie("_noosfero_.XSRF-TOKEN")+'" name="csrf-token" />'); |
528 | - } else { | |
529 | - // not logged in | |
530 | - $('#user .not-logged-in, .login-block .not-logged-user').fadeIn(); | |
531 | 526 | } |
532 | 527 | if (data.notice) { |
533 | 528 | display_notice(data.notice); |
... | ... | @@ -536,45 +531,6 @@ jQuery(function($) { |
536 | 531 | $(window).trigger("userDataLoaded", data); |
537 | 532 | }); |
538 | 533 | |
539 | - function loggedInDataCallBack(data) { | |
540 | - // logged in | |
541 | - $('body').addClass('logged-in'); | |
542 | - $('#user .logged-in, .login-block .logged-user-info').each(function() { | |
543 | - $(this).find('a[href]').each(function() { | |
544 | - var new_href = $(this).attr('href').replace('{login}', data.login); | |
545 | - if (data.email_domain) { | |
546 | - new_href = new_href.replace('{email_domain}', data.email_domain); | |
547 | - } | |
548 | - $(this).attr('href', new_href); | |
549 | - }); | |
550 | - var html = $(this).html() | |
551 | - .replace(/{login}/g, data.login) | |
552 | - .replace('{avatar}', data.avatar) | |
553 | - .replace('{month}', data.since_month) | |
554 | - .replace('{year}', data.since_year); | |
555 | - $(this).html(html).fadeIn(); | |
556 | - if (data.is_admin) { | |
557 | - $('#user .admin-link').show(); | |
558 | - } | |
559 | - if (data.email_domain) { | |
560 | - $('#user .webmail-link').show(); | |
561 | - } | |
562 | - }); | |
563 | - } | |
564 | - | |
565 | - function addManageEnterprisesToOldStyleMenu(data) { | |
566 | - if ($('#manage-enterprises-link-template').length > 0) { | |
567 | - $.each(data.enterprises, function(index, enterprise) { | |
568 | - var item = $('<li>' + $('#manage-enterprises-link-template').html() + '</li>'); | |
569 | - item.find('a[href]').each(function() { | |
570 | - $(this).attr('href', '/myprofile/' + enterprise.identifier); | |
571 | - }); | |
572 | - item.html(item.html().replace('{name}', enterprise.name)); | |
573 | - item.insertAfter('#manage-enterprises-link-template'); | |
574 | - }); | |
575 | - } | |
576 | - } | |
577 | - | |
578 | 534 | function chatOnlineUsersDataCallBack(data) { |
579 | 535 | if ($('#chat-online-users').length == 0) { |
580 | 536 | return; | ... | ... |