To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / news_controller.rb @ 912:5e80956cc792

History | View | Annotate | Download (3.38 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
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.
17
18
class NewsController < ApplicationController
19
  default_search_scope :news
20
  model_object News
21 37:94944d00e43c chris
  before_filter :find_model_object, :except => [:new, :create, :index]
22
  before_filter :find_project_from_association, :except => [:new, :create, :index]
23
  before_filter :find_project, :only => [:new, :create]
24
  before_filter :authorize, :except => [:index]
25 0:513646585e45 Chris
  before_filter :find_optional_project, :only => :index
26 507:0c939c159af4 Chris
  accept_rss_auth :index
27
  accept_api_auth :index
28 909:cbb26bc654de Chris
29 441:cbce1fd3b1b7 Chris
  helper :watchers
30 909:cbb26bc654de Chris
31 0:513646585e45 Chris
  def index
32 119:8661b858af72 Chris
    case params[:format]
33
    when 'xml', 'json'
34
      @offset, @limit = api_offset_and_limit
35
    else
36
      @limit =  10
37
    end
38 909:cbb26bc654de Chris
39 119:8661b858af72 Chris
    scope = @project ? @project.news.visible : News.visible
40 909:cbb26bc654de Chris
41 119:8661b858af72 Chris
    @news_count = scope.count
42
    @news_pages = Paginator.new self, @news_count, @limit, params['page']
43
    @offset ||= @news_pages.current.offset
44
    @newss = scope.all(:include => [:author, :project],
45
                                       :order => "#{News.table_name}.created_on DESC",
46
                                       :offset => @offset,
47
                                       :limit => @limit)
48 909:cbb26bc654de Chris
49 0:513646585e45 Chris
    respond_to do |format|
50 909:cbb26bc654de Chris
      format.html {
51
        @news = News.new # for adding news inline
52
        render :layout => false if request.xhr?
53
      }
54 119:8661b858af72 Chris
      format.api
55 0:513646585e45 Chris
      format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
56
    end
57
  end
58 909:cbb26bc654de Chris
59 0:513646585e45 Chris
  def show
60
    @comments = @news.comments
61
    @comments.reverse! if User.current.wants_comments_in_reverse_order?
62
  end
63
64
  def new
65
    @news = News.new(:project => @project, :author => User.current)
66 22:40f7cfd4df19 chris
  end
67
68
  def create
69
    @news = News.new(:project => @project, :author => User.current)
70 0:513646585e45 Chris
    if request.post?
71
      @news.attributes = params[:news]
72
      if @news.save
73
        flash[:notice] = l(:notice_successful_create)
74
        redirect_to :controller => 'news', :action => 'index', :project_id => @project
75 22:40f7cfd4df19 chris
      else
76
        render :action => 'new'
77 0:513646585e45 Chris
      end
78
    end
79
  end
80 22:40f7cfd4df19 chris
81
  def edit
82
  end
83 909:cbb26bc654de Chris
84 22:40f7cfd4df19 chris
  def update
85
    if request.put? and @news.update_attributes(params[:news])
86 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_update)
87
      redirect_to :action => 'show', :id => @news
88 22:40f7cfd4df19 chris
    else
89
      render :action => 'edit'
90 0:513646585e45 Chris
    end
91
  end
92
93
  def destroy
94
    @news.destroy
95
    redirect_to :action => 'index', :project_id => @project
96
  end
97 909:cbb26bc654de Chris
98 0:513646585e45 Chris
private
99
  def find_project
100
    @project = Project.find(params[:project_id])
101
  rescue ActiveRecord::RecordNotFound
102
    render_404
103
  end
104 909:cbb26bc654de Chris
105 0:513646585e45 Chris
  def find_optional_project
106
    return true unless params[:project_id]
107
    @project = Project.find(params[:project_id])
108
    authorize
109
  rescue ActiveRecord::RecordNotFound
110
    render_404
111
  end
112
end