<h3>
  <%=l(:label_applied_shcools)%>
</h3>

<%= render 'tab_has_applied_applied' %>

<%= form_tag({}, :method => :get) do %>
    <fieldset>
      <label for='name'>
        单位名称:
      </label>
      <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '输入单位名称进行搜索' %>
      <%= submit_tag l(:button_apply ), :class => "small", :name => nil %>
      <%= link_to l(:button_clear), {:controller => 'admin', :action => 'has_applied_schools'}, :class => 'icon icon-reload' %>
    </fieldset>
<% end %>
&nbsp;

<div class="autoscroll">
  <table class="list" style="width: 100%;table-layout: fixed">
    <thead>
    <tr>
      <th style="width: 25px;">
        序号
      </th>
      <th style="width: 80px;">
        单位名称
      </th>
      <th style="width: 35px;">
        申请者
      </th>
      <th style="width: 95px;">
        地区
      </th>
      <th style="width: 75px;">
        详细地址
      </th>
      <th style="width: 85px;">
        原名
      </th>
      <th style="width: 30px;">
        用户
      </th>
      <th style="width: 65px;">
        创建时间
      </th>
      <th style="width: 75px;">
        操作
      </th>
    </tr>
    </thead>
    <tbody>
    <% @has_apply_status.each do |apply| %>
    <% if apply.status == 1 || apply.status == 2%>
        <tr class="<%= cycle("odd", "even") %>">
          <td style="text-align: center;">
            <%= apply.id %>
          </td>
          <td  class="name" title='<%=apply.name%>' >
            <% unless apply.school_id.nil? %>
                <% school_name = School.where("id=?", apply.school_id).first %>
                <span title="双击可编辑" ondblclick = "show_edit_school_name('<%= apply.id %>');" id="apply_title_<%= apply.id %>"><%= school_name.name %></span>
                <textarea style="display: none; width:100px; height:16px; border:1px solid #ddd; outline:none; padding:0 0 0 5px; resize:none; overflow:hidden;" placeholder="请编辑单位名称" id="school_name_edit_<%=apply.id%>" onblur="edit_school_name('<%= edit_apply_name_school_path(apply.id)%>','<%= apply.id %>');"></textarea>
            <% end %>
          </td>
          <td class="center">
            <% user = User.where("id=?", apply.user_id).first%>
            <% unless user.nil? %>
                <%=link_to user.show_name, user_path(user), :target => '_blank'%>
            <% end %>
          </td>
          <td class="center">
            <span ondblclick = "show_edit_school_province('<%= apply.id %>');" id="apply_province_<%= apply.id %>">
            <%= (apply.province.nil? ? "" : apply.province) + (apply.city.nil? ? "" : apply.city)  %>
            </span>
            <select onchange="showcity(this.value, document.getElementById('schoolCity_<%=apply.id%>'));edit_school_province('<%= edit_apply_province_school_path(apply.id)%>','<%= apply.id %>');" name="province" id="school_province_edit_<%=apply.id%>" class="fl" style="width:55px; height:18px; display: none">
              <option value="北京">北京</option>
              <option value="上海">上海</option>
              <option value="广东">广东</option>
              <option value="江苏">江苏</option>
              <option value="浙江">浙江</option>
              <option value="重庆">重庆</option>
              <option value="安徽">安徽</option>
              <option value="福建">福建</option>
              <option value="甘肃">甘肃</option>
              <option value="广西">广西</option>
              <option value="贵州">贵州</option>
              <option value="海南">海南</option>
              <option value="河北">河北</option>
              <option value="黑龙江">黑龙江</option>
              <option value="河南">河南</option>
              <option value="湖北">湖北</option>
              <option value="湖南">湖南</option>
              <option value="江西">江西</option>
              <option value="吉林">吉林</option>
              <option value="辽宁">辽宁</option>
              <option value="内蒙古">内蒙古</option>
              <option value="宁夏">宁夏</option>
              <option value="青海">青海</option>
              <option value="山东">山东</option>
              <option value="山西">山西</option>
              <option value="陕西">陕西</option>
              <option value="四川">四川</option>
              <option value="天津">天津</option>
              <option value="新疆">新疆</option>
              <option value="西藏">西藏</option>
              <option value="云南">云南</option>
              <option value="香港">香港特别行政区</option>
              <option value="澳门">澳门特别行政区</option>
              <option value="台湾">台湾</option>
              <option value="海外">海外</option>
            </select>
            <select onchange="edit_school_province('<%= edit_apply_province_school_path(apply.id)%>','<%= apply.id %>');" name="city" id="schoolCity_<%=apply.id%>" class="fl ml5" style="width:55px; height:18px; display: none"></select>
          </td>
          <td class="center">
            <span title="双击可编辑" ondblclick = "show_edit_school_address('<%= apply.id %>');" id="apply_address_<%= apply.id %>"><%= apply.address %></span>
            <textarea style="display: none; width:100px; height:16px; border:1px solid #ddd; outline:none; padding:0 0 0 5px; resize:none; overflow:hidden;" placeholder="请编辑单位地址" id="school_address_edit_<%=apply.id%>" onblur="edit_school_address('<%= edit_apply_address_school_path(apply.id)%>','<%= apply.id %>');"><%= apply.address %></textarea>
          </td>
          <td class="center">
            <%= apply.name %>
          </td>
          <td class="center">
            <% count = UserExtensions.where("school_id = #{apply.school_id}").count %>
            <%= count %>
          </td>
          <td class="center">
            <%= format_date(apply.created_at) %>
          </td>
          <td class="center">
            <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id, :tip => 'applied' },:method => :delete, :confirm => l(:text_are_you_sure) ) %>
          </td>
        </tr>
        <script>
            init_province_and_city(document.getElementById('school_province_edit_<%=apply.id%>'), '<%=apply.province%>', document.getElementById('schoolCity_<%=apply.id%>'), '<%=apply.city%>');
        </script>
        <% end %>
    <% end %>
    </tbody>
  </table>
</div>
<ul class="wlist" id="pages" style="float: right;margin-top: 10px;">
  <%= pagination_links_full @has_apply_pages, @has_apply_count ,:per_page_links => true, :remote => false, :flag => true %>
</ul>