From c4bf9a8f72827a55ced099250a2134ded72bf3ef Mon Sep 17 00:00:00 2001 From: yanxd Date: Fri, 15 Nov 2013 15:36:45 +0800 Subject: [PATCH] refactor gender avatar html.erb => helper --- app/helpers/users_helper.rb | 136 ++++++++++++++------------ app/views/layouts/base_users.html.erb | 16 +-- 2 files changed, 74 insertions(+), 78 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4ba39cfd1..8fd923234 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -102,72 +102,73 @@ module UsersHelper s = content_tag('span', l(:label_has_watched_project), :class => "current-page") content << content_tag('li', link_to(l(:label_project_take), {:controller => 'users', :action => 'user_projects'})) content << content_tag('li', s, :class => "current-page") - end + end content_tag('div', content, :class => "pagination") end - def user_course(state) - content = ''.html_safe - if @user != User.current - if @user.user_extensions.identity == 0 - case state - when 0 - s = content_tag('span', '他执教的课程', :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('他发布的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '他发布的作业', :class => "current-page") - content << content_tag('li', link_to('他执教的课程', {:controller => 'users', :action => 'user_courses'})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - else - case state - when 0 - s = content_tag('span', '他的课程', :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('他的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '他的作业', :class => "current-page") - content << content_tag('li', link_to('他的课程', {:controller => 'users', :action => 'user_courses', :type => 0})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - end - else - if @user.user_extensions.identity == 0 - case state - when 0 - s = content_tag('span', l(:label_teaching_course), :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to(l(:label_release_homework), {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', l(:label_release_homework), :class => "current-page") - content << content_tag('li', link_to(l(:label_teaching_course), {:controller => 'users', :action => 'user_courses'})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - else - case state - when 0 - s = content_tag('span', l(:label_my_course), :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('我的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '我的作业', :class => "current-page") - content << content_tag('li', link_to(l(:label_my_course), {:controller => 'users', :action => 'user_courses', :type => 0})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - end - end - end -# added by huang -def sort_user(state, project_type) + def user_course(state) + content = ''.html_safe + if @user != User.current + if @user.user_extensions.identity == 0 + case state + when 0 + s = content_tag('span', '他执教的课程', :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('他发布的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '他发布的作业', :class => "current-page") + content << content_tag('li', link_to('他执教的课程', {:controller => 'users', :action => 'user_courses'})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + else + case state + when 0 + s = content_tag('span', '他的课程', :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('他的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '他的作业', :class => "current-page") + content << content_tag('li', link_to('他的课程', {:controller => 'users', :action => 'user_courses', :type => 0})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + end + else + if @user.user_extensions.identity == 0 + case state + when 0 + s = content_tag('span', l(:label_teaching_course), :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to(l(:label_release_homework), {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', l(:label_release_homework), :class => "current-page") + content << content_tag('li', link_to(l(:label_teaching_course), {:controller => 'users', :action => 'user_courses'})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + else + case state + when 0 + s = content_tag('span', l(:label_my_course), :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('我的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '我的作业', :class => "current-page") + content << content_tag('li', link_to(l(:label_my_course), {:controller => 'users', :action => 'user_courses', :type => 0})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + end + end + end + + # added by huang + def sort_user(state, project_type) content = ''.html_safe case state when 0 @@ -205,5 +206,12 @@ def sort_user(state, project_type) end content = content_tag('ul', content) content_tag('div', content, :class => "tabs_enterprise") - end + end + + def gender_avatar_uri user + img_uri = '/images/sidebar/female.png' + return img_uri if user.user_extensions.blank? + person_gender = user.user_extensions.gender + img_uri = (person_gender == 1) ? '/images/sidebar/female.png' : '/images/sidebar/male.png' + end end diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 0f289b37b..64c33e32a 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -55,20 +55,8 @@ - - <%= image_tag(img_uri, weight:"25px", height:"25px") %> + + <%= image_tag(gender_avatar_uri(@user), weight:"25px", height:"25px") if (@user.user_extensions && (@user.user_extensions.identity != 2) )%>
<%= h @user.lastname<<@user.firstname %> - <% img_path = '' %> - <% unless @user.user_extensions.nil?%> - <% unless @user.user_extensions.identity == 2 %> - <% if @user.user_extensions.gender == 1 %> - <% img_uri = '/images/sidebar/female.png' %> - <% else %> - <% img_uri = '/images/sidebar/male.png' %> - <% end %> - <% end %> - <% else %> - <% img_uri = '/images/sidebar/female.png' %> - <% end %> <%= h @user.lastname<<@user.firstname %>
<% unless User.current == @user %>