From 55dded8e5fbba512c6026d1a3e5c7847cb93688d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 5 Nov 2006 18:38:20 +0000 Subject: [PATCH] multiple file upload git-svn-id: http://redmine.rubyforge.org/svn/trunk@40 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- redmine/app/controllers/issues_controller.rb | 9 +++--- .../app/controllers/projects_controller.rb | 9 +++--- redmine/app/views/issues/show.rhtml | 31 +++++++++---------- redmine/app/views/projects/add_issue.rhtml | 5 +-- redmine/public/javascripts/application.js | 11 +++++++ redmine/public/stylesheets/application.css | 1 + 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/redmine/app/controllers/issues_controller.rb b/redmine/app/controllers/issues_controller.rb index 8bf3805d..d428c75b 100644 --- a/redmine/app/controllers/issues_controller.rb +++ b/redmine/app/controllers/issues_controller.rb @@ -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 diff --git a/redmine/app/controllers/projects_controller.rb b/redmine/app/controllers/projects_controller.rb index 8666dae0..9e1dc14e 100644 --- a/redmine/app/controllers/projects_controller.rb +++ b/redmine/app/controllers/projects_controller.rb @@ -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 diff --git a/redmine/app/views/issues/show.rhtml b/redmine/app/views/issues/show.rhtml index b1affb5a..104d3365 100644 --- a/redmine/app/views/issues/show.rhtml +++ b/redmine/app/views/issues/show.rhtml @@ -77,18 +77,6 @@ end %>

-<% if authorize_for('issues', 'add_note') %> -
-

<%= l(:label_add_note) %>

- <%= start_form_tag ({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular" ) %> -

- <%= text_area 'history', 'notes', :cols => 60, :rows => 10 %>

- <%= submit_tag l(:button_add) %> - <%= end_form_tag %> -
-<% end %> - -

<%=l(:label_history)%>

@@ -104,9 +92,7 @@ end %> <% end %>
-
-

<%=l(:label_attachment_plural)%>

@@ -127,11 +113,22 @@ end %>

<% 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") %> +

+ <%= file_field_tag 'attachments[]', :size => 30 %>

<%= submit_tag l(:button_add) %> <%= end_form_tag %> <% end %>
-
+<% if authorize_for('issues', 'add_note') %> +
+

<%= l(:label_add_note) %>

+ <%= start_form_tag ({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular" ) %> +

+ <%= text_area 'history', 'notes', :cols => 60, :rows => 10 %>

+ <%= submit_tag l(:button_add) %> + <%= end_form_tag %> +
+<% end %> diff --git a/redmine/app/views/projects/add_issue.rhtml b/redmine/app/views/projects/add_issue.rhtml index 11e61d6b..3e22940b 100644 --- a/redmine/app/views/projects/add_issue.rhtml +++ b/redmine/app/views/projects/add_issue.rhtml @@ -17,8 +17,9 @@

<%= custom_field_tag_with_label @custom_value %>

<% end %> -

-<%= file_field 'attachment', 'file' %>

+

+<%= file_field_tag 'attachments[]', :size => 30 %>

diff --git a/redmine/public/javascripts/application.js b/redmine/public/javascripts/application.js index d8083a95..3625914a 100644 --- a/redmine/public/javascripts/application.js +++ b/redmine/public/javascripts/application.js @@ -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); } \ No newline at end of file diff --git a/redmine/public/stylesheets/application.css b/redmine/public/stylesheets/application.css index d4b3bc5f..ef9736bd 100644 --- a/redmine/public/stylesheets/application.css +++ b/redmine/public/stylesheets/application.css @@ -198,6 +198,7 @@ textarea { input { vertical-align: middle; + margin-bottom: 4px; } input.button-small