##// END OF EJS Templates
Preserve uploaded files when on news....
Jean-Philippe Lang -
r8822:707ce0beeff8
parent child
Show More
@@ -1,115 +1,117
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class NewsController < ApplicationController
18 class NewsController < ApplicationController
19 default_search_scope :news
19 default_search_scope :news
20 model_object News
20 model_object News
21 before_filter :find_model_object, :except => [:new, :create, :index]
21 before_filter :find_model_object, :except => [:new, :create, :index]
22 before_filter :find_project_from_association, :except => [:new, :create, :index]
22 before_filter :find_project_from_association, :except => [:new, :create, :index]
23 before_filter :find_project, :only => [:new, :create]
23 before_filter :find_project, :only => [:new, :create]
24 before_filter :authorize, :except => [:index]
24 before_filter :authorize, :except => [:index]
25 before_filter :find_optional_project, :only => :index
25 before_filter :find_optional_project, :only => :index
26 accept_rss_auth :index
26 accept_rss_auth :index
27 accept_api_auth :index
27 accept_api_auth :index
28
28
29 helper :watchers
29 helper :watchers
30 helper :attachments
30 helper :attachments
31
31
32 def index
32 def index
33 case params[:format]
33 case params[:format]
34 when 'xml', 'json'
34 when 'xml', 'json'
35 @offset, @limit = api_offset_and_limit
35 @offset, @limit = api_offset_and_limit
36 else
36 else
37 @limit = 10
37 @limit = 10
38 end
38 end
39
39
40 scope = @project ? @project.news.visible : News.visible
40 scope = @project ? @project.news.visible : News.visible
41
41
42 @news_count = scope.count
42 @news_count = scope.count
43 @news_pages = Paginator.new self, @news_count, @limit, params['page']
43 @news_pages = Paginator.new self, @news_count, @limit, params['page']
44 @offset ||= @news_pages.current.offset
44 @offset ||= @news_pages.current.offset
45 @newss = scope.all(:include => [:author, :project],
45 @newss = scope.all(:include => [:author, :project],
46 :order => "#{News.table_name}.created_on DESC",
46 :order => "#{News.table_name}.created_on DESC",
47 :offset => @offset,
47 :offset => @offset,
48 :limit => @limit)
48 :limit => @limit)
49
49
50 respond_to do |format|
50 respond_to do |format|
51 format.html {
51 format.html {
52 @news = News.new # for adding news inline
52 @news = News.new # for adding news inline
53 render :layout => false if request.xhr?
53 render :layout => false if request.xhr?
54 }
54 }
55 format.api
55 format.api
56 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
56 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
57 end
57 end
58 end
58 end
59
59
60 def show
60 def show
61 @comments = @news.comments
61 @comments = @news.comments
62 @comments.reverse! if User.current.wants_comments_in_reverse_order?
62 @comments.reverse! if User.current.wants_comments_in_reverse_order?
63 end
63 end
64
64
65 def new
65 def new
66 @news = News.new(:project => @project, :author => User.current)
66 @news = News.new(:project => @project, :author => User.current)
67 end
67 end
68
68
69 def create
69 def create
70 @news = News.new(:project => @project, :author => User.current)
70 @news = News.new(:project => @project, :author => User.current)
71 @news.attributes = params[:news]
71 @news.attributes = params[:news]
72 @news.save_attachments(params[:attachments])
72 if @news.save
73 if @news.save
73 attachments = Attachment.attach_files(@news, params[:attachments])
74 attachments = Attachment.attach_files(@news, params[:attachments])
74 render_attachment_warning_if_needed(@news)
75 render_attachment_warning_if_needed(@news)
75 flash[:notice] = l(:notice_successful_create)
76 flash[:notice] = l(:notice_successful_create)
76 redirect_to :controller => 'news', :action => 'index', :project_id => @project
77 redirect_to :controller => 'news', :action => 'index', :project_id => @project
77 else
78 else
78 render :action => 'new'
79 render :action => 'new'
79 end
80 end
80 end
81 end
81
82
82 def edit
83 def edit
83 end
84 end
84
85
85 def update
86 def update
87 @news.save_attachments(params[:attachments])
86 if @news.update_attributes(params[:news])
88 if @news.update_attributes(params[:news])
87 attachments = Attachment.attach_files(@news, params[:attachments])
89 attachments = Attachment.attach_files(@news, params[:attachments])
88 render_attachment_warning_if_needed(@news)
90 render_attachment_warning_if_needed(@news)
89 flash[:notice] = l(:notice_successful_update)
91 flash[:notice] = l(:notice_successful_update)
90 redirect_to :action => 'show', :id => @news
92 redirect_to :action => 'show', :id => @news
91 else
93 else
92 render :action => 'edit'
94 render :action => 'edit'
93 end
95 end
94 end
96 end
95
97
96 def destroy
98 def destroy
97 @news.destroy
99 @news.destroy
98 redirect_to :action => 'index', :project_id => @project
100 redirect_to :action => 'index', :project_id => @project
99 end
101 end
100
102
101 private
103 private
102 def find_project
104 def find_project
103 @project = Project.find(params[:project_id])
105 @project = Project.find(params[:project_id])
104 rescue ActiveRecord::RecordNotFound
106 rescue ActiveRecord::RecordNotFound
105 render_404
107 render_404
106 end
108 end
107
109
108 def find_optional_project
110 def find_optional_project
109 return true unless params[:project_id]
111 return true unless params[:project_id]
110 @project = Project.find(params[:project_id])
112 @project = Project.find(params[:project_id])
111 authorize
113 authorize
112 rescue ActiveRecord::RecordNotFound
114 rescue ActiveRecord::RecordNotFound
113 render_404
115 render_404
114 end
116 end
115 end
117 end
@@ -1,9 +1,9
1 <%= f.error_messages %>
1 <%= f.error_messages %>
2 <div class="box tabular">
2 <div class="box tabular">
3 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
3 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
4 <p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p>
4 <p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p>
5 <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
5 <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
6 <p id="attachments_form"><%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %></p>
6 <p id="attachments_form"><%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form', :locals => {:container => @news} %></p>
7 </div>
7 </div>
8
8
9 <%= wikitoolbar_for 'news_description' %>
9 <%= wikitoolbar_for 'news_description' %>
General Comments 0
You need to be logged in to leave comments. Login now