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