diff options
-rw-r--r-- | app/controllers/documents_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 32 | ||||
-rw-r--r-- | app/views/documents/show.rhtml | 7 | ||||
-rw-r--r-- | app/views/projects/add_document.rhtml | 5 | ||||
-rw-r--r-- | app/views/projects/add_file.rhtml | 5 | ||||
-rw-r--r-- | public/javascripts/application.js | 1 | ||||
-rw-r--r-- | public/stylesheets/application.css | 1 |
7 files changed, 29 insertions, 32 deletions
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 3107b3ed1..3cc8662ea 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -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
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3a6986bee..78a1e4660 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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
diff --git a/app/views/documents/show.rhtml b/app/views/documents/show.rhtml index 385b25179..ace093dc5 100644 --- a/app/views/documents/show.rhtml +++ b/app/views/documents/show.rhtml @@ -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>
- <%= 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)%>
+ <%= link_to_function image_tag('add'), "addFileField()" %></label>
+ <%= file_field_tag 'attachments[]', :size => 30 %></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
<% end %>
diff --git a/app/views/projects/add_document.rhtml b/app/views/projects/add_document.rhtml index 88572f409..e788a7bc7 100644 --- a/app/views/projects/add_document.rhtml +++ b/app/views/projects/add_document.rhtml @@ -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)%> +<%= link_to_function image_tag('add'), "addFileField()" %></label> +<%= file_field_tag 'attachments[]', :size => 30 %></p> </div> <%= submit_tag l(:button_create) %> diff --git a/app/views/projects/add_file.rhtml b/app/views/projects/add_file.rhtml index cb478cb16..41c208431 100644 --- a/app/views/projects/add_file.rhtml +++ b/app/views/projects/add_file.rhtml @@ -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)%>
+<%= link_to_function image_tag('add'), "addFileField()" %></label>
+<%= file_field_tag 'attachments[]', :size => 30 %></p>
</div>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
\ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 46649130e..3625914ab 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -15,6 +15,5 @@ function addFileField() { p = document.getElementById("attachments_p");
p.appendChild(document.createElement("br"));
- p.appendChild(document.createElement("br"));
p.appendChild(f);
}
\ No newline at end of file diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 71c19d8b6..29ca3cf86 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -204,6 +204,7 @@ blockquote { input, select {
vertical-align: middle;
+ margin-bottom: 4px;
}
input.button-small
|