##// END OF EJS Templates
Preserve uploaded files when on documents....
Jean-Philippe Lang -
r8824:8f24aa6c676b
parent child
Show More
@@ -1,89 +1,89
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class DocumentsController < ApplicationController
19 19 default_search_scope :documents
20 20 model_object Document
21 21 before_filter :find_project_by_project_id, :only => [:index, :new, :create]
22 22 before_filter :find_model_object, :except => [:index, :new, :create]
23 23 before_filter :find_project_from_association, :except => [:index, :new, :create]
24 24 before_filter :authorize
25 25
26 26 helper :attachments
27 27
28 28 def index
29 29 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
30 30 documents = @project.documents.find :all, :include => [:attachments, :category]
31 31 case @sort_by
32 32 when 'date'
33 33 @grouped = documents.group_by {|d| d.updated_on.to_date }
34 34 when 'title'
35 35 @grouped = documents.group_by {|d| d.title.first.upcase}
36 36 when 'author'
37 37 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
38 38 else
39 39 @grouped = documents.group_by(&:category)
40 40 end
41 41 @document = @project.documents.build
42 42 render :layout => false if request.xhr?
43 43 end
44 44
45 45 def show
46 46 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
47 47 end
48 48
49 49 def new
50 50 @document = @project.documents.build(params[:document])
51 51 end
52 52
53 53 def create
54 54 @document = @project.documents.build(params[:document])
55 if request.post? and @document.save
56 attachments = Attachment.attach_files(@document, params[:attachments])
55 @document.save_attachments(params[:attachments])
56 if @document.save
57 57 render_attachment_warning_if_needed(@document)
58 58 flash[:notice] = l(:notice_successful_create)
59 59 redirect_to :action => 'index', :project_id => @project
60 60 else
61 61 render :action => 'new'
62 62 end
63 63 end
64 64
65 65 def edit
66 66 end
67 67
68 68 def update
69 69 if request.put? and @document.update_attributes(params[:document])
70 70 flash[:notice] = l(:notice_successful_update)
71 71 redirect_to :action => 'show', :id => @document
72 72 else
73 73 render :action => 'edit'
74 74 end
75 75 end
76 76
77 77 def destroy
78 78 @document.destroy if request.delete?
79 79 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
80 80 end
81 81
82 82 def add_attachment
83 83 attachments = Attachment.attach_files(@document, params[:attachments])
84 84 render_attachment_warning_if_needed(@document)
85 85
86 86 Mailer.deliver_attachments_added(attachments[:files]) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
87 87 redirect_to :action => 'show', :id => @document
88 88 end
89 89 end
@@ -1,15 +1,15
1 1 <%= f.error_messages %>
2 2
3 3 <div class="box tabular">
4 4 <p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
5 5 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
6 6 <p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
7 7 </div>
8 8
9 9 <%= wikitoolbar_for 'document_description' %>
10 10
11 11 <% if @document.new_record? %>
12 12 <div class="box tabular">
13 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
13 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form', :locals => {:container => @document} %></p>
14 14 </div>
15 15 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now