refactor gender avatar html.erb => helper

This commit is contained in:
yanxd 2013-11-15 15:36:45 +08:00
parent 26d75af51a
commit c4bf9a8f72
2 changed files with 74 additions and 78 deletions

View File

@ -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
@ -206,4 +207,11 @@ def sort_user(state, project_type)
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs_enterprise")
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

View File

@ -55,20 +55,8 @@
<td>
<table>
<tr>
<td class="info_font" align="center" style=" word-wrap: break-word; word-break: break-all"><%= h @user.lastname<<@user.firstname %> <!-- added by bai -->
<% 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 %> <!-- end --></td>
<%= image_tag(img_uri, weight:"25px", height:"25px") %>
<td class="info_font" align="center" style=" word-wrap: break-word; word-break: break-all"><%= h @user.lastname<<@user.firstname %> <!-- added by bai --></td>
<%= image_tag(gender_avatar_uri(@user), weight:"25px", height:"25px") if (@user.user_extensions && (@user.user_extensions.identity != 2) )%>
</tr>
<tr>
<td align="center"> <% unless User.current == @user %>