@@ -1,117 +1,115 | |||
|
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 NewsController < ApplicationController |
|
19 | 19 | default_search_scope :news |
|
20 | 20 | model_object News |
|
21 | 21 | before_filter :find_model_object, :except => [:new, :create, :index] |
|
22 | 22 | before_filter :find_project_from_association, :except => [:new, :create, :index] |
|
23 | 23 | before_filter :find_project, :only => [:new, :create] |
|
24 | 24 | before_filter :authorize, :except => [:index] |
|
25 | 25 | before_filter :find_optional_project, :only => :index |
|
26 | 26 | accept_rss_auth :index |
|
27 | 27 | accept_api_auth :index |
|
28 | 28 | |
|
29 | 29 | helper :watchers |
|
30 | 30 | helper :attachments |
|
31 | 31 | |
|
32 | 32 | def index |
|
33 | 33 | case params[:format] |
|
34 | 34 | when 'xml', 'json' |
|
35 | 35 | @offset, @limit = api_offset_and_limit |
|
36 | 36 | else |
|
37 | 37 | @limit = 10 |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | scope = @project ? @project.news.visible : News.visible |
|
41 | 41 | |
|
42 | 42 | @news_count = scope.count |
|
43 | 43 | @news_pages = Paginator.new self, @news_count, @limit, params['page'] |
|
44 | 44 | @offset ||= @news_pages.current.offset |
|
45 | 45 | @newss = scope.all(:include => [:author, :project], |
|
46 | 46 | :order => "#{News.table_name}.created_on DESC", |
|
47 | 47 | :offset => @offset, |
|
48 | 48 | :limit => @limit) |
|
49 | 49 | |
|
50 | 50 | respond_to do |format| |
|
51 | 51 | format.html { |
|
52 | 52 | @news = News.new # for adding news inline |
|
53 | 53 | render :layout => false if request.xhr? |
|
54 | 54 | } |
|
55 | 55 | format.api |
|
56 | 56 | format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def show |
|
61 | 61 | @comments = @news.comments |
|
62 | 62 | @comments.reverse! if User.current.wants_comments_in_reverse_order? |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def new |
|
66 | 66 | @news = News.new(:project => @project, :author => User.current) |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def create |
|
70 | 70 | @news = News.new(:project => @project, :author => User.current) |
|
71 | if request.post? | |
|
72 | @news.attributes = params[:news] | |
|
73 | if @news.save | |
|
74 | attachments = Attachment.attach_files(@news, params[:attachments]) | |
|
75 | render_attachment_warning_if_needed(@news) | |
|
76 | flash[:notice] = l(:notice_successful_create) | |
|
77 | redirect_to :controller => 'news', :action => 'index', :project_id => @project | |
|
78 | else | |
|
79 | render :action => 'new' | |
|
80 | end | |
|
71 | @news.attributes = params[:news] | |
|
72 | if @news.save | |
|
73 | attachments = Attachment.attach_files(@news, params[:attachments]) | |
|
74 | render_attachment_warning_if_needed(@news) | |
|
75 | flash[:notice] = l(:notice_successful_create) | |
|
76 | redirect_to :controller => 'news', :action => 'index', :project_id => @project | |
|
77 | else | |
|
78 | render :action => 'new' | |
|
81 | 79 | end |
|
82 | 80 | end |
|
83 | 81 | |
|
84 | 82 | def edit |
|
85 | 83 | end |
|
86 | 84 | |
|
87 | 85 | def update |
|
88 |
if |
|
|
86 | if @news.update_attributes(params[:news]) | |
|
89 | 87 | attachments = Attachment.attach_files(@news, params[:attachments]) |
|
90 | 88 | render_attachment_warning_if_needed(@news) |
|
91 | 89 | flash[:notice] = l(:notice_successful_update) |
|
92 | 90 | redirect_to :action => 'show', :id => @news |
|
93 | 91 | else |
|
94 | 92 | render :action => 'edit' |
|
95 | 93 | end |
|
96 | 94 | end |
|
97 | 95 | |
|
98 | 96 | def destroy |
|
99 | 97 | @news.destroy |
|
100 | 98 | redirect_to :action => 'index', :project_id => @project |
|
101 | 99 | end |
|
102 | 100 | |
|
103 | 101 | private |
|
104 | 102 | def find_project |
|
105 | 103 | @project = Project.find(params[:project_id]) |
|
106 | 104 | rescue ActiveRecord::RecordNotFound |
|
107 | 105 | render_404 |
|
108 | 106 | end |
|
109 | 107 | |
|
110 | 108 | def find_optional_project |
|
111 | 109 | return true unless params[:project_id] |
|
112 | 110 | @project = Project.find(params[:project_id]) |
|
113 | 111 | authorize |
|
114 | 112 | rescue ActiveRecord::RecordNotFound |
|
115 | 113 | render_404 |
|
116 | 114 | end |
|
117 | 115 | end |
General Comments 0
You need to be logged in to leave comments.
Login now