##// END OF EJS Templates
association loading in documents/show...
Jean-Philippe Lang -
r22:dc26a9cd39be
parent child
Show More
@@ -1,65 +1,65
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class DocumentsController < ApplicationController
19 layout 'base'
20 before_filter :find_project, :authorize
21
22 def show
19 layout 'base'
20 before_filter :find_project, :authorize
21
22 def show
23 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
23 24 end
24 25
25 26 def edit
26 27 @categories = Enumeration::get_values('DCAT')
27 28 if request.post? and @document.update_attributes(params[:document])
28 29 flash[:notice] = l(:notice_successful_update)
29 30 redirect_to :action => 'show', :id => @document
30 31 end
31 32 end
32 33
33 34 def destroy
34 35 @document.destroy
35 36 redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
36 37 end
37 38
38 39 def download
39 40 @attachment = @document.attachments.find(params[:attachment_id])
40 41 @attachment.increment_download
41 42 send_file @attachment.diskfile, :filename => @attachment.filename
42 43 end
43 44
44 45 def add_attachment
45 46 # Save the attachment
46 47 if params[:attachment][:file].size > 0
47 48 @attachment = @document.attachments.build(params[:attachment])
48 49 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
49 50 @attachment.save
50 51 end
51 render :action => 'show'
52 redirect_to :action => 'show', :id => @document
52 53 end
53 54
54 55 def destroy_attachment
55 56 @document.attachments.find(params[:attachment_id]).destroy
56 render :action => 'show'
57 redirect_to :action => 'show', :id => @document
57 58 end
58 59
59 60 private
60 def find_project
61 def find_project
61 62 @document = Document.find(params[:id])
62 @project = @document.project
63 end
64
63 @project = @document.project
64 end
65 65 end
@@ -1,47 +1,47
1 1 <h2><%= @document.title %></h2>
2 2
3 3 <strong><%=l(:field_description)%>:</strong> <%= @document.description %><br />
4 4 <strong><%=l(:field_category)%>:</strong> <%= @document.category.name %><br />
5 5 <br />
6 6
7 7 <% if authorize_for('documents', 'edit') %>
8 8 <%= start_form_tag({ :controller => 'documents', :action => 'edit', :id => @document }, :method => 'get' ) %>
9 9 <%= submit_tag l(:button_edit) %>
10 10 <%= end_form_tag %>
11 11 <% end %>
12 12
13 13 <% if authorize_for('documents', 'destroy') %>
14 14 <%= start_form_tag({ :controller => 'documents', :action => 'destroy', :id => @document } ) %>
15 15 <%= submit_tag l(:button_delete) %>
16 16 <%= end_form_tag %>
17 17 <% end %>
18 18
19 19 <br /><br />
20 20
21 <table border="0" cellspacing="1" cellpadding="2" width="100%">
22 <% for attachment in @document.attachments %>
23 <tr style="background-color:#CEE1ED">
21 <table class="listTableContent">
22 <% for attachment in @attachments %>
23 <tr class="<%= cycle("odd", "even") %>">
24 <td><%= format_date(attachment.created_on) %></td>
24 25 <td><%= link_to attachment.filename, :action => 'download', :id => @document, :attachment_id => attachment %></td>
25 <td align="center"><%= format_date(attachment.created_on) %></td>
26 26 <td align="center"><%= attachment.author.display_name %></td>
27 27 <td><%= human_size(attachment.filesize) %><br /><%= lwr(:label_download, attachment.downloads) %></td>
28 28
29 29 <% if authorize_for('documents', 'destroy_attachment') %>
30 30 <td align="center">
31 31 <%= start_form_tag :action => 'destroy_attachment', :id => @document, :attachment_id => attachment %>
32 32 <%= submit_tag l(:button_delete), :class => "button-small" %>
33 33 <%= end_form_tag %>
34 34 </tr>
35 35 <% end %>
36 36
37 37 <% end %>
38 38 </table>
39 39 <br />
40 40
41 41 <% if authorize_for('documents', 'add_attachment') %>
42 42 <%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true) %>
43 43 <%=l(:label_attachment_new)%><br /><%= file_field 'attachment', 'file' %>
44 44 <%= submit_tag l(:button_add) %>
45 45 <%= end_form_tag %>
46 46 <% end %>
47 47
General Comments 0
You need to be logged in to leave comments. Login now