Mercurial > hg > soundsoftware-site
comparison app/controllers/.svn/text-base/news_controller.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 40f7cfd4df19 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006 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, :index, :preview] | |
22 before_filter :find_project_from_association, :except => [:new, :index, :preview] | |
23 before_filter :find_project, :only => [:new, :preview] | |
24 before_filter :authorize, :except => [:index, :preview] | |
25 before_filter :find_optional_project, :only => :index | |
26 accept_key_auth :index | |
27 | |
28 def index | |
29 @news_pages, @newss = paginate :news, | |
30 :per_page => 10, | |
31 :conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project), | |
32 :include => [:author, :project], | |
33 :order => "#{News.table_name}.created_on DESC" | |
34 respond_to do |format| | |
35 format.html { render :layout => false if request.xhr? } | |
36 format.xml { render :xml => @newss.to_xml } | |
37 format.json { render :json => @newss.to_json } | |
38 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } | |
39 end | |
40 end | |
41 | |
42 def show | |
43 @comments = @news.comments | |
44 @comments.reverse! if User.current.wants_comments_in_reverse_order? | |
45 end | |
46 | |
47 def new | |
48 @news = News.new(:project => @project, :author => User.current) | |
49 if request.post? | |
50 @news.attributes = params[:news] | |
51 if @news.save | |
52 flash[:notice] = l(:notice_successful_create) | |
53 redirect_to :controller => 'news', :action => 'index', :project_id => @project | |
54 end | |
55 end | |
56 end | |
57 | |
58 def edit | |
59 if request.post? and @news.update_attributes(params[:news]) | |
60 flash[:notice] = l(:notice_successful_update) | |
61 redirect_to :action => 'show', :id => @news | |
62 end | |
63 end | |
64 | |
65 def add_comment | |
66 @comment = Comment.new(params[:comment]) | |
67 @comment.author = User.current | |
68 if @news.comments << @comment | |
69 flash[:notice] = l(:label_comment_added) | |
70 redirect_to :action => 'show', :id => @news | |
71 else | |
72 show | |
73 render :action => 'show' | |
74 end | |
75 end | |
76 | |
77 def destroy_comment | |
78 @news.comments.find(params[:comment_id]).destroy | |
79 redirect_to :action => 'show', :id => @news | |
80 end | |
81 | |
82 def destroy | |
83 @news.destroy | |
84 redirect_to :action => 'index', :project_id => @project | |
85 end | |
86 | |
87 def preview | |
88 @text = (params[:news] ? params[:news][:description] : nil) | |
89 render :partial => 'common/preview' | |
90 end | |
91 | |
92 private | |
93 def find_project | |
94 @project = Project.find(params[:project_id]) | |
95 rescue ActiveRecord::RecordNotFound | |
96 render_404 | |
97 end | |
98 | |
99 def find_optional_project | |
100 return true unless params[:project_id] | |
101 @project = Project.find(params[:project_id]) | |
102 authorize | |
103 rescue ActiveRecord::RecordNotFound | |
104 render_404 | |
105 end | |
106 end |