<% delete_allowed = User.current.admin? %>

<% org_subfield_attachments.each do |file| %>
  <% if file.is_public == 1 or User.current.member_of_org?(file.container.organization) %>
    <div class="resources mt10" id="container_files_<%= file.id %>">
        <div class="homepagePostBrief">
          <div class="homepagePostPortrait">
            <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %>
          </div>
          <div class="homepagePostDes">
            <div class="homepagePostTitle break_word">
              <%# 如果有历史版本则提供历史版本下载 %>
              <% if file.attachment_histories.count == 0 %>
                  <%= link_to file.is_public? ? truncate(file.filename, length: 45) : truncate(file.filename,length: 35, omission: '...'),
                              download_named_attachment_path(file.id, file.filename),
                              :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14"  %>
              <% else %>
                  <%= link_to truncate(file.filename,length: 35, omission: '...'), attachment_history_download_path(file.id),
                              :title => file.filename+"\n"+file.description.to_s,
                              :class => "linkGrey3 f_14",
                              :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;", :remote=>true %>
              <% end %>
              <%= file_preview_eye(file, class: 'preview') %>
              <span id="image_private_<%= file.id%>">
                <% if file.is_public? == false%>
                   <span class="img_private ml5">私有</span>
                <%end %>
              </span>
              <br/>
            </div>
            <div class="mt5">
              <span class="fontGrey2 mr15 fl">上传时间：<%= format_date(file.created_on)%></span>
              <% if file.tag_list.length > 0%>
                  <span class="fontGrey2 fl mr15">上传类型：<%= file.tag_list[0] %></span>
              <% end %>
              <p class="f_l mb5 fontGrey2">文件大小：<%= number_to_human_size(file.filesize) %></p>
              <p class="fl ml15 fontGrey2">下载<%= file.downloads%>&nbsp;&nbsp;|&nbsp;&nbsp;引用<span id="reference_number_<%= file.id %>"><%= file.quotes.nil? ? 0:file.quotes  %></span></p>
            </div>
            <div class="cl"></div>
            <div class="tag_h">
              <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6"} %>
              <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6"} %>
            </div>
            <div class="homepagePostSetting">
              <ul>
                <% if User.current.logged? %>
                <li class="homepagePostSettingIcon">
                     <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield"  %>
                        <ul class="homepagePostSettiongText">
                          <li><%= link_to("发&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')")  %></li>
                            <li><%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %></li>
                          <% if file.container.try(:organization).try(:is_public?) %>
                            <li>
                              <span id="is_public_<%= file.id %>">
                                <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post  %>
                              </span>
                            </li>
                          <% end %>
                            <li>
                              <%= link_to( '删除资源', attachment_path(file),
                                               :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" && file.destroyable %>
                            </li>
                        </ul>
                      <%else%>
                          <ul class="resourceSendO">
                            <li><%= link_to("发&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')")  %></li>
                          </ul>
                      <% end %>
                </li>
                <% end %>
              </ul>

            </div>
          </div>
          <div class="cl"></div>
        </div>

  </div><!---re_con_box end-->
  <% end %>
<% end %>

<% if org_subfield_attachments.count == 10 %>
    <% if params[:action] == 'search_files_in_subfield' %>
        <%=link_to "点击展开更多",  search_files_in_subfield_org_subfield_files_path(:org_subfield_id => org_subfield.id,:page => @page.to_i + 1, :name => params[:name],:insite => params[:insite]),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %>
    <% else %>
        <!-- 全站搜索的时候 返回的页码对象是obj_pages,而站内搜索返回的页码对象是feedback_pages -->
        <%=link_to "点击展开更多",  org_subfield_files_path(:org_subfield_id => org_subfield.id, :page => @page.nil? ? 2 :(@page.to_i + 1)), :id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %>
    <%end%>
<% end%>

