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 / .svn / text-base / news_controller.rb.svn-base @ 441:cbce1fd3b1b7
History | View | Annotate | Download (3.32 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 | # |
||
| 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 | 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 | accept_key_auth :index |
||
| 27 | |||
| 28 | 441:cbce1fd3b1b7 | Chris | helper :watchers |
| 29 | |||
| 30 | 0:513646585e45 | Chris | def index |
| 31 | 119:8661b858af72 | Chris | case params[:format] |
| 32 | when 'xml', 'json' |
||
| 33 | @offset, @limit = api_offset_and_limit |
||
| 34 | else |
||
| 35 | @limit = 10 |
||
| 36 | end |
||
| 37 | |||
| 38 | scope = @project ? @project.news.visible : News.visible |
||
| 39 | |||
| 40 | @news_count = scope.count |
||
| 41 | @news_pages = Paginator.new self, @news_count, @limit, params['page'] |
||
| 42 | @offset ||= @news_pages.current.offset |
||
| 43 | @newss = scope.all(:include => [:author, :project], |
||
| 44 | :order => "#{News.table_name}.created_on DESC",
|
||
| 45 | :offset => @offset, |
||
| 46 | :limit => @limit) |
||
| 47 | |||
| 48 | 0:513646585e45 | Chris | respond_to do |format| |
| 49 | format.html { render :layout => false if request.xhr? }
|
||
| 50 | 119:8661b858af72 | Chris | format.api |
| 51 | 0:513646585e45 | Chris | format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
| 52 | end |
||
| 53 | end |
||
| 54 | |||
| 55 | def show |
||
| 56 | @comments = @news.comments |
||
| 57 | @comments.reverse! if User.current.wants_comments_in_reverse_order? |
||
| 58 | end |
||
| 59 | |||
| 60 | def new |
||
| 61 | @news = News.new(:project => @project, :author => User.current) |
||
| 62 | 22:40f7cfd4df19 | chris | end |
| 63 | |||
| 64 | def create |
||
| 65 | @news = News.new(:project => @project, :author => User.current) |
||
| 66 | 0:513646585e45 | Chris | if request.post? |
| 67 | @news.attributes = params[:news] |
||
| 68 | if @news.save |
||
| 69 | flash[:notice] = l(:notice_successful_create) |
||
| 70 | redirect_to :controller => 'news', :action => 'index', :project_id => @project |
||
| 71 | 22:40f7cfd4df19 | chris | else |
| 72 | render :action => 'new' |
||
| 73 | 0:513646585e45 | Chris | end |
| 74 | end |
||
| 75 | end |
||
| 76 | 22:40f7cfd4df19 | chris | |
| 77 | def edit |
||
| 78 | end |
||
| 79 | 0:513646585e45 | Chris | |
| 80 | 22:40f7cfd4df19 | chris | def update |
| 81 | if request.put? and @news.update_attributes(params[:news]) |
||
| 82 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_update) |
| 83 | redirect_to :action => 'show', :id => @news |
||
| 84 | 22:40f7cfd4df19 | chris | else |
| 85 | render :action => 'edit' |
||
| 86 | 0:513646585e45 | Chris | end |
| 87 | end |
||
| 88 | |||
| 89 | def destroy |
||
| 90 | @news.destroy |
||
| 91 | redirect_to :action => 'index', :project_id => @project |
||
| 92 | end |
||
| 93 | |||
| 94 | private |
||
| 95 | def find_project |
||
| 96 | @project = Project.find(params[:project_id]) |
||
| 97 | rescue ActiveRecord::RecordNotFound |
||
| 98 | render_404 |
||
| 99 | end |
||
| 100 | |||
| 101 | def find_optional_project |
||
| 102 | return true unless params[:project_id] |
||
| 103 | @project = Project.find(params[:project_id]) |
||
| 104 | authorize |
||
| 105 | rescue ActiveRecord::RecordNotFound |
||
| 106 | render_404 |
||
| 107 | end |
||
| 108 | end |