documents_controller.rb
66 lines
| 2.3 KiB
| text/x-ruby
|
RubyLexer
|
r2 | # redMine - project management software | ||
# Copyright (C) 2006 Jean-Philippe Lang | ||||
# | ||||
# 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 | ||
flash.now[:notice] = l(:notice_file_not_found) | ||||
render :text => "", :layout => true, :status => 404 | ||||
|
r2 | end | ||
def add_attachment | ||||
|
r127 | # Save the attachments | ||
params[:attachments].each { |a| | ||||
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | ||||
} if params[:attachments] and params[:attachments].is_a? Array | ||||
|
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 | ||
end | ||||
|
r2 | end | ||