multiple file upload

git-svn-id: http://redmine.rubyforge.org/svn/trunk@40 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2006-11-05 18:38:20 +00:00
parent 0778ac8c1b
commit 55dded8e5f
6 changed files with 37 additions and 29 deletions

View File

@ -101,12 +101,11 @@ class IssuesController < ApplicationController
end
def add_attachment
# Save the attachment
if params[:attachment][:file].size > 0
@attachment = @issue.attachments.build(params[:attachment])
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
# Save the attachments
params[:attachments].each { |a|
@attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0
@attachment.save
end
} if params[:attachments] and params[:attachments].is_a? Array
redirect_to :action => 'show', :id => @issue
end

View File

@ -187,11 +187,10 @@ class ProjectsController < ApplicationController
else
@issue.attributes = params[:issue]
@issue.author_id = self.logged_in_user.id if self.logged_in_user
# Create the document if a file was sent
if params[:attachment][:file].size > 0
@attachment = @issue.attachments.build(params[:attachment])
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
end
# Multiple file upload
params[:attachments].each { |a|
@attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0
} if params[:attachments] and params[:attachments].is_a? Array
@custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
@issue.custom_values = @custom_values
if @issue.save

View File

@ -77,18 +77,6 @@ end %>
</p>
</div>
<% if authorize_for('issues', 'add_note') %>
<div class="box">
<h3><%= l(:label_add_note) %></h3>
<%= start_form_tag ({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular" ) %>
<p><label for="history_notes"><%=l(:field_notes)%></label>
<%= text_area 'history', 'notes', :cols => 60, :rows => 10 %></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
</div>
<% end %>
<div class="splitcontentleft">
<div class="box">
<h3><%=l(:label_history)%></h3>
<table width="100%">
@ -104,9 +92,7 @@ end %>
<% end %>
</table>
</div>
</div>
<div class="splitcontentright">
<div class="box">
<h3><%=l(:label_attachment_plural)%></h3>
<table width="100%">
@ -127,11 +113,22 @@ end %>
</table>
<br />
<% if authorize_for('issues', 'add_attachment') %>
<%= start_form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true) %>
<%=l(:label_attachment_new)%>: <%= file_field 'attachment', 'file' %>
<%= start_form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label><%=l(:label_attachment_new)%>
<%= link_to_function image_tag('add', :align => "top"), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
<% end %>
</div>
</div>
<% if authorize_for('issues', 'add_note') %>
<div class="box">
<h3><%= l(:label_add_note) %></h3>
<%= start_form_tag ({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular" ) %>
<p><label for="history_notes"><%=l(:field_notes)%></label>
<%= text_area 'history', 'notes', :cols => 60, :rows => 10 %></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
</div>
<% end %>

View File

@ -17,8 +17,9 @@
<p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>
<p><label for="attachment_file"><%=l(:label_attachment)%></label>
<%= file_field 'attachment', 'file' %></p>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
<%= link_to_function image_tag('add', :align => "top"), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p>
<!--[eoform:issue]-->
</div>

View File

@ -5,4 +5,15 @@ function checkAll (id, checked) {
el.elements[i].checked = checked;
}
}
}
function addFileField() {
var f = document.createElement("input");
f.type = "file";
f.name = "attachments[]";
f.size = 30;
p = document.getElementById("attachments_p");
p.appendChild(document.createElement("br"));
p.appendChild(f);
}

View File

@ -198,6 +198,7 @@ textarea {
input {
vertical-align: middle;
margin-bottom: 4px;
}
input.button-small