summaryrefslogtreecommitdiffstats
path: root/app/views/attachments/_form.html.erb
blob: 7bda59c95b9555e5af14acd6400ab6d5dc2400d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<% attachment_param ||= 'attachments' %>
<% attachment_format_custom_field ||= false %>
<% saved_attachments ||= container.saved_attachments if defined?(container) && container %>
<% multiple = true unless defined?(multiple) && multiple == false %>
<% show_add = multiple || saved_attachments.blank? %>
<% description = (defined?(description) && description == false ? false : true) %>
<% css_class = (defined?(filedrop) && filedrop == false ? '' : (attachment_format_custom_field ? 'custom-field-filedrop' : 'filedrop')) %>

<span class="attachments_form">
  <span class="attachments_fields">
  <% if saved_attachments.present? %>
    <% saved_attachments.each_with_index do |attachment, i| %>
      <span id="attachments_p<%= i %>">
        <%= text_field_tag("#{attachment_param}[p#{i}][filename]", attachment.filename, :class => 'filename') %>
        <% if attachment.container_id.present? %>
          <%= link_to l(:label_delete), "#", :onclick => "$(this).closest('.attachments_form').find('.add_attachment').show(); $(this).parent().remove(); return false;", :class => 'icon-only icon-del' %>
          <%= hidden_field_tag "#{attachment_param}[p#{i}][id]", attachment.id %>
        <% else %>
          <%= text_field_tag("#{attachment_param}[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') if description %>
          <%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'icon-only icon-del remove-upload') %>
          <%= hidden_field_tag "#{attachment_param}[p#{i}][token]", attachment.token %>
        <% end %>
      </span>
    <% end %>
  <% end %>
  </span>
  <span class="add_attachment" style="<%= show_add ? nil : 'display:none;' %>">
    <%= file_field_tag "#{attachment_param}[dummy][file]",
        :id => nil,
        :class => "file_selector #{css_class}",
        :multiple => multiple,
        :onchange => 'addInputFiles(this);',
        :data => {
          :max_number_of_files_message => l(:error_attachments_too_many, :max_number_of_files => (multiple ? 10 : 1)),
          :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'),
          :param => attachment_param,
          :description => description,
          :description_placeholder => l(:label_optional_description)
        } %>
    (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
  </span>
</span>

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