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