##// END OF EJS Templates
Fixed: Wiki Linking Fails on News Item Preview (#1661)....
Jean-Philippe Lang -
r1660:93201e7386eb
parent child
Show More
@@ -1,109 +1,109
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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 layout 'base'
19 layout 'base'
20 before_filter :find_news, :except => [:new, :index, :preview]
20 before_filter :find_news, :except => [:new, :index, :preview]
21 before_filter :find_project, :only => :new
21 before_filter :find_project, :only => [:new, :preview]
22 before_filter :authorize, :except => [:index, :preview]
22 before_filter :authorize, :except => [:index, :preview]
23 before_filter :find_optional_project, :only => :index
23 before_filter :find_optional_project, :only => :index
24 accept_key_auth :index
24 accept_key_auth :index
25
25
26 def index
26 def index
27 @news_pages, @newss = paginate :news,
27 @news_pages, @newss = paginate :news,
28 :per_page => 10,
28 :per_page => 10,
29 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
29 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
30 :include => [:author, :project],
30 :include => [:author, :project],
31 :order => "#{News.table_name}.created_on DESC"
31 :order => "#{News.table_name}.created_on DESC"
32 respond_to do |format|
32 respond_to do |format|
33 format.html { render :layout => false if request.xhr? }
33 format.html { render :layout => false if request.xhr? }
34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
35 end
35 end
36 end
36 end
37
37
38 def show
38 def show
39 @comments = @news.comments
39 @comments = @news.comments
40 @comments.reverse! if User.current.wants_comments_in_reverse_order?
40 @comments.reverse! if User.current.wants_comments_in_reverse_order?
41 end
41 end
42
42
43 def new
43 def new
44 @news = News.new(:project => @project, :author => User.current)
44 @news = News.new(:project => @project, :author => User.current)
45 if request.post?
45 if request.post?
46 @news.attributes = params[:news]
46 @news.attributes = params[:news]
47 if @news.save
47 if @news.save
48 flash[:notice] = l(:notice_successful_create)
48 flash[:notice] = l(:notice_successful_create)
49 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
49 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
50 redirect_to :controller => 'news', :action => 'index', :project_id => @project
50 redirect_to :controller => 'news', :action => 'index', :project_id => @project
51 end
51 end
52 end
52 end
53 end
53 end
54
54
55 def edit
55 def edit
56 if request.post? and @news.update_attributes(params[:news])
56 if request.post? and @news.update_attributes(params[:news])
57 flash[:notice] = l(:notice_successful_update)
57 flash[:notice] = l(:notice_successful_update)
58 redirect_to :action => 'show', :id => @news
58 redirect_to :action => 'show', :id => @news
59 end
59 end
60 end
60 end
61
61
62 def add_comment
62 def add_comment
63 @comment = Comment.new(params[:comment])
63 @comment = Comment.new(params[:comment])
64 @comment.author = User.current
64 @comment.author = User.current
65 if @news.comments << @comment
65 if @news.comments << @comment
66 flash[:notice] = l(:label_comment_added)
66 flash[:notice] = l(:label_comment_added)
67 redirect_to :action => 'show', :id => @news
67 redirect_to :action => 'show', :id => @news
68 else
68 else
69 render :action => 'show'
69 render :action => 'show'
70 end
70 end
71 end
71 end
72
72
73 def destroy_comment
73 def destroy_comment
74 @news.comments.find(params[:comment_id]).destroy
74 @news.comments.find(params[:comment_id]).destroy
75 redirect_to :action => 'show', :id => @news
75 redirect_to :action => 'show', :id => @news
76 end
76 end
77
77
78 def destroy
78 def destroy
79 @news.destroy
79 @news.destroy
80 redirect_to :action => 'index', :project_id => @project
80 redirect_to :action => 'index', :project_id => @project
81 end
81 end
82
82
83 def preview
83 def preview
84 @text = (params[:news] ? params[:news][:description] : nil)
84 @text = (params[:news] ? params[:news][:description] : nil)
85 render :partial => 'common/preview'
85 render :partial => 'common/preview'
86 end
86 end
87
87
88 private
88 private
89 def find_news
89 def find_news
90 @news = News.find(params[:id])
90 @news = News.find(params[:id])
91 @project = @news.project
91 @project = @news.project
92 rescue ActiveRecord::RecordNotFound
92 rescue ActiveRecord::RecordNotFound
93 render_404
93 render_404
94 end
94 end
95
95
96 def find_project
96 def find_project
97 @project = Project.find(params[:project_id])
97 @project = Project.find(params[:project_id])
98 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
99 render_404
99 render_404
100 end
100 end
101
101
102 def find_optional_project
102 def find_optional_project
103 return true unless params[:project_id]
103 return true unless params[:project_id]
104 @project = Project.find(params[:project_id])
104 @project = Project.find(params[:project_id])
105 authorize
105 authorize
106 rescue ActiveRecord::RecordNotFound
106 rescue ActiveRecord::RecordNotFound
107 render_404
107 render_404
108 end
108 end
109 end
109 end
@@ -1,14 +1,14
1 <h2><%=l(:label_news)%></h2>
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 :html => { :id => 'news-form' } do |f| %>
5 <%= render :partial => 'form', :locals => { :f => f } %>
5 <%= render :partial => 'form', :locals => { :f => f } %>
6 <%= submit_tag l(:button_save) %>
6 <%= submit_tag l(:button_save) %>
7 <%= link_to_remote l(:label_preview),
7 <%= link_to_remote l(:label_preview),
8 { :url => { :controller => 'news', :action => 'preview' },
8 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
9 :method => 'post',
9 :method => 'post',
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>
@@ -1,51 +1,51
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to_if_authorized(l(:label_news_new),
2 <%= link_to_if_authorized(l(:label_news_new),
3 {:controller => 'news', :action => 'new', :project_id => @project},
3 {:controller => 'news', :action => 'new', :project_id => @project},
4 :class => 'icon icon-add',
4 :class => 'icon icon-add',
5 :onclick => 'Element.show("add-news"); return false;') if @project %>
5 :onclick => 'Element.show("add-news"); return false;') if @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 => { :controller => 'news', :action => 'new', :project_id => @project },
10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @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 => { :controller => 'news', :action => 'preview' },
15 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
16 :method => 'post',
16 :method => 'post',
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><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
31 <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
32 <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
32 <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
33 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
33 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" 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 <p class="other-formats">
42 <p class="other-formats">
43 <%= l(:label_export_to) %>
43 <%= l(:label_export_to) %>
44 <span><%= link_to 'Atom', {:format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span>
44 <span><%= link_to 'Atom', {:format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span>
45 </p>
45 </p>
46
46
47 <% content_for :header_tags do %>
47 <% content_for :header_tags do %>
48 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
48 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
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 => { :controller => 'news', :action => 'new', :project_id => @project },
3 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @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 => { :controller => 'news', :action => 'preview' },
8 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
9 :method => 'post',
9 :method => 'post',
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>
@@ -1,61 +1,61
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to_if_authorized l(:button_edit),
2 <%= link_to_if_authorized l(:button_edit),
3 {:controller => 'news', :action => 'edit', :id => @news},
3 {:controller => 'news', :action => 'edit', :id => @news},
4 :class => 'icon icon-edit',
4 :class => 'icon icon-edit',
5 :accesskey => accesskey(:edit),
5 :accesskey => accesskey(:edit),
6 :onclick => 'Element.show("edit-news"); return false;' %>
6 :onclick => 'Element.show("edit-news"); return false;' %>
7 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy', :id => @news}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
7 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy', :id => @news}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
8 </div>
8 </div>
9
9
10 <h2><%=h @news.title %></h2>
10 <h2><%=h @news.title %></h2>
11
11
12 <div id="edit-news" style="display:none;">
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 :html => { :id => 'news-form' } do |f| %>
15 <%= render :partial => 'form', :locals => { :f => f } %>
15 <%= render :partial => 'form', :locals => { :f => f } %>
16 <%= submit_tag l(:button_save) %>
16 <%= submit_tag l(:button_save) %>
17 <%= link_to_remote l(:label_preview),
17 <%= link_to_remote l(:label_preview),
18 { :url => { :controller => 'news', :action => 'preview' },
18 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
19 :method => 'post',
19 :method => 'post',
20 :update => 'preview',
20 :update => 'preview',
21 :with => "Form.serialize('news-form')"
21 :with => "Form.serialize('news-form')"
22 }, :accesskey => accesskey(:preview) %> |
22 }, :accesskey => accesskey(:preview) %> |
23 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
23 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
24 <% end %>
24 <% end %>
25 <div id="preview" class="wiki"></div>
25 <div id="preview" class="wiki"></div>
26 </div>
26 </div>
27
27
28 <p><em><% unless @news.summary.blank? %><%=h @news.summary %><br /><% end %>
28 <p><em><% unless @news.summary.blank? %><%=h @news.summary %><br /><% end %>
29 <span class="author"><%= authoring @news.created_on, @news.author %></span></em></p>
29 <span class="author"><%= authoring @news.created_on, @news.author %></span></em></p>
30 <div class="wiki">
30 <div class="wiki">
31 <%= textilizable(@news.description) %>
31 <%= textilizable(@news.description) %>
32 </div>
32 </div>
33 <br />
33 <br />
34
34
35 <div id="comments" style="margin-bottom:16px;">
35 <div id="comments" style="margin-bottom:16px;">
36 <h3 class="icon22 icon22-comment"><%= l(:label_comment_plural) %></h3>
36 <h3 class="icon22 icon22-comment"><%= l(:label_comment_plural) %></h3>
37 <% @comments.each do |comment| %>
37 <% @comments.each do |comment| %>
38 <% next if comment.new_record? %>
38 <% next if comment.new_record? %>
39 <div class="contextual">
39 <div class="contextual">
40 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment},
40 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment},
41 :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_delete) %>
41 :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_delete) %>
42 </div>
42 </div>
43 <h4><%= authoring comment.created_on, comment.author %></h4>
43 <h4><%= authoring comment.created_on, comment.author %></h4>
44 <%= textilizable(comment.comments) %>
44 <%= textilizable(comment.comments) %>
45 <% end if @comments.any? %>
45 <% end if @comments.any? %>
46 </div>
46 </div>
47
47
48 <% if authorize_for 'news', 'add_comment' %>
48 <% if authorize_for 'news', 'add_comment' %>
49 <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p>
49 <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p>
50 <% form_tag({:action => 'add_comment', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
50 <% form_tag({:action => 'add_comment', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
51 <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %>
51 <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %>
52 <%= wikitoolbar_for 'comment_comments' %>
52 <%= wikitoolbar_for 'comment_comments' %>
53 <p><%= submit_tag l(:button_add) %></p>
53 <p><%= submit_tag l(:button_add) %></p>
54 <% end %>
54 <% end %>
55 <% end %>
55 <% end %>
56
56
57 <% html_title @news.title -%>
57 <% html_title @news.title -%>
58
58
59 <% content_for :header_tags do %>
59 <% content_for :header_tags do %>
60 <%= stylesheet_link_tag 'scm' %>
60 <%= stylesheet_link_tag 'scm' %>
61 <% end %>
61 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now