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