Revision 1111
Added by Jean-Philippe Lang over 17 years ago
trunk/app/controllers/news_controller.rb | ||
---|---|---|
17 | 17 | |
18 | 18 |
class NewsController < ApplicationController |
19 | 19 |
layout 'base' |
20 |
before_filter :find_project, :authorize, :except => :index |
|
20 |
before_filter :find_news, :except => [:new, :index, :preview] |
|
21 |
before_filter :find_project, :only => :new |
|
22 |
before_filter :authorize, :except => [:index, :preview] |
|
21 | 23 |
before_filter :find_optional_project, :only => :index |
22 | 24 |
accept_key_auth :index |
23 | 25 |
|
... | ... | |
36 | 38 |
def show |
37 | 39 |
end |
38 | 40 | |
41 |
def new |
|
42 |
@news = News.new(:project => @project, :author => User.current) |
|
43 |
if request.post? |
|
44 |
@news.attributes = params[:news] |
|
45 |
if @news.save |
|
46 |
flash[:notice] = l(:notice_successful_create) |
|
47 |
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
48 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
49 |
end |
|
50 |
end |
|
51 |
end |
|
52 |
|
|
39 | 53 |
def edit |
40 | 54 |
if request.post? and @news.update_attributes(params[:news]) |
41 | 55 |
flash[:notice] = l(:notice_successful_update) |
... | ... | |
64 | 78 |
redirect_to :action => 'index', :project_id => @project |
65 | 79 |
end |
66 | 80 |
|
81 |
def preview |
|
82 |
@text = (params[:news] ? params[:news][:description] : nil) |
|
83 |
render :partial => 'common/preview' |
|
84 |
end |
|
85 |
|
|
67 | 86 |
private |
68 |
def find_project
|
|
87 |
def find_news
|
|
69 | 88 |
@news = News.find(params[:id]) |
70 | 89 |
@project = @news.project |
71 | 90 |
rescue ActiveRecord::RecordNotFound |
72 | 91 |
render_404 |
73 | 92 |
end |
74 | 93 |
|
94 |
def find_project |
|
95 |
@project = Project.find(params[:project_id]) |
|
96 |
rescue ActiveRecord::RecordNotFound |
|
97 |
render_404 |
|
98 |
end |
|
99 |
|
|
75 | 100 |
def find_optional_project |
76 | 101 |
return true unless params[:project_id] |
77 | 102 |
@project = Project.find(params[:project_id]) |
trunk/app/controllers/projects_controller.rb | ||
---|---|---|
259 | 259 |
render :layout => false if request.xhr? |
260 | 260 |
end |
261 | 261 | |
262 |
# Add a news to @project |
|
263 |
def add_news |
|
264 |
@news = News.new(:project => @project, :author => User.current) |
|
265 |
if request.post? |
|
266 |
@news.attributes = params[:news] |
|
267 |
if @news.save |
|
268 |
flash[:notice] = l(:notice_successful_create) |
|
269 |
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
270 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
271 |
end |
|
272 |
end |
|
273 |
end |
|
274 | ||
275 | 262 |
def add_file |
276 | 263 |
if request.post? |
277 | 264 |
@version = @project.versions.find_by_id(params[:version_id]) |
trunk/app/views/news/edit.rhtml | ||
---|---|---|
1 | 1 |
<h2><%=l(:label_news)%></h2> |
2 | 2 | |
3 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" } do |f| %> |
|
3 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" }, |
|
4 |
:html => { :id => 'news-form' } do |f| %> |
|
4 | 5 |
<%= render :partial => 'form', :locals => { :f => f } %> |
5 | 6 |
<%= submit_tag l(:button_save) %> |
6 |
<% end %> |
|
7 |
<%= link_to_remote l(:label_preview), |
|
8 |
{ :url => { :controller => 'news', :action => 'preview' }, |
|
9 |
:method => 'post', |
|
10 |
:update => 'preview', |
|
11 |
:with => "Form.serialize('news-form')" |
|
12 |
}, :accesskey => accesskey(:preview) %> |
|
13 |
<% end %> |
|
14 |
<div id="preview" class="wiki"></div> |
trunk/app/views/news/index.rhtml | ||
---|---|---|
1 | 1 |
<div class="contextual"> |
2 | 2 |
<%= link_to_if_authorized(l(:label_news_new), |
3 |
{:controller => 'projects', :action => 'add_news', :id => @project},
|
|
3 |
{:controller => 'news', :action => 'new', :project_id => @project},
|
|
4 | 4 |
:class => 'icon icon-add', |
5 | 5 |
:onclick => 'Element.show("add-news"); return false;') if @project %> |
6 | 6 |
</div> |
7 | 7 | |
8 | 8 |
<div id="add-news" style="display:none;"> |
9 | 9 |
<h2><%=l(:label_news_new)%></h2> |
10 |
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %> |
|
10 |
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, |
|
11 |
:html => { :id => 'news-form' } do |f| %> |
|
11 | 12 |
<%= render :partial => 'news/form', :locals => { :f => f } %> |
12 | 13 |
<%= submit_tag l(:button_create) %> |
14 |
<%= link_to_remote l(:label_preview), |
|
15 |
{ :url => { :controller => 'news', :action => 'preview' }, |
|
16 |
:method => 'post', |
|
17 |
:update => 'preview', |
|
18 |
:with => "Form.serialize('news-form')" |
|
19 |
}, :accesskey => accesskey(:preview) %> | |
|
13 | 20 |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %> |
14 | 21 |
<% end if @project %> |
22 |
<div id="preview" class="wiki"></div> |
|
15 | 23 |
</div> |
16 | 24 | |
17 | 25 |
<h2><%=l(:label_news_plural)%></h2> |
trunk/app/views/news/new.rhtml | ||
---|---|---|
1 |
<h2><%=l(:label_news_new)%></h2> |
|
2 | ||
3 |
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, |
|
4 |
:html => { :id => 'news-form' } do |f| %> |
|
5 |
<%= render :partial => 'news/form', :locals => { :f => f } %> |
|
6 |
<%= submit_tag l(:button_create) %> |
|
7 |
<%= link_to_remote l(:label_preview), |
|
8 |
{ :url => { :controller => 'news', :action => 'preview' }, |
|
9 |
:method => 'post', |
|
10 |
:update => 'preview', |
|
11 |
:with => "Form.serialize('news-form')" |
|
12 |
}, :accesskey => accesskey(:preview) %> |
|
13 |
<% end %> |
|
14 |
<div id="preview" class="wiki"></div> |
|
0 | 15 |
trunk/app/views/news/show.rhtml | ||
---|---|---|
10 | 10 |
<h2><%=h @news.title %></h2> |
11 | 11 | |
12 | 12 |
<div id="edit-news" style="display:none;"> |
13 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news } do |f| %> |
|
13 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news }, |
|
14 |
:html => { :id => 'news-form' } do |f| %> |
|
14 | 15 |
<%= render :partial => 'form', :locals => { :f => f } %> |
15 | 16 |
<%= submit_tag l(:button_save) %> |
17 |
<%= link_to_remote l(:label_preview), |
|
18 |
{ :url => { :controller => 'news', :action => 'preview' }, |
|
19 |
:method => 'post', |
|
20 |
:update => 'preview', |
|
21 |
:with => "Form.serialize('news-form')" |
|
22 |
}, :accesskey => accesskey(:preview) %> | |
|
16 | 23 |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %> |
17 | 24 |
<% end %> |
25 |
<div id="preview" class="wiki"></div> |
|
18 | 26 |
</div> |
19 | 27 | |
20 | 28 |
<p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %> |
trunk/app/views/projects/add_news.rhtml | ||
---|---|---|
1 |
<h2><%=l(:label_news_new)%></h2> |
|
2 | ||
3 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "add_news" } do |f| %> |
|
4 |
<%= render :partial => 'news/form', :locals => { :f => f } %> |
|
5 |
<%= submit_tag l(:button_create) %> |
|
6 |
<% end %> |
|
7 | 0 |
trunk/lib/redmine.rb | ||
---|---|---|
51 | 51 |
end |
52 | 52 |
|
53 | 53 |
map.project_module :news do |map| |
54 |
map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
|
|
54 |
map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
|
|
55 | 55 |
map.permission :view_news, {:news => [:index, :show]}, :public => true |
56 | 56 |
map.permission :comment_news, {:news => :add_comment} |
57 | 57 |
end |
trunk/test/functional/news_controller_test.rb | ||
---|---|---|
45 | 45 |
assert_template 'index' |
46 | 46 |
assert_not_nil assigns(:newss) |
47 | 47 |
end |
48 |
|
|
49 |
def test_preview |
|
50 |
get :preview, :project_id => 1, |
|
51 |
:news => {:title => '', |
|
52 |
:description => 'News description', |
|
53 |
:summary => ''} |
|
54 |
assert_response :success |
|
55 |
assert_template 'common/_preview' |
|
56 |
assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, |
|
57 |
:content => /News description/ |
|
58 |
end |
|
48 | 59 |
end |
Also available in: Unified diff
ProjectsController#add_news moved to NewsController#new.
Preview added when adding/editing a news (#590).