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:
parent
7a03cf92ba
commit
ff65a5b22a
|
@ -46,12 +46,10 @@ class DocumentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_attachment
|
def add_attachment
|
||||||
# Save the attachment
|
# Save the attachments
|
||||||
if params[:attachment][:file].size > 0
|
params[:attachments].each { |a|
|
||||||
@attachment = @document.attachments.build(params[:attachment])
|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
|
||||||
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
|
} if params[:attachments] and params[:attachments].is_a? Array
|
||||||
@attachment.save
|
|
||||||
end
|
|
||||||
redirect_to :action => 'show', :id => @document
|
redirect_to :action => 'show', :id => @document
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -174,16 +174,13 @@ class ProjectsController < ApplicationController
|
||||||
def add_document
|
def add_document
|
||||||
@categories = Enumeration::get_values('DCAT')
|
@categories = Enumeration::get_values('DCAT')
|
||||||
@document = @project.documents.build(params[:document])
|
@document = @project.documents.build(params[:document])
|
||||||
if request.post?
|
if request.post? and @document.save
|
||||||
# Save the attachment
|
# Save the attachments
|
||||||
if params[:attachment][:file].size > 0
|
params[:attachments].each { |a|
|
||||||
@attachment = @document.attachments.build(params[:attachment])
|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
|
||||||
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
|
} if params[:attachments] and params[:attachments].is_a? Array
|
||||||
end
|
flash[:notice] = l(:notice_successful_create)
|
||||||
if @document.save
|
redirect_to :action => 'list_documents', :id => @project
|
||||||
flash[:notice] = l(:notice_successful_create)
|
|
||||||
redirect_to :action => 'list_documents', :id => @project
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -360,14 +357,13 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_file
|
def add_file
|
||||||
@attachment = Attachment.new(params[:attachment])
|
if request.post?
|
||||||
if request.post? and params[:attachment][:file].size > 0
|
@version = @project.versions.find_by_id(params[:version_id])
|
||||||
@attachment.container = @project.versions.find_by_id(params[:version_id])
|
# Save the attachments
|
||||||
@attachment.author = logged_in_user
|
params[:attachments].each { |a|
|
||||||
if @attachment.save
|
Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0
|
||||||
flash[:notice] = l(:notice_successful_create)
|
} if params[:attachments] and params[:attachments].is_a? Array
|
||||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@versions = @project.versions
|
@versions = @project.versions
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
|
|
||||||
<% if authorize_for('documents', 'add_attachment') %>
|
<% if authorize_for('documents', 'add_attachment') %>
|
||||||
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true) %>
|
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %>
|
||||||
<label><%=l(:label_attachment_new)%></label>
|
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
|
||||||
<%= file_field 'attachment', 'file' %>
|
<%= link_to_function image_tag('add'), "addFileField()" %></label>
|
||||||
|
<%= file_field_tag 'attachments[]', :size => 30 %></p>
|
||||||
<%= submit_tag l(:button_add) %>
|
<%= submit_tag l(:button_add) %>
|
||||||
<%= end_form_tag %>
|
<%= end_form_tag %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
<%= render :partial => 'documents/form' %>
|
<%= render :partial => 'documents/form' %>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<p><label for="attachment_file"><%=l(:label_attachment)%></label>
|
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
|
||||||
<%= file_field 'attachment', 'file' %></p>
|
<%= link_to_function image_tag('add'), "addFileField()" %></label>
|
||||||
|
<%= file_field_tag 'attachments[]', :size => 30 %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= submit_tag l(:button_create) %>
|
<%= submit_tag l(:button_create) %>
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
|
<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>
|
<%= 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>
|
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
|
||||||
<%= file_field 'attachment', 'file' %></p>
|
<%= link_to_function image_tag('add'), "addFileField()" %></label>
|
||||||
|
<%= file_field_tag 'attachments[]', :size => 30 %></p>
|
||||||
</div>
|
</div>
|
||||||
<%= submit_tag l(:button_add) %>
|
<%= submit_tag l(:button_add) %>
|
||||||
<%= end_form_tag %>
|
<%= end_form_tag %>
|
|
@ -15,6 +15,5 @@ function addFileField() {
|
||||||
|
|
||||||
p = document.getElementById("attachments_p");
|
p = document.getElementById("attachments_p");
|
||||||
p.appendChild(document.createElement("br"));
|
p.appendChild(document.createElement("br"));
|
||||||
p.appendChild(document.createElement("br"));
|
|
||||||
p.appendChild(f);
|
p.appendChild(f);
|
||||||
}
|
}
|
|
@ -204,6 +204,7 @@ blockquote {
|
||||||
|
|
||||||
input, select {
|
input, select {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.button-small
|
input.button-small
|
||||||
|
|
Loading…
Reference in New Issue