added multiple file upload for documents and files modules

git-svn-id: http://redmine.rubyforge.org/svn/trunk@130 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-01-01 11:26:56 +00:00
parent 7a03cf92ba
commit ff65a5b22a
7 changed files with 29 additions and 32 deletions

View File

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

View File

@ -174,16 +174,13 @@ class ProjectsController < ApplicationController
def add_document
@categories = Enumeration::get_values('DCAT')
@document = @project.documents.build(params[:document])
if request.post?
# Save the attachment
if params[:attachment][:file].size > 0
@attachment = @document.attachments.build(params[:attachment])
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
end
if @document.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list_documents', :id => @project
end
if request.post? and @document.save
# Save the attachments
params[:attachments].each { |a|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
} if params[:attachments] and params[:attachments].is_a? Array
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list_documents', :id => @project
end
end
@ -360,14 +357,13 @@ class ProjectsController < ApplicationController
end
def add_file
@attachment = Attachment.new(params[:attachment])
if request.post? and params[:attachment][:file].size > 0
@attachment.container = @project.versions.find_by_id(params[:version_id])
@attachment.author = logged_in_user
if @attachment.save
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
if request.post?
@version = @project.versions.find_by_id(params[:version_id])
# Save the attachments
params[:attachments].each { |a|
Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0
} if params[:attachments] and params[:attachments].is_a? Array
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
@versions = @project.versions
end

View File

@ -28,9 +28,10 @@
<% if authorize_for('documents', 'add_attachment') %>
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true) %>
<label><%=l(:label_attachment_new)%></label>&nbsp;&nbsp;
<%= file_field 'attachment', 'file' %>
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
<% end %>

View File

@ -4,8 +4,9 @@
<%= render :partial => 'documents/form' %>
<div class="box">
<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)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p>
</div>
<%= submit_tag l(:button_create) %>

View File

@ -7,8 +7,9 @@
<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
<p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>
<%= file_field 'attachment', 'file' %></p>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p>
</div>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>

View File

@ -15,6 +15,5 @@ function addFileField() {
p = document.getElementById("attachments_p");
p.appendChild(document.createElement("br"));
p.appendChild(document.createElement("br"));
p.appendChild(f);
}

View File

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