From: Jean-Philippe Lang Date: Sat, 9 Jul 2011 20:11:18 +0000 (+0000) Subject: Adds a button to remove a file upload before submission (#5670). X-Git-Tag: 1.3.0~1711 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e63f0c615cb353927ed9ff416f26e57b4f57c8b0;p=redmine.git Adds a button to remove a file upload before submission (#5670). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6212 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/views/attachments/_form.rhtml b/app/views/attachments/_form.rhtml index 6d387d1c2..b936af198 100644 --- a/app/views/attachments/_form.rhtml +++ b/app/views/attachments/_form.rhtml @@ -1,8 +1,10 @@ -<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%> + + <%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil, :class => 'file' -%> + + <%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %> + -
<%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;' %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) diff --git a/public/javascripts/application.js b/public/javascripts/application.js index e8e8e4add..19aef77b8 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -86,9 +86,9 @@ function hideFieldset(el) { var fileFieldCount = 1; function addFileField() { - if (fileFieldCount >= 10) return false - fileFieldCount++; var fields = $('attachments_fields'); + if (fields.childElements().length >= 10) return false; + fileFieldCount++; var s = document.createElement("span"); s.update(fields.down('span').innerHTML); s.down('input.file').name = "attachments[" + fileFieldCount + "][file]"; @@ -96,6 +96,16 @@ function addFileField() { fields.appendChild(s); } +function removeFileField(el) { + var fields = $('attachments_fields'); + var s = Element.up(el, 'span'); + if (fields.childElements().length > 1) { + s.remove(); + } else { + s.update(s.innerHTML); + } +} + function showTab(name) { var f = $$('div#content .tab-content'); for(var i=0; i