To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / news_controller.rb @ 1035:4ac34b54f946
History | View | Annotate | Download (3.39 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 |
#
|
| 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 |
#
|
| 9 |
# 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 |
#
|
| 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
|
| 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 |
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 |
before_filter :find_optional_project, :only => :index |
| 26 |
accept_rss_auth :index
|
| 27 |
accept_api_auth :index
|
| 28 |
|
| 29 |
helper :watchers
|
| 30 |
|
| 31 |
def index |
| 32 |
case params[:format] |
| 33 |
when 'xml', 'json' |
| 34 |
@offset, @limit = api_offset_and_limit |
| 35 |
else
|
| 36 |
@limit = 10 |
| 37 |
end
|
| 38 |
|
| 39 |
scope = @project ? @project.news.visible : News.visible |
| 40 |
|
| 41 |
@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 |
|
| 49 |
respond_to do |format|
|
| 50 |
format.html {
|
| 51 |
@news = News.new # for adding news inline |
| 52 |
render :layout => false if request.xhr? |
| 53 |
} |
| 54 |
format.api |
| 55 |
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
| 56 |
end
|
| 57 |
end
|
| 58 |
|
| 59 |
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 |
end
|
| 67 |
|
| 68 |
def create |
| 69 |
@news = News.new(:project => @project, :author => User.current) |
| 70 |
@news.safe_attributes = params[:news] |
| 71 |
if request.post?
|
| 72 |
if @news.save |
| 73 |
flash[:notice] = l(:notice_successful_create) |
| 74 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
| 75 |
else
|
| 76 |
render :action => 'new' |
| 77 |
end
|
| 78 |
end
|
| 79 |
end
|
| 80 |
|
| 81 |
def edit |
| 82 |
end
|
| 83 |
|
| 84 |
def update |
| 85 |
@news.safe_attributes = params[:news] |
| 86 |
if request.put? and @news.save |
| 87 |
flash[:notice] = l(:notice_successful_update) |
| 88 |
redirect_to :action => 'show', :id => @news |
| 89 |
else
|
| 90 |
render :action => 'edit' |
| 91 |
end
|
| 92 |
end
|
| 93 |
|
| 94 |
def destroy |
| 95 |
@news.destroy
|
| 96 |
redirect_to :action => 'index', :project_id => @project |
| 97 |
end
|
| 98 |
|
| 99 |
private |
| 100 |
def find_project |
| 101 |
@project = Project.find(params[:project_id]) |
| 102 |
rescue ActiveRecord::RecordNotFound |
| 103 |
render_404 |
| 104 |
end
|
| 105 |
|
| 106 |
def find_optional_project |
| 107 |
return true unless params[:project_id] |
| 108 |
@project = Project.find(params[:project_id]) |
| 109 |
authorize |
| 110 |
rescue ActiveRecord::RecordNotFound |
| 111 |
render_404 |
| 112 |
end
|
| 113 |
end
|