@@ -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 |
|
|
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 |
|
|
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 |
|
|
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> |
|
32 | <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%> | |
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)%> |
|
7 | <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%> | |
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)%> |
|
10 | <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%> | |
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 | } |
General Comments 0
You need to be logged in to leave comments.
Login now