comparison app/controllers/documents_controller.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
25 25
26 helper :attachments 26 helper :attachments
27 27
28 def index 28 def index
29 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' 29 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
30 documents = @project.documents.find :all, :include => [:attachments, :category] 30 documents = @project.documents.includes(:attachments, :category).all
31 case @sort_by 31 case @sort_by
32 when 'date' 32 when 'date'
33 @grouped = documents.group_by {|d| d.updated_on.to_date } 33 @grouped = documents.group_by {|d| d.updated_on.to_date }
34 when 'title' 34 when 'title'
35 @grouped = documents.group_by {|d| d.title.first.upcase} 35 @grouped = documents.group_by {|d| d.title.first.upcase}
41 @document = @project.documents.build 41 @document = @project.documents.build
42 render :layout => false if request.xhr? 42 render :layout => false if request.xhr?
43 end 43 end
44 44
45 def show 45 def show
46 @attachments = @document.attachments.find(:all, :order => "created_on DESC") 46 @attachments = @document.attachments.all
47 end 47 end
48 48
49 def new 49 def new
50 @document = @project.documents.build 50 @document = @project.documents.build
51 @document.safe_attributes = params[:document] 51 @document.safe_attributes = params[:document]
56 @document.safe_attributes = params[:document] 56 @document.safe_attributes = params[:document]
57 @document.save_attachments(params[:attachments]) 57 @document.save_attachments(params[:attachments])
58 if @document.save 58 if @document.save
59 render_attachment_warning_if_needed(@document) 59 render_attachment_warning_if_needed(@document)
60 flash[:notice] = l(:notice_successful_create) 60 flash[:notice] = l(:notice_successful_create)
61 redirect_to :action => 'index', :project_id => @project 61 redirect_to project_documents_path(@project)
62 else 62 else
63 render :action => 'new' 63 render :action => 'new'
64 end 64 end
65 end 65 end
66 66
69 69
70 def update 70 def update
71 @document.safe_attributes = params[:document] 71 @document.safe_attributes = params[:document]
72 if request.put? and @document.save 72 if request.put? and @document.save
73 flash[:notice] = l(:notice_successful_update) 73 flash[:notice] = l(:notice_successful_update)
74 redirect_to :action => 'show', :id => @document 74 redirect_to document_path(@document)
75 else 75 else
76 render :action => 'edit' 76 render :action => 'edit'
77 end 77 end
78 end 78 end
79 79
80 def destroy 80 def destroy
81 @document.destroy if request.delete? 81 @document.destroy if request.delete?
82 redirect_to :controller => 'documents', :action => 'index', :project_id => @project 82 redirect_to project_documents_path(@project)
83 end 83 end
84 84
85 def add_attachment 85 def add_attachment
86 attachments = Attachment.attach_files(@document, params[:attachments]) 86 attachments = Attachment.attach_files(@document, params[:attachments])
87 render_attachment_warning_if_needed(@document) 87 render_attachment_warning_if_needed(@document)
88 88
89 if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') 89 if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
90 Mailer.attachments_added(attachments[:files]).deliver 90 Mailer.attachments_added(attachments[:files]).deliver
91 end 91 end
92 redirect_to :action => 'show', :id => @document 92 redirect_to document_path(@document)
93 end 93 end
94 end 94 end