Mercurial > hg > soundsoftware-site
comparison app/controllers/news_controller.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
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 |
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 | 30 |
31 def index | 31 def index |
32 case params[:format] | 32 case params[:format] |
33 when 'xml', 'json' | 33 when 'xml', 'json' |
34 @offset, @limit = api_offset_and_limit | 34 @offset, @limit = api_offset_and_limit |
35 else | 35 else |
36 @limit = 10 | 36 @limit = 10 |
37 end | 37 end |
38 | 38 |
39 scope = @project ? @project.news.visible : News.visible | 39 scope = @project ? @project.news.visible : News.visible |
40 | 40 |
41 @news_count = scope.count | 41 @news_count = scope.count |
42 @news_pages = Paginator.new self, @news_count, @limit, params['page'] | 42 @news_pages = Paginator.new self, @news_count, @limit, params['page'] |
43 @offset ||= @news_pages.current.offset | 43 @offset ||= @news_pages.current.offset |
44 @newss = scope.all(:include => [:author, :project], | 44 @newss = scope.all(:include => [:author, :project], |
45 :order => "#{News.table_name}.created_on DESC", | 45 :order => "#{News.table_name}.created_on DESC", |
46 :offset => @offset, | 46 :offset => @offset, |
47 :limit => @limit) | 47 :limit => @limit) |
48 | 48 |
49 respond_to do |format| | 49 respond_to do |format| |
50 format.html { render :layout => false if request.xhr? } | 50 format.html { |
51 @news = News.new # for adding news inline | |
52 render :layout => false if request.xhr? | |
53 } | |
51 format.api | 54 format.api |
52 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } | 55 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } |
53 end | 56 end |
54 end | 57 end |
55 | 58 |
56 def show | 59 def show |
57 @comments = @news.comments | 60 @comments = @news.comments |
58 @comments.reverse! if User.current.wants_comments_in_reverse_order? | 61 @comments.reverse! if User.current.wants_comments_in_reverse_order? |
59 end | 62 end |
60 | 63 |
75 end | 78 end |
76 end | 79 end |
77 | 80 |
78 def edit | 81 def edit |
79 end | 82 end |
80 | 83 |
81 def update | 84 def update |
82 if request.put? and @news.update_attributes(params[:news]) | 85 if request.put? and @news.update_attributes(params[:news]) |
83 flash[:notice] = l(:notice_successful_update) | 86 flash[:notice] = l(:notice_successful_update) |
84 redirect_to :action => 'show', :id => @news | 87 redirect_to :action => 'show', :id => @news |
85 else | 88 else |
89 | 92 |
90 def destroy | 93 def destroy |
91 @news.destroy | 94 @news.destroy |
92 redirect_to :action => 'index', :project_id => @project | 95 redirect_to :action => 'index', :project_id => @project |
93 end | 96 end |
94 | 97 |
95 private | 98 private |
96 def find_project | 99 def find_project |
97 @project = Project.find(params[:project_id]) | 100 @project = Project.find(params[:project_id]) |
98 rescue ActiveRecord::RecordNotFound | 101 rescue ActiveRecord::RecordNotFound |
99 render_404 | 102 render_404 |
100 end | 103 end |
101 | 104 |
102 def find_optional_project | 105 def find_optional_project |
103 return true unless params[:project_id] | 106 return true unless params[:project_id] |
104 @project = Project.find(params[:project_id]) | 107 @project = Project.find(params[:project_id]) |
105 authorize | 108 authorize |
106 rescue ActiveRecord::RecordNotFound | 109 rescue ActiveRecord::RecordNotFound |