<% if defined?(container) %>
<span id="attachments_fields<%= container.id %>" class="attachments_fields" xmlns="http://www.w3.org/1999/html">
<% if defined?(container) && container && container.saved_attachments %>
  <% if isReply  %>
  <% container.saved_attachments.each_with_index do |attachment, i| %>
    <span id="attachments_p<%= i %>" class="sub_btn">

      <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
      <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
      <span class="ispublic-label"><%= l(:field_is_public)%>:</span>
      <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%>

      <%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
      <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
     <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
    </span>
  <% end %>
  <% else %>
  <% container.attachments.each_with_index do |attachment, i| %>
    <span id="attachments_p<%= i %>" class="attachment">

      <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
      <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
          <span class="ispublic-label"><%= l(:field_is_public)%>:</span>
              <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%>

              <%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), 'data-containerid'=>"#{container.id}",:method => 'delete', :remote => true, :class => 'remove-upload') %>
              <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>

      <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
    </span>
  <% end %>
  <% end %>
<% end %>
</span>
<script type='text/javascript'>
    //    function CompatibleSend()
    //    {
    //        var obj=document.getElementById("_file");
    //        var file= $(obj).clone();
    //        file.click();
    //    }
</script>
<span class="add_attachment" data-containerid="<%= container.id %>">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
  <!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
  <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file#{container.id}.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %>
  <%= file_field_tag 'attachments[dummy][file]',
                     :id => "_file#{container.id}",
                     :class => 'file_selector',
                     :multiple => true,
                     :onchange => "addInputFiles_board(this, '#{container.id}');",
                     :style => 'display:none',
                     :data => {
                             :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
                             :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
                             :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
                             :upload_path => uploads_path(:format => 'js'),
                             :description_placeholder => l(:label_optional_description),
                             :field_is_public => l(:field_is_public),
                             :are_you_sure => l(:text_are_you_sure),
                             :file_count => l(:label_file_count),
                             :delete_all_files => l(:text_are_you_sure_all),
                             :containerid => "#{container.id}"
                     } %>
  <span id="upload_file_count<%=container.id %>" :class="c_grey"><%= l(:label_no_file_uploaded)%></span>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</span>
<% else %>
    <span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
<% if defined?(container) && container && container.saved_attachments %>
  <% if isReply  %>
  <% container.saved_attachments.each_with_index do |attachment, i| %>
    <span id="attachments_p<%= i %>" class="sub_btn">
      <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
      <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") +
                  link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
      <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
      <span class="ispublic-label"><%= l(:field_is_public)%>:</span>
      <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%>
      <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
    </span>
  <% end %>
  <% else %>
  <% container.attachments.each_with_index do |attachment, i| %>
    <span id="attachments_p<%= i %>" class="attachment">
      <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
      <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") +
                  link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
      <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
      <span class="ispublic-label"><%= l(:field_is_public)%>:</span>
      <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%>
      <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
    </span>
  <% end %>
  <% end %>
<% end %>
</span>
    <script type='text/javascript'>
        //    function CompatibleSend()
        //    {
        //        var obj=document.getElementById("_file");
        //        var file= $(obj).clone();
        //        file.click();
        //    }
    </script>
    <span class="add_attachment">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
      <!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
      <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %>
      <%= file_field_tag 'attachments[dummy][file]',
                         :id => '_file',
                         :class => 'file_selector',
                         :multiple => true,
                         :onchange => 'addInputFiles(this);',
                         :style => 'display:none',
                         :data => {
                                 :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
                                 :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
                                 :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
                                 :upload_path => uploads_path(:format => 'js'),
                                 :description_placeholder => l(:label_optional_description),
                                 :field_is_public => l(:field_is_public),
                                 :are_you_sure => l(:text_are_you_sure),
                                 :file_count => l(:label_file_count),
                                 :delete_all_files => l(:text_are_you_sure_all)
                         } %>
      <% if defined?(container) %>
        <span id="upload_file_count" class="c_grey"><%= l(:label_no_file_uploaded)%></span>
     <% end %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</span>

<% end %>
<% content_for :header_tags do %>
    <%= javascript_include_tag 'attachments' %>
<% end %>


