##// END OF EJS Templates
added multiple file upload for documents and files modules...
Jean-Philippe Lang -
r127:ff65a5b22a54
parent child
Show More
@@ -46,12 +46,10 class DocumentsController < ApplicationController
46 end
46 end
47
47
48 def add_attachment
48 def add_attachment
49 # Save the attachment
49 # Save the attachments
50 if params[:attachment][:file].size > 0
50 params[:attachments].each { |a|
51 @attachment = @document.attachments.build(params[:attachment])
51 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
52 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
52 } if params[:attachments] and params[:attachments].is_a? Array
53 @attachment.save
54 end
55 redirect_to :action => 'show', :id => @document
53 redirect_to :action => 'show', :id => @document
56 end
54 end
57
55
@@ -174,16 +174,13 class ProjectsController < ApplicationController
174 def add_document
174 def add_document
175 @categories = Enumeration::get_values('DCAT')
175 @categories = Enumeration::get_values('DCAT')
176 @document = @project.documents.build(params[:document])
176 @document = @project.documents.build(params[:document])
177 if request.post?
177 if request.post? and @document.save
178 # Save the attachment
178 # Save the attachments
179 if params[:attachment][:file].size > 0
179 params[:attachments].each { |a|
180 @attachment = @document.attachments.build(params[:attachment])
180 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
181 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
181 } if params[:attachments] and params[:attachments].is_a? Array
182 end
182 flash[:notice] = l(:notice_successful_create)
183 if @document.save
183 redirect_to :action => 'list_documents', :id => @project
184 flash[:notice] = l(:notice_successful_create)
185 redirect_to :action => 'list_documents', :id => @project
186 end
187 end
184 end
188 end
185 end
189
186
@@ -360,14 +357,13 class ProjectsController < ApplicationController
360 end
357 end
361
358
362 def add_file
359 def add_file
363 @attachment = Attachment.new(params[:attachment])
360 if request.post?
364 if request.post? and params[:attachment][:file].size > 0
361 @version = @project.versions.find_by_id(params[:version_id])
365 @attachment.container = @project.versions.find_by_id(params[:version_id])
362 # Save the attachments
366 @attachment.author = logged_in_user
363 params[:attachments].each { |a|
367 if @attachment.save
364 Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0
368 flash[:notice] = l(:notice_successful_create)
365 } if params[:attachments] and params[:attachments].is_a? Array
369 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
366 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
370 end
371 end
367 end
372 @versions = @project.versions
368 @versions = @project.versions
373 end
369 end
@@ -28,9 +28,10
28
28
29
29
30 <% if authorize_for('documents', 'add_attachment') %>
30 <% if authorize_for('documents', 'add_attachment') %>
31 <%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true) %>
31 <%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %>
32 <label><%=l(:label_attachment_new)%></label>&nbsp;&nbsp;
32 <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
33 <%= file_field 'attachment', 'file' %>
33 <%= link_to_function image_tag('add'), "addFileField()" %></label>
34 <%= file_field_tag 'attachments[]', :size => 30 %></p>
34 <%= submit_tag l(:button_add) %>
35 <%= submit_tag l(:button_add) %>
35 <%= end_form_tag %>
36 <%= end_form_tag %>
36 <% end %>
37 <% end %>
@@ -4,8 +4,9
4 <%= render :partial => 'documents/form' %>
4 <%= render :partial => 'documents/form' %>
5
5
6 <div class="box">
6 <div class="box">
7 <p><label for="attachment_file"><%=l(:label_attachment)%></label>
7 <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
8 <%= file_field 'attachment', 'file' %></p>
8 <%= link_to_function image_tag('add'), "addFileField()" %></label>
9 <%= file_field_tag 'attachments[]', :size => 30 %></p>
9 </div>
10 </div>
10
11
11 <%= submit_tag l(:button_create) %>
12 <%= submit_tag l(:button_create) %>
@@ -7,8 +7,9
7 <p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
7 <p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
8 <%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
8 <%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
9
9
10 <p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>
10 <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
11 <%= file_field 'attachment', 'file' %></p>
11 <%= link_to_function image_tag('add'), "addFileField()" %></label>
12 <%= file_field_tag 'attachments[]', :size => 30 %></p>
12 </div>
13 </div>
13 <%= submit_tag l(:button_add) %>
14 <%= submit_tag l(:button_add) %>
14 <%= end_form_tag %> No newline at end of file
15 <%= end_form_tag %>
@@ -15,6 +15,5 function addFileField() {
15
15
16 p = document.getElementById("attachments_p");
16 p = document.getElementById("attachments_p");
17 p.appendChild(document.createElement("br"));
17 p.appendChild(document.createElement("br"));
18 p.appendChild(document.createElement("br"));
19 p.appendChild(f);
18 p.appendChild(f);
20 } No newline at end of file
19 }
@@ -204,6 +204,7 blockquote {
204
204
205 input, select {
205 input, select {
206 vertical-align: middle;
206 vertical-align: middle;
207 margin-bottom: 4px;
207 }
208 }
208
209
209 input.button-small
210 input.button-small
General Comments 0
You need to be logged in to leave comments. Login now