##// 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 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class NewsController < ApplicationController
19 19 layout 'base'
20 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 22 before_filter :authorize, :except => [:index, :preview]
23 23 before_filter :find_optional_project, :only => :index
24 24 accept_key_auth :index
25 25
26 26 def index
27 27 @news_pages, @newss = paginate :news,
28 28 :per_page => 10,
29 29 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
30 30 :include => [:author, :project],
31 31 :order => "#{News.table_name}.created_on DESC"
32 32 respond_to do |format|
33 33 format.html { render :layout => false if request.xhr? }
34 34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
35 35 end
36 36 end
37 37
38 38 def show
39 39 @comments = @news.comments
40 40 @comments.reverse! if User.current.wants_comments_in_reverse_order?
41 41 end
42 42
43 43 def new
44 44 @news = News.new(:project => @project, :author => User.current)
45 45 if request.post?
46 46 @news.attributes = params[:news]
47 47 if @news.save
48 48 flash[:notice] = l(:notice_successful_create)
49 49 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
50 50 redirect_to :controller => 'news', :action => 'index', :project_id => @project
51 51 end
52 52 end
53 53 end
54 54
55 55 def edit
56 56 if request.post? and @news.update_attributes(params[:news])
57 57 flash[:notice] = l(:notice_successful_update)
58 58 redirect_to :action => 'show', :id => @news
59 59 end
60 60 end
61 61
62 62 def add_comment
63 63 @comment = Comment.new(params[:comment])
64 64 @comment.author = User.current
65 65 if @news.comments << @comment
66 66 flash[:notice] = l(:label_comment_added)
67 67 redirect_to :action => 'show', :id => @news
68 68 else
69 69 render :action => 'show'
70 70 end
71 71 end
72 72
73 73 def destroy_comment
74 74 @news.comments.find(params[:comment_id]).destroy
75 75 redirect_to :action => 'show', :id => @news
76 76 end
77 77
78 78 def destroy
79 79 @news.destroy
80 80 redirect_to :action => 'index', :project_id => @project
81 81 end
82 82
83 83 def preview
84 84 @text = (params[:news] ? params[:news][:description] : nil)
85 85 render :partial => 'common/preview'
86 86 end
87 87
88 88 private
89 89 def find_news
90 90 @news = News.find(params[:id])
91 91 @project = @news.project
92 92 rescue ActiveRecord::RecordNotFound
93 93 render_404
94 94 end
95 95
96 96 def find_project
97 97 @project = Project.find(params[:project_id])
98 98 rescue ActiveRecord::RecordNotFound
99 99 render_404
100 100 end
101 101
102 102 def find_optional_project
103 103 return true unless params[:project_id]
104 104 @project = Project.find(params[:project_id])
105 105 authorize
106 106 rescue ActiveRecord::RecordNotFound
107 107 render_404
108 108 end
109 109 end
@@ -1,14 +1,14
1 1 <h2><%=l(:label_news)%></h2>
2 2
3 3 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit" },
4 4 :html => { :id => 'news-form' } do |f| %>
5 5 <%= render :partial => 'form', :locals => { :f => f } %>
6 6 <%= submit_tag l(:button_save) %>
7 7 <%= link_to_remote l(:label_preview),
8 { :url => { :controller => 'news', :action => 'preview' },
8 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
9 9 :method => 'post',
10 10 :update => 'preview',
11 11 :with => "Form.serialize('news-form')"
12 12 }, :accesskey => accesskey(:preview) %>
13 13 <% end %>
14 14 <div id="preview" class="wiki"></div>
@@ -1,51 +1,51
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized(l(:label_news_new),
3 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 10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
11 11 :html => { :id => 'news-form' } do |f| %>
12 12 <%= render :partial => 'news/form', :locals => { :f => f } %>
13 13 <%= submit_tag l(:button_create) %>
14 14 <%= link_to_remote l(:label_preview),
15 { :url => { :controller => 'news', :action => 'preview' },
15 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
16 16 :method => 'post',
17 17 :update => 'preview',
18 18 :with => "Form.serialize('news-form')"
19 19 }, :accesskey => accesskey(:preview) %> |
20 20 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
21 21 <% end if @project %>
22 22 <div id="preview" class="wiki"></div>
23 23 </div>
24 24
25 25 <h2><%=l(:label_news_plural)%></h2>
26 26
27 27 <% if @newss.empty? %>
28 28 <p class="nodata"><%= l(:label_no_data) %></p>
29 29 <% else %>
30 30 <% @newss.each do |news| %>
31 31 <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
32 32 <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
33 33 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
34 34 <p class="author"><%= authoring news.created_on, news.author %></p>
35 35 <div class="wiki">
36 36 <%= textilizable(news.description) %>
37 37 </div>
38 38 <% end %>
39 39 <% end %>
40 40 <p class="pagination"><%= pagination_links_full @news_pages %></p>
41 41
42 42 <p class="other-formats">
43 43 <%= l(:label_export_to) %>
44 44 <span><%= link_to 'Atom', {:format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span>
45 45 </p>
46 46
47 47 <% content_for :header_tags do %>
48 48 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
49 49 <% end %>
50 50
51 51 <% html_title(l(:label_news_plural)) -%>
@@ -1,14 +1,14
1 1 <h2><%=l(:label_news_new)%></h2>
2 2
3 3 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
4 4 :html => { :id => 'news-form' } do |f| %>
5 5 <%= render :partial => 'news/form', :locals => { :f => f } %>
6 6 <%= submit_tag l(:button_create) %>
7 7 <%= link_to_remote l(:label_preview),
8 { :url => { :controller => 'news', :action => 'preview' },
8 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
9 9 :method => 'post',
10 10 :update => 'preview',
11 11 :with => "Form.serialize('news-form')"
12 12 }, :accesskey => accesskey(:preview) %>
13 13 <% end %>
14 14 <div id="preview" class="wiki"></div>
@@ -1,61 +1,61
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:button_edit),
3 3 {:controller => 'news', :action => 'edit', :id => @news},
4 4 :class => 'icon icon-edit',
5 5 :accesskey => accesskey(:edit),
6 6 :onclick => 'Element.show("edit-news"); return false;' %>
7 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 8 </div>
9 9
10 10 <h2><%=h @news.title %></h2>
11 11
12 12 <div id="edit-news" style="display:none;">
13 13 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news },
14 14 :html => { :id => 'news-form' } do |f| %>
15 15 <%= render :partial => 'form', :locals => { :f => f } %>
16 16 <%= submit_tag l(:button_save) %>
17 17 <%= link_to_remote l(:label_preview),
18 { :url => { :controller => 'news', :action => 'preview' },
18 { :url => { :controller => 'news', :action => 'preview', :project_id => @project },
19 19 :method => 'post',
20 20 :update => 'preview',
21 21 :with => "Form.serialize('news-form')"
22 22 }, :accesskey => accesskey(:preview) %> |
23 23 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
24 24 <% end %>
25 25 <div id="preview" class="wiki"></div>
26 26 </div>
27 27
28 28 <p><em><% unless @news.summary.blank? %><%=h @news.summary %><br /><% end %>
29 29 <span class="author"><%= authoring @news.created_on, @news.author %></span></em></p>
30 30 <div class="wiki">
31 31 <%= textilizable(@news.description) %>
32 32 </div>
33 33 <br />
34 34
35 35 <div id="comments" style="margin-bottom:16px;">
36 36 <h3 class="icon22 icon22-comment"><%= l(:label_comment_plural) %></h3>
37 37 <% @comments.each do |comment| %>
38 38 <% next if comment.new_record? %>
39 39 <div class="contextual">
40 40 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment},
41 41 :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_delete) %>
42 42 </div>
43 43 <h4><%= authoring comment.created_on, comment.author %></h4>
44 44 <%= textilizable(comment.comments) %>
45 45 <% end if @comments.any? %>
46 46 </div>
47 47
48 48 <% if authorize_for 'news', 'add_comment' %>
49 49 <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p>
50 50 <% form_tag({:action => 'add_comment', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
51 51 <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %>
52 52 <%= wikitoolbar_for 'comment_comments' %>
53 53 <p><%= submit_tag l(:button_add) %></p>
54 54 <% end %>
55 55 <% end %>
56 56
57 57 <% html_title @news.title -%>
58 58
59 59 <% content_for :header_tags do %>
60 60 <%= stylesheet_link_tag 'scm' %>
61 61 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now