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
This commit is contained in:
Jean-Philippe Lang 2011-07-09 20:11:18 +00:00
parent e6104d344f
commit e63f0c615c
3 changed files with 19 additions and 5 deletions

View File

@ -1,8 +1,10 @@
<span id="attachments_fields">
<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%><label class="inline"><span id="attachment_description_label_content"><%= l(:label_optional_description) %></span><%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %>
</label>
<span>
<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil, :class => 'file' -%>
<label class="inline"><%= l(:label_optional_description) %><%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil, :class => 'description' %></label>
<%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %>
</span>
</span>
<br />
<small><%= 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) %>)
</small>

View File

@ -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<f.length; i++){

View File

@ -445,6 +445,8 @@ fieldset#notified_events .parent { padding-left: 20px; }
.summary {font-style: italic;}
#attachments_fields input[type=text] {margin-left: 8px; }
#attachments_fields span {display:block; white-space:nowrap;}
#attachments_fields img {vertical-align: middle;}
div.attachments { margin-top: 12px; }
div.attachments p { margin:4px 0 2px 0; }