##// END OF EJS Templates
Removed object name from form_for arguments....
Jean-Philippe Lang -
r7784:3e0936606ec9
parent child
Show More
@@ -1,109 +1,112
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class NewsController < ApplicationController
18 class NewsController < ApplicationController
19 default_search_scope :news
19 default_search_scope :news
20 model_object News
20 model_object News
21 before_filter :find_model_object, :except => [:new, :create, :index]
21 before_filter :find_model_object, :except => [:new, :create, :index]
22 before_filter :find_project_from_association, :except => [:new, :create, :index]
22 before_filter :find_project_from_association, :except => [:new, :create, :index]
23 before_filter :find_project, :only => [:new, :create]
23 before_filter :find_project, :only => [:new, :create]
24 before_filter :authorize, :except => [:index]
24 before_filter :authorize, :except => [:index]
25 before_filter :find_optional_project, :only => :index
25 before_filter :find_optional_project, :only => :index
26 accept_rss_auth :index
26 accept_rss_auth :index
27 accept_api_auth :index
27 accept_api_auth :index
28
28
29 helper :watchers
29 helper :watchers
30
30
31 def index
31 def index
32 case params[:format]
32 case params[:format]
33 when 'xml', 'json'
33 when 'xml', 'json'
34 @offset, @limit = api_offset_and_limit
34 @offset, @limit = api_offset_and_limit
35 else
35 else
36 @limit = 10
36 @limit = 10
37 end
37 end
38
38
39 scope = @project ? @project.news.visible : News.visible
39 scope = @project ? @project.news.visible : News.visible
40
40
41 @news_count = scope.count
41 @news_count = scope.count
42 @news_pages = Paginator.new self, @news_count, @limit, params['page']
42 @news_pages = Paginator.new self, @news_count, @limit, params['page']
43 @offset ||= @news_pages.current.offset
43 @offset ||= @news_pages.current.offset
44 @newss = scope.all(:include => [:author, :project],
44 @newss = scope.all(:include => [:author, :project],
45 :order => "#{News.table_name}.created_on DESC",
45 :order => "#{News.table_name}.created_on DESC",
46 :offset => @offset,
46 :offset => @offset,
47 :limit => @limit)
47 :limit => @limit)
48
48
49 respond_to do |format|
49 respond_to do |format|
50 format.html { render :layout => false if request.xhr? }
50 format.html {
51 @news = News.new # for adding news inline
52 render :layout => false if request.xhr?
53 }
51 format.api
54 format.api
52 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
55 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
53 end
56 end
54 end
57 end
55
58
56 def show
59 def show
57 @comments = @news.comments
60 @comments = @news.comments
58 @comments.reverse! if User.current.wants_comments_in_reverse_order?
61 @comments.reverse! if User.current.wants_comments_in_reverse_order?
59 end
62 end
60
63
61 def new
64 def new
62 @news = News.new(:project => @project, :author => User.current)
65 @news = News.new(:project => @project, :author => User.current)
63 end
66 end
64
67
65 def create
68 def create
66 @news = News.new(:project => @project, :author => User.current)
69 @news = News.new(:project => @project, :author => User.current)
67 if request.post?
70 if request.post?
68 @news.attributes = params[:news]
71 @news.attributes = params[:news]
69 if @news.save
72 if @news.save
70 flash[:notice] = l(:notice_successful_create)
73 flash[:notice] = l(:notice_successful_create)
71 redirect_to :controller => 'news', :action => 'index', :project_id => @project
74 redirect_to :controller => 'news', :action => 'index', :project_id => @project
72 else
75 else
73 render :action => 'new'
76 render :action => 'new'
74 end
77 end
75 end
78 end
76 end
79 end
77
80
78 def edit
81 def edit
79 end
82 end
80
83
81 def update
84 def update
82 if request.put? and @news.update_attributes(params[:news])
85 if request.put? and @news.update_attributes(params[:news])
83 flash[:notice] = l(:notice_successful_update)
86 flash[:notice] = l(:notice_successful_update)
84 redirect_to :action => 'show', :id => @news
87 redirect_to :action => 'show', :id => @news
85 else
88 else
86 render :action => 'edit'
89 render :action => 'edit'
87 end
90 end
88 end
91 end
89
92
90 def destroy
93 def destroy
91 @news.destroy
94 @news.destroy
92 redirect_to :action => 'index', :project_id => @project
95 redirect_to :action => 'index', :project_id => @project
93 end
96 end
94
97
95 private
98 private
96 def find_project
99 def find_project
97 @project = Project.find(params[:project_id])
100 @project = Project.find(params[:project_id])
98 rescue ActiveRecord::RecordNotFound
101 rescue ActiveRecord::RecordNotFound
99 render_404
102 render_404
100 end
103 end
101
104
102 def find_optional_project
105 def find_optional_project
103 return true unless params[:project_id]
106 return true unless params[:project_id]
104 @project = Project.find(params[:project_id])
107 @project = Project.find(params[:project_id])
105 authorize
108 authorize
106 rescue ActiveRecord::RecordNotFound
109 rescue ActiveRecord::RecordNotFound
107 render_404
110 render_404
108 end
111 end
109 end
112 end
@@ -1,18 +1,17
1 <h2><%=l(:label_news)%></h2>
1 <h2><%=l(:label_news)%></h2>
2
2
3 <% labelled_tabular_form_for :news, @news, :url => news_path(@news),
3 <% labelled_tabular_form_for @news, :html => { :id => 'news-form', :method => :put } do |f| %>
4 :html => { :id => 'news-form', :method => :put } do |f| %>
5 <%= render :partial => 'form', :locals => { :f => f } %>
4 <%= render :partial => 'form', :locals => { :f => f } %>
6 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
7 <%= link_to_remote l(:label_preview),
6 <%= link_to_remote l(:label_preview),
8 { :url => preview_news_path(:project_id => @project),
7 { :url => preview_news_path(:project_id => @project),
9 :method => 'get',
8 :method => 'get',
10 :update => 'preview',
9 :update => 'preview',
11 :with => "Form.serialize('news-form')"
10 :with => "Form.serialize('news-form')"
12 }, :accesskey => accesskey(:preview) %>
11 }, :accesskey => accesskey(:preview) %>
13 <% end %>
12 <% end %>
14 <div id="preview" class="wiki"></div>
13 <div id="preview" class="wiki"></div>
15
14
16 <% content_for :header_tags do %>
15 <% content_for :header_tags do %>
17 <%= stylesheet_link_tag 'scm' %>
16 <%= stylesheet_link_tag 'scm' %>
18 <% end %>
17 <% end %>
@@ -1,51 +1,51
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to(l(:label_news_new),
2 <%= link_to(l(:label_news_new),
3 new_project_news_path(@project),
3 new_project_news_path(@project),
4 :class => 'icon icon-add',
4 :class => 'icon icon-add',
5 :onclick => 'Element.show("add-news"); Form.Element.focus("news_title"); return false;') if @project && User.current.allowed_to?(:manage_news, @project) %>
5 :onclick => 'Element.show("add-news"); Form.Element.focus("news_title"); return false;') if @project && User.current.allowed_to?(:manage_news, @project) %>
6 </div>
6 </div>
7
7
8 <div id="add-news" style="display:none;">
8 <div id="add-news" style="display:none;">
9 <h2><%=l(:label_news_new)%></h2>
9 <h2><%=l(:label_news_new)%></h2>
10 <% labelled_tabular_form_for :news, @news, :url => project_news_index_path(@project),
10 <% labelled_tabular_form_for @news, :url => project_news_index_path(@project),
11 :html => { :id => 'news-form' } do |f| %>
11 :html => { :id => 'news-form' } do |f| %>
12 <%= render :partial => 'news/form', :locals => { :f => f } %>
12 <%= render :partial => 'news/form', :locals => { :f => f } %>
13 <%= submit_tag l(:button_create) %>
13 <%= submit_tag l(:button_create) %>
14 <%= link_to_remote l(:label_preview),
14 <%= link_to_remote l(:label_preview),
15 { :url => preview_news_path(:project_id => @project),
15 { :url => preview_news_path(:project_id => @project),
16 :method => 'get',
16 :method => 'get',
17 :update => 'preview',
17 :update => 'preview',
18 :with => "Form.serialize('news-form')"
18 :with => "Form.serialize('news-form')"
19 }, :accesskey => accesskey(:preview) %> |
19 }, :accesskey => accesskey(:preview) %> |
20 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
20 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
21 <% end if @project %>
21 <% end if @project %>
22 <div id="preview" class="wiki"></div>
22 <div id="preview" class="wiki"></div>
23 </div>
23 </div>
24
24
25 <h2><%=l(:label_news_plural)%></h2>
25 <h2><%=l(:label_news_plural)%></h2>
26
26
27 <% if @newss.empty? %>
27 <% if @newss.empty? %>
28 <p class="nodata"><%= l(:label_no_data) %></p>
28 <p class="nodata"><%= l(:label_no_data) %></p>
29 <% else %>
29 <% else %>
30 <% @newss.each do |news| %>
30 <% @newss.each do |news| %>
31 <h3><%= avatar(news.author, :size => "24") %><%= link_to_project(news.project) + ': ' unless news.project == @project %>
31 <h3><%= avatar(news.author, :size => "24") %><%= link_to_project(news.project) + ': ' unless news.project == @project %>
32 <%= link_to h(news.title), news_path(news) %>
32 <%= link_to h(news.title), news_path(news) %>
33 <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3>
33 <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3>
34 <p class="author"><%= authoring news.created_on, news.author %></p>
34 <p class="author"><%= authoring news.created_on, news.author %></p>
35 <div class="wiki">
35 <div class="wiki">
36 <%= textilizable(news.description) %>
36 <%= textilizable(news.description) %>
37 </div>
37 </div>
38 <% end %>
38 <% end %>
39 <% end %>
39 <% end %>
40 <p class="pagination"><%= pagination_links_full @news_pages %></p>
40 <p class="pagination"><%= pagination_links_full @news_pages %></p>
41
41
42 <% other_formats_links do |f| %>
42 <% other_formats_links do |f| %>
43 <%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.rss_key} %>
43 <%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.rss_key} %>
44 <% end %>
44 <% end %>
45
45
46 <% content_for :header_tags do %>
46 <% content_for :header_tags do %>
47 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
47 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
48 <%= stylesheet_link_tag 'scm' %>
48 <%= stylesheet_link_tag 'scm' %>
49 <% end %>
49 <% end %>
50
50
51 <% html_title(l(:label_news_plural)) -%>
51 <% html_title(l(:label_news_plural)) -%>
@@ -1,14 +1,14
1 <h2><%=l(:label_news_new)%></h2>
1 <h2><%=l(:label_news_new)%></h2>
2
2
3 <% labelled_tabular_form_for :news, @news, :url => project_news_index_path(@project),
3 <% labelled_tabular_form_for @news, :url => project_news_index_path(@project),
4 :html => { :id => 'news-form' } do |f| %>
4 :html => { :id => 'news-form' } do |f| %>
5 <%= render :partial => 'news/form', :locals => { :f => f } %>
5 <%= render :partial => 'news/form', :locals => { :f => f } %>
6 <%= submit_tag l(:button_create) %>
6 <%= submit_tag l(:button_create) %>
7 <%= link_to_remote l(:label_preview),
7 <%= link_to_remote l(:label_preview),
8 { :url => preview_news_path(:project_id => @project),
8 { :url => preview_news_path(:project_id => @project),
9 :method => 'get',
9 :method => 'get',
10 :update => 'preview',
10 :update => 'preview',
11 :with => "Form.serialize('news-form')"
11 :with => "Form.serialize('news-form')"
12 }, :accesskey => accesskey(:preview) %>
12 }, :accesskey => accesskey(:preview) %>
13 <% end %>
13 <% end %>
14 <div id="preview" class="wiki"></div>
14 <div id="preview" class="wiki"></div>
General Comments 0
You need to be logged in to leave comments. Login now