From 1d891d1953e684b8f5f7dc537df6c3031061c9b6 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 29 May 2014 22:38:35 +0000 Subject: [PATCH] user-menu: loading user menu on the server-side instead of on the client-side --- app/helpers/application_helper.rb | 12 ++++++------ app/models/environment.rb | 4 ++++ app/views/account/accept_terms.html.erb | 10 +++++++++- app/views/blocks/login_block.html.erb | 27 +++++++++++++++------------ app/views/layouts/_user.html.erb | 33 ++++++++++++++++++--------------- public/javascripts/application.js | 44 -------------------------------------------- 6 files changed, 52 insertions(+), 78 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a7e92ea..d5dbfac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1091,10 +1091,10 @@ module ApplicationHelper link_to_all = nil if list.count > 5 list = list.first(5) - link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => current_user.login) + link_to_all = link_to(content_tag('strong', _('See all')), :controller => 'memberships', :profile => user.identifier) end link = list.map do |element| - link_to(content_tag('strong', [_('Manage %s') % element.short_name(25)]), @environment.top_url + "/myprofile/#{element.identifier}", :class => "icon-menu-"+element.class.identification.underscore, :title => [_('Manage %s') % element.short_name]) + link_to(content_tag('strong', _('Manage %s') % element.short_name(25)), element.admin_url, :class => "icon-menu-"+element.class.identification.underscore, :title => _('Manage %s') % element.short_name) end if link_to_all link << link_to_all @@ -1118,15 +1118,15 @@ module ApplicationHelper pending_tasks_count = '' count = user ? Task.to(user).pending.count : -1 if count > 0 - pending_tasks_count = link_to(count.to_s, @environment.top_url + '/myprofile/{login}/tasks', :id => 'pending-tasks-count', :title => _("Manage your pending tasks")) + pending_tasks_count = link_to(count.to_s, user.tasks_url, :id => 'pending-tasks-count', :title => _("Manage your pending tasks")) end - (_("Welcome, %s") % link_to('{login}', @environment.top_url + '/{login}', :id => "homepage-link", :title => _('Go to your homepage'))) + + (_("Welcome, %s") % link_to("#{user.identifier}", user.public_profile_url, :id => "homepage-link", :title => _('Go to your homepage'))) + render_environment_features(:usermenu) + - link_to('' + _('Administration') + '', @environment.top_url + '/admin', :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') + + link_to('' + _('Administration') + '', @environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') + manage_enterprises.to_s + manage_communities.to_s + - link_to('' + _('Control panel') + '', @environment.top_url + '/myprofile/{login}', :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + + link_to('' + _('Control panel') + '', user.admin_url, :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + pending_tasks_count + link_to('' + _('Logout') + '', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) end diff --git a/app/models/environment.rb b/app/models/environment.rb index e3b7f31..579dfa7 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -637,6 +637,10 @@ class Environment < ActiveRecord::Base domain end + def admin_url + { :controller => 'admin_panel', :action => 'index' } + end + def top_url url = 'http://' url << (Noosfero.url_options.key?(:host) ? Noosfero.url_options[:host] : default_hostname) diff --git a/app/views/account/accept_terms.html.erb b/app/views/account/accept_terms.html.erb index dfc4ab2..404f944 100644 --- a/app/views/account/accept_terms.html.erb +++ b/app/views/account/accept_terms.html.erb @@ -19,10 +19,18 @@ <%= hidden_field_tag :enterprise_code, params[:enterprise_code] %> <%= hidden_field_tag :answer, params[:answer] %> - <%= 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)') %> + <%= 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') %> <% button_bar do %> <%= button 'cancel', _('Cancel'), :controller => 'home', :action => 'index' %> <%= submit_button 'forward', _('Continue'), {:disabled => true, :class => 'disabled', :id => 'submit-accept-terms'} %> <% end %> <% end %> + + + diff --git a/app/views/blocks/login_block.html.erb b/app/views/blocks/login_block.html.erb index c1a3bb9..82dfea6 100644 --- a/app/views/blocks/login_block.html.erb +++ b/app/views/blocks/login_block.html.erb @@ -1,13 +1,16 @@ -