annotate .svn/pristine/ab/ab1771a93ca21896e5fcd177b31086235de0d81c.svn-base @ 929:5f33065ddc4b redmine-1.3

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