OSDN Git Service

added svn:eol-style native property on /app files
[redminele/redmine.git] / app / controllers / documents_controller.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2007  Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 class DocumentsController < ApplicationController
19   layout 'base'
20   before_filter :find_project, :authorize
21
22   def show
23     @attachments = @document.attachments.find(:all, :order => "created_on DESC")
24   end
25
26   def edit
27     @categories = Enumeration::get_values('DCAT')
28     if request.post? and @document.update_attributes(params[:document])
29       flash[:notice] = l(:notice_successful_update)
30       redirect_to :action => 'show', :id => @document
31     end
32   end  
33
34   def destroy
35     @document.destroy
36     redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
37   end
38
39   def download
40     @attachment = @document.attachments.find(params[:attachment_id])
41     @attachment.increment_download
42     send_file @attachment.diskfile, :filename => @attachment.filename
43   rescue
44     render_404
45   end 
46   
47   def add_attachment
48     # Save the attachments
49     @attachments = []
50     params[:attachments].each { |file|
51       next unless file.size > 0
52       a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
53       @attachments << a unless a.new_record?
54     } if params[:attachments] and params[:attachments].is_a? Array
55     Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
56     redirect_to :action => 'show', :id => @document
57   end
58   
59   def destroy_attachment
60     @document.attachments.find(params[:attachment_id]).destroy
61     redirect_to :action => 'show', :id => @document
62   end
63
64 private
65   def find_project
66     @document = Document.find(params[:id])
67     @project = @document.project
68   rescue ActiveRecord::RecordNotFound
69     render_404
70   end  
71 end