documents_controller.rb
71 lines
| 2.5 KiB
| text/x-ruby
|
RubyLexer
|
r2 | # redMine - project management software | ||
|
r193 | # Copyright (C) 2006-2007 Jean-Philippe Lang | ||
|
r2 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU General Public License | ||||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
class DocumentsController < ApplicationController | ||||
|
r22 | layout 'base' | ||
before_filter :find_project, :authorize | ||||
def show | ||||
@attachments = @document.attachments.find(:all, :order => "created_on DESC") | ||||
|
r2 | end | ||
def edit | ||||
@categories = Enumeration::get_values('DCAT') | ||||
if request.post? and @document.update_attributes(params[:document]) | ||||
|
r15 | flash[:notice] = l(:notice_successful_update) | ||
|
r2 | redirect_to :action => 'show', :id => @document | ||
end | ||||
end | ||||
def destroy | ||||
@document.destroy | ||||
redirect_to :controller => 'projects', :action => 'list_documents', :id => @project | ||||
end | ||||
def download | ||||
@attachment = @document.attachments.find(params[:attachment_id]) | ||||
@attachment.increment_download | ||||
send_file @attachment.diskfile, :filename => @attachment.filename | ||||
|
r49 | rescue | ||
|
r130 | render_404 | ||
|
r2 | end | ||
def add_attachment | ||||
|
r127 | # Save the attachments | ||
|
r193 | @attachments = [] | ||
params[:attachments].each { |file| | ||||
next unless file.size > 0 | ||||
a = Attachment.create(:container => @document, :file => file, :author => logged_in_user) | ||||
@attachments << a unless a.new_record? | ||||
|
r127 | } if params[:attachments] and params[:attachments].is_a? Array | ||
|
r193 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | ||
|
r22 | redirect_to :action => 'show', :id => @document | ||
|
r2 | end | ||
def destroy_attachment | ||||
@document.attachments.find(params[:attachment_id]).destroy | ||||
|
r22 | redirect_to :action => 'show', :id => @document | ||
|
r2 | end | ||
private | ||||
|
r22 | def find_project | ||
|
r2 | @document = Document.find(params[:id]) | ||
|
r22 | @project = @document.project | ||
|
r130 | rescue ActiveRecord::RecordNotFound | ||
render_404 | ||||
|
r22 | end | ||
|
r2 | end | ||