To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / documents_controller.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (3.08 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | default_search_scope :documents
|
||
| 20 | model_object Document
|
||
| 21 | 1115:433d4f72a19b | Chris | before_filter :find_project_by_project_id, :only => [:index, :new, :create] |
| 22 | before_filter :find_model_object, :except => [:index, :new, :create] |
||
| 23 | before_filter :find_project_from_association, :except => [:index, :new, :create] |
||
| 24 | 0:513646585e45 | Chris | before_filter :authorize
|
| 25 | 909:cbb26bc654de | Chris | |
| 26 | 0:513646585e45 | Chris | helper :attachments
|
| 27 | 909:cbb26bc654de | Chris | |
| 28 | 0:513646585e45 | Chris | def index |
| 29 | @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' |
||
| 30 | 1295:622f24f53b42 | Chris | documents = @project.documents.includes(:attachments, :category).all |
| 31 | 0:513646585e45 | Chris | case @sort_by |
| 32 | when 'date' |
||
| 33 | @grouped = documents.group_by {|d| d.updated_on.to_date }
|
||
| 34 | when 'title' |
||
| 35 | @grouped = documents.group_by {|d| d.title.first.upcase}
|
||
| 36 | when 'author' |
||
| 37 | @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
|
||
| 38 | else
|
||
| 39 | @grouped = documents.group_by(&:category) |
||
| 40 | end
|
||
| 41 | @document = @project.documents.build |
||
| 42 | render :layout => false if request.xhr? |
||
| 43 | end
|
||
| 44 | 909:cbb26bc654de | Chris | |
| 45 | 0:513646585e45 | Chris | def show |
| 46 | 1295:622f24f53b42 | Chris | @attachments = @document.attachments.all |
| 47 | 0:513646585e45 | Chris | end
|
| 48 | |||
| 49 | def new |
||
| 50 | 929:5f33065ddc4b | Chris | @document = @project.documents.build |
| 51 | @document.safe_attributes = params[:document] |
||
| 52 | 1115:433d4f72a19b | Chris | end
|
| 53 | |||
| 54 | def create |
||
| 55 | @document = @project.documents.build |
||
| 56 | @document.safe_attributes = params[:document] |
||
| 57 | @document.save_attachments(params[:attachments]) |
||
| 58 | if @document.save |
||
| 59 | 0:513646585e45 | Chris | render_attachment_warning_if_needed(@document)
|
| 60 | flash[:notice] = l(:notice_successful_create) |
||
| 61 | 1295:622f24f53b42 | Chris | redirect_to project_documents_path(@project)
|
| 62 | 1115:433d4f72a19b | Chris | else
|
| 63 | render :action => 'new' |
||
| 64 | 0:513646585e45 | Chris | end
|
| 65 | end
|
||
| 66 | 909:cbb26bc654de | Chris | |
| 67 | 0:513646585e45 | Chris | def edit |
| 68 | 1115:433d4f72a19b | Chris | end
|
| 69 | |||
| 70 | def update |
||
| 71 | 929:5f33065ddc4b | Chris | @document.safe_attributes = params[:document] |
| 72 | 1115:433d4f72a19b | Chris | if request.put? and @document.save |
| 73 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_update) |
| 74 | 1295:622f24f53b42 | Chris | redirect_to document_path(@document)
|
| 75 | 1115:433d4f72a19b | Chris | else
|
| 76 | render :action => 'edit' |
||
| 77 | 0:513646585e45 | Chris | end
|
| 78 | 909:cbb26bc654de | Chris | end
|
| 79 | 0:513646585e45 | Chris | |
| 80 | def destroy |
||
| 81 | 1115:433d4f72a19b | Chris | @document.destroy if request.delete? |
| 82 | 1295:622f24f53b42 | Chris | redirect_to project_documents_path(@project)
|
| 83 | 0:513646585e45 | Chris | end
|
| 84 | 909:cbb26bc654de | Chris | |
| 85 | 0:513646585e45 | Chris | def add_attachment |
| 86 | attachments = Attachment.attach_files(@document, params[:attachments]) |
||
| 87 | render_attachment_warning_if_needed(@document)
|
||
| 88 | |||
| 89 | 1115:433d4f72a19b | Chris | if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') |
| 90 | Mailer.attachments_added(attachments[:files]).deliver |
||
| 91 | end
|
||
| 92 | 1295:622f24f53b42 | Chris | redirect_to document_path(@document)
|
| 93 | 0:513646585e45 | Chris | end
|
| 94 | end |