Class: DocumentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/documents_controller.rb

Overview

redMine - project management software Copyright (C) 2006-2007 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.

Instance Method Summary collapse

Methods inherited from ApplicationController

accept_key_auth, #accept_key_auth_actions, #attach_files, #authorize, #check_if_login_required, #check_project_privacy, #current_role, #deny_access, #filename_for_content_disposition, #find_current_user, #logged_user=, #parse_qvalues, #per_page_option, #redirect_back_or_default, #render_403, #render_404, #render_error, #render_feed, #require_admin, #require_login, #set_localization, #user_setup

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Methods included from Redmine::I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#add_attachmentObject



69
70
71
72
73
# File 'app/controllers/documents_controller.rb', line 69

def add_attachment
  attachments = attach_files(@document, params[:attachments])
  Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
  redirect_to :action => 'show', :id => @document
end

#destroyObject



64
65
66
67
# File 'app/controllers/documents_controller.rb', line 64

def destroy
  @document.destroy
  redirect_to :controller => 'documents', :action => 'index', :project_id => @project
end

#editObject



56
57
58
59
60
61
62
# File 'app/controllers/documents_controller.rb', line 56

def edit
  @categories = Enumeration.document_categories
  if request.post? and @document.update_attributes(params[:document])
    flash[:notice] = l(:notice_successful_update)
    redirect_to :action => 'show', :id => @document
  end
end

#indexObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/documents_controller.rb', line 25

def index
  @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
  documents = @project.documents.find :all, :include => [:attachments, :category]
  case @sort_by
  when 'date'
    @grouped = documents.group_by {|d| d.created_on.to_date }
  when 'title'
    @grouped = documents.group_by {|d| d.title.first.upcase}
  when 'author'
    @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
  else
    @grouped = documents.group_by(&:category)
  end
  @document = @project.documents.build
  render :layout => false if request.xhr?
end

#newObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/documents_controller.rb', line 46

def new
  @document = @project.documents.build(params[:document])    
  if request.post? and @document.save	
    attach_files(@document, params[:attachments])
    flash[:notice] = l(:notice_successful_create)
    Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
    redirect_to :action => 'index', :project_id => @project
  end
end

#showObject



42
43
44
# File 'app/controllers/documents_controller.rb', line 42

def show
  @attachments = @document.attachments.find(:all, :order => "created_on DESC")
end