summaryrefslogtreecommitdiffstats
path: root/app/views/attachments
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-10 20:09:41 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-10 20:09:41 +0000
commitef25210aca9278e51f81bd15e85a3143c667ff17 (patch)
tree312d20360571770a231f4fd307c12d0c535d60f2 /app/views/attachments
parent2304f5d42c2bb1829b1cf9055c2848db116742d3 (diff)
downloadredmine-ef25210aca9278e51f81bd15e85a3143c667ff17.tar.gz
redmine-ef25210aca9278e51f81bd15e85a3143c667ff17.zip
Merged ajax_upload branch (#3957).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10977 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/views/attachments')
-rw-r--r--app/views/attachments/_form.html.erb34
-rw-r--r--app/views/attachments/destroy.js.erb1
-rw-r--r--app/views/attachments/upload.js.erb9
3 files changed, 32 insertions, 12 deletions
diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb
index e47c288a9..092f68244 100644
--- a/app/views/attachments/_form.html.erb
+++ b/app/views/attachments/_form.html.erb
@@ -1,18 +1,28 @@
+<span id="attachments_fields">
<% if defined?(container) && container && container.saved_attachments %>
<% container.saved_attachments.each_with_index do |attachment, i| %>
- <span class="icon icon-attachment" style="display:block; line-height:1.5em;">
- <%= h(attachment.filename) %> (<%= number_to_human_size(attachment.filesize) %>)
- <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.id}.#{attachment.digest}" %>
+ <span id="attachments_p<%= i %>">
+ <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename') +
+ text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') +
+ link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
+ <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span>
<% end %>
<% end %>
-<span id="attachments_fields">
- <span>
- <%= file_field_tag 'attachments[1][file]', :id => nil, :class => 'file',
- :onchange => "checkFileSize(this, #{Setting.attachment_max_size.to_i.kilobytes}, '#{escape_javascript(l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)))}');" -%>
- <%= text_field_tag 'attachments[1][description]', '', :id => nil, :class => 'description', :maxlength => 255, :placeholder => l(:label_optional_description) %>
- <%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %>
- </span>
</span>
-<span class="add_attachment"><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;', :class => 'add_attachment' %>
-(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</span>
+<span class="add_attachment">
+<%= file_field_tag 'attachments_files',
+ :id => nil,
+ :multiple => true,
+ :onchange => 'addInputFiles(this);',
+ :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)
+ } %>
+(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
+</span>
+
+<%= javascript_include_tag 'attachments' %>
diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb
new file mode 100644
index 000000000..3cfb5845f
--- /dev/null
+++ b/app/views/attachments/destroy.js.erb
@@ -0,0 +1 @@
+$('#attachments_<%= j params[:attachment_id] %>').remove();
diff --git a/app/views/attachments/upload.js.erb b/app/views/attachments/upload.js.erb
new file mode 100644
index 000000000..04e30b569
--- /dev/null
+++ b/app/views/attachments/upload.js.erb
@@ -0,0 +1,9 @@
+var fileSpan = $('#attachments_<%= j params[:attachment_id] %>');
+$('<input>', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan);
+fileSpan.find('a.remove-upload')
+ .attr({
+ "data-remote": true,
+ "data-method": 'delete',
+ href: '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>'
+ })
+ .off('click');