@@ -0,0 +1,14 | |||
|
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> |
@@ -17,7 +17,9 | |||
|
17 | 17 | |
|
18 | 18 | class NewsController < ApplicationController |
|
19 | 19 | layout 'base' |
|
20 |
before_filter :find_ |
|
|
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,6 +38,18 class NewsController < ApplicationController | |||
|
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,14 +78,25 class NewsController < ApplicationController | |||
|
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_ |
|
|
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]) |
@@ -259,19 +259,6 class ProjectsController < ApplicationController | |||
|
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]) |
@@ -1,6 +1,14 | |||
|
1 | 1 | <h2><%=l(:label_news)%></h2> |
|
2 | 2 | |
|
3 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" } |
|
|
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 %> No newline at end of file | |
|
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> |
@@ -1,17 +1,25 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to_if_authorized(l(:label_news_new), |
|
3 |
{:controller => ' |
|
|
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 => ' |
|
|
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> |
@@ -10,11 +10,19 | |||
|
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 } |
|
|
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 %> |
@@ -51,7 +51,7 Redmine::AccessControl.map do |map| | |||
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | map.project_module :news do |map| |
|
54 |
map.permission :manage_news, { |
|
|
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 |
@@ -45,4 +45,15 class NewsControllerTest < Test::Unit::TestCase | |||
|
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 |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now