<% is_admin = User.current == @syllabus.user || User.current.admin? %>
<table class="sy_new_table clear mb15"  cellpadding="0" cellspacing="0" id="syllabus_member_list">
  <thead>
  <tr>
    <th>序号</th>
    <th class="sy_new_namebox">姓名</th>
    <th>职业</th>
    <th>创建班级数</th>
    <th>参与班级数</th>
    <% if is_admin %>
        <th>操作</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% count = @members.count %>
  <% @members.each_with_index do |member, i| %>
      <% user = member.user %>
      <% allow_delete = is_admin && @syllabus.courses.where(:tea_id => member.user_id).empty? %>
      <tr>
        <td><%= member.rank %></td>
        <td>
          <% if user == @syllabus.user %>
              <div style="display: inline-block"><span class="sy_new_name fl"><%= user.show_name %></span><span class="sy_new_orange ml5 fl mt12">创建者</span></div>
          <% else %>
              <span class="sy_new_long_name"><%= user.show_name %></span>
          <% end %>
        </td>
        <td>
          <% if user.user_extensions && user.user_extensions.identity %>
              <%= get_user_roll user %>
          <% end%>
        </td>
        <% courses = user.courses.not_deleted %>
        <td><%= courses.where("tea_id = #{user.id}").count %></td>
        <td><%= courses.where("tea_id != #{user.id}").count %></td>
        <% if is_admin %>
            <td>
              <% if user == @syllabus.user %>
              <% elsif allow_delete %>
                  <%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :confirm => l(:text_are_you_sure), :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %>
              <% else %>
                  <a href="javascript:void(0)" class="fr sy_btn_grey mr5" title="该老师已在本课程下创建了班级，不能删除">删除</a>
              <% end %>
            <% if i == 0 && count == 1 %>
                &nbsp;
            <% elsif i != 0 && i < count - 1 %>
                <%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
                <%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
            <% elsif i < count - 1 %>
                <%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
            <% elsif i == count - 1 %>
                <%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
            <% end %>
            </td>
        <% end %>
      </tr>
  <% end %>
  </tbody>
</table>