##// END OF EJS Templates
Added preview for forum messages....
Jean-Philippe Lang -
r1191:a4c6c62c8b13
parent child
Show More
@@ -1,101 +1,108
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 MessagesController < ApplicationController
19 19 layout 'base'
20 20 menu_item :boards
21 before_filter :find_board, :only => :new
22 before_filter :find_message, :except => :new
23 before_filter :authorize
21 before_filter :find_board, :only => [:new, :preview]
22 before_filter :find_message, :except => [:new, :preview]
23 before_filter :authorize, :except => :preview
24 24
25 25 verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
26 26
27 27 helper :attachments
28 28 include AttachmentsHelper
29 29
30 30 # Show a topic and its replies
31 31 def show
32 32 @replies = @topic.children
33 33 @replies.reverse! if User.current.wants_comments_in_reverse_order?
34 34 @reply = Message.new(:subject => "RE: #{@message.subject}")
35 35 render :action => "show", :layout => false if request.xhr?
36 36 end
37 37
38 38 # Create a new topic
39 39 def new
40 40 @message = Message.new(params[:message])
41 41 @message.author = User.current
42 42 @message.board = @board
43 43 if params[:message] && User.current.allowed_to?(:edit_messages, @project)
44 44 @message.locked = params[:message]['locked']
45 45 @message.sticky = params[:message]['sticky']
46 46 end
47 47 if request.post? && @message.save
48 48 attach_files(@message, params[:attachments])
49 49 redirect_to :action => 'show', :id => @message
50 50 end
51 51 end
52 52
53 53 # Reply to a topic
54 54 def reply
55 55 @reply = Message.new(params[:reply])
56 56 @reply.author = User.current
57 57 @reply.board = @board
58 58 @topic.children << @reply
59 59 if !@reply.new_record?
60 60 attach_files(@reply, params[:attachments])
61 61 end
62 62 redirect_to :action => 'show', :id => @topic
63 63 end
64 64
65 65 # Edit a message
66 66 def edit
67 67 if params[:message] && User.current.allowed_to?(:edit_messages, @project)
68 68 @message.locked = params[:message]['locked']
69 69 @message.sticky = params[:message]['sticky']
70 70 end
71 71 if request.post? && @message.update_attributes(params[:message])
72 72 attach_files(@message, params[:attachments])
73 73 flash[:notice] = l(:notice_successful_update)
74 74 redirect_to :action => 'show', :id => @topic
75 75 end
76 76 end
77 77
78 78 # Delete a messages
79 79 def destroy
80 80 @message.destroy
81 81 redirect_to @message.parent.nil? ?
82 82 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
83 83 { :action => 'show', :id => @message.parent }
84 84 end
85 85
86 def preview
87 message = @board.messages.find_by_id(params[:id])
88 @attachements = message.attachments if message
89 @text = (params[:message] || params[:reply])[:content]
90 render :partial => 'common/preview'
91 end
92
86 93 private
87 94 def find_message
88 95 find_board
89 96 @message = @board.messages.find(params[:id], :include => :parent)
90 97 @topic = @message.root
91 98 rescue ActiveRecord::RecordNotFound
92 99 render_404
93 100 end
94 101
95 102 def find_board
96 103 @board = Board.find(params[:board_id], :include => :project)
97 104 @project = @board.project
98 105 rescue ActiveRecord::RecordNotFound
99 106 render_404
100 107 end
101 108 end
@@ -1,49 +1,57
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:label_message_new),
3 3 {:controller => 'messages', :action => 'new', :board_id => @board},
4 4 :class => 'icon icon-add',
5 5 :onclick => 'Element.show("add-message"); return false;' %>
6 6 <%= watcher_tag(@board, User.current) %>
7 7 </div>
8 8
9 9 <div id="add-message" style="display:none;">
10 10 <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%= l(:label_message_new) %></h2>
11 <% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true} do |f| %>
11 <% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
12 12 <%= render :partial => 'messages/form', :locals => {:f => f} %>
13 13 <p><%= submit_tag l(:button_create) %>
14 <%= link_to_remote l(:label_preview),
15 { :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
16 :method => 'post',
17 :update => 'preview',
18 :with => "Form.serialize('message-form')",
19 :complete => "Element.scrollTo('preview')"
20 }, :accesskey => accesskey(:preview) %> |
14 21 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %></p>
15 22 <% end %>
23 <div id="preview" class="wiki"></div>
16 24 </div>
17 25
18 26 <h2><%=h @board.name %></h2>
19 27
20 28 <% if @topics.any? %>
21 29 <table class="list messages">
22 30 <thead><tr>
23 31 <th><%= l(:field_subject) %></th>
24 32 <th><%= l(:field_author) %></th>
25 33 <%= sort_header_tag("#{Message.table_name}.created_on", :caption => l(:field_created_on)) %>
26 34 <th><%= l(:label_reply_plural) %></th>
27 35 <%= sort_header_tag("#{Message.table_name}.updated_on", :caption => l(:label_message_last)) %>
28 36 </tr></thead>
29 37 <tbody>
30 38 <% @topics.each do |topic| %>
31 39 <tr class="message <%= cycle 'odd', 'even' %> <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>">
32 40 <td class="subject"><%= link_to h(topic.subject), { :controller => 'messages', :action => 'show', :board_id => @board, :id => topic }, :class => 'icon' %></td>
33 41 <td class="author" align="center"><%= topic.author %></td>
34 42 <td class="created_on" align="center"><%= format_time(topic.created_on) %></td>
35 43 <td class="replies" align="center"><%= topic.replies_count %></td>
36 44 <td class="last_message">
37 45 <% if topic.last_reply %>
38 46 <%= authoring topic.last_reply.created_on, topic.last_reply.author %><br />
39 47 <%= link_to_message topic.last_reply %>
40 48 <% end %>
41 49 </td>
42 50 </tr>
43 51 <% end %>
44 52 </tbody>
45 53 </table>
46 54 <p class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></p>
47 55 <% else %>
48 56 <p class="nodata"><%= l(:label_no_data) %></p>
49 57 <% end %>
@@ -1,6 +1,14
1 1 <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%=h @message.subject %></h2>
2 2
3 <% form_for :message, @message, :url => {:action => 'edit'}, :html => {:multipart => true} do |f| %>
3 <% form_for :message, @message, :url => {:action => 'edit'}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
4 4 <%= render :partial => 'form', :locals => {:f => f, :replying => !@message.parent.nil?} %>
5 5 <%= submit_tag l(:button_save) %>
6 <%= link_to_remote l(:label_preview),
7 { :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
8 :method => 'post',
9 :update => 'preview',
10 :with => "Form.serialize('message-form')",
11 :complete => "Element.scrollTo('preview')"
12 }, :accesskey => accesskey(:preview) %>
6 13 <% end %>
14 <div id="preview" class="wiki"></div>
@@ -1,6 +1,15
1 1 <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%= l(:label_message_new) %></h2>
2 2
3 <% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true} do |f| %>
3 <% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
4 4 <%= render :partial => 'form', :locals => {:f => f} %>
5 5 <%= submit_tag l(:button_create) %>
6 <%= link_to_remote l(:label_preview),
7 { :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
8 :method => 'post',
9 :update => 'preview',
10 :with => "Form.serialize('message-form')",
11 :complete => "Element.scrollTo('preview')"
12 }, :accesskey => accesskey(:preview) %>
6 13 <% end %>
14
15 <div id="preview" class="wiki"></div>
@@ -1,39 +1,47
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit' %>
3 3 <%= link_to_if_authorized l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del' %>
4 4 </div>
5 5
6 6 <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%=h @topic.subject %></h2>
7 7
8 8 <div class="message">
9 9 <p><span class="author"><%= authoring @topic.created_on, @topic.author %></span></p>
10 10 <div class="wiki">
11 11 <%= textilizable(@topic.content, :attachments => @topic.attachments) %>
12 12 </div>
13 13 <%= link_to_attachments @topic.attachments, :no_author => true %>
14 14 </div>
15 15 <br />
16 16
17 17 <h3 class="icon22 icon22-comment"><%= l(:label_reply_plural) %></h3>
18 18 <% @replies.each do |message| %>
19 19 <a name="<%= "message-#{message.id}" %>"></a>
20 20 <div class="contextual">
21 21 <%= link_to_if_authorized image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit) %>
22 22 <%= link_to_if_authorized image_tag('delete.png'), {:action => 'destroy', :id => message}, :method => :post, :confirm => l(:text_are_you_sure), :title => l(:button_delete) %>
23 23 </div>
24 24 <div class="message reply">
25 25 <h4><%=h message.subject %> - <%= authoring message.created_on, message.author %></h4>
26 26 <div class="wiki"><%= textilizable message.content %></div>
27 27 <%= link_to_attachments message.attachments, :no_author => true %>
28 28 </div>
29 29 <% end %>
30 30
31 31 <% if !@topic.locked? && authorize_for('messages', 'reply') %>
32 32 <p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p>
33 33 <div id="reply" style="display:none;">
34 <% form_for :reply, @reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true} do |f| %>
35 <%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
36 <%= submit_tag l(:button_submit) %>
34 <% form_for :reply, @reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
35 <%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
36 <%= submit_tag l(:button_submit) %>
37 <%= link_to_remote l(:label_preview),
38 { :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
39 :method => 'post',
40 :update => 'preview',
41 :with => "Form.serialize('message-form')",
42 :complete => "Element.scrollTo('preview')"
43 }, :accesskey => accesskey(:preview) %>
37 44 <% end %>
45 <div id="preview" class="wiki"></div>
38 46 </div>
39 47 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now