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 @ 762:7dc4d205233e
History | View | Annotate | Download (3.34 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 { render :layout => false if request.xhr? }
|
| 51 |
format.api |
| 52 |
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
| 53 |
end
|
| 54 |
end
|
| 55 |
|
| 56 |
def show |
| 57 |
@comments = @news.comments |
| 58 |
@comments.reverse! if User.current.wants_comments_in_reverse_order? |
| 59 |
end
|
| 60 |
|
| 61 |
def new |
| 62 |
@news = News.new(:project => @project, :author => User.current) |
| 63 |
end
|
| 64 |
|
| 65 |
def create |
| 66 |
@news = News.new(:project => @project, :author => User.current) |
| 67 |
if request.post?
|
| 68 |
@news.attributes = params[:news] |
| 69 |
if @news.save |
| 70 |
flash[:notice] = l(:notice_successful_create) |
| 71 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
| 72 |
else
|
| 73 |
render :action => 'new' |
| 74 |
end
|
| 75 |
end
|
| 76 |
end
|
| 77 |
|
| 78 |
def edit |
| 79 |
end
|
| 80 |
|
| 81 |
def update |
| 82 |
if request.put? and @news.update_attributes(params[:news]) |
| 83 |
flash[:notice] = l(:notice_successful_update) |
| 84 |
redirect_to :action => 'show', :id => @news |
| 85 |
else
|
| 86 |
render :action => 'edit' |
| 87 |
end
|
| 88 |
end
|
| 89 |
|
| 90 |
def destroy |
| 91 |
@news.destroy
|
| 92 |
redirect_to :action => 'index', :project_id => @project |
| 93 |
end
|
| 94 |
|
| 95 |
private |
| 96 |
def find_project |
| 97 |
@project = Project.find(params[:project_id]) |
| 98 |
rescue ActiveRecord::RecordNotFound |
| 99 |
render_404 |
| 100 |
end
|
| 101 |
|
| 102 |
def find_optional_project |
| 103 |
return true unless params[:project_id] |
| 104 |
@project = Project.find(params[:project_id]) |
| 105 |
authorize |
| 106 |
rescue ActiveRecord::RecordNotFound |
| 107 |
render_404 |
| 108 |
end
|
| 109 |
end
|