@@ -1,131 +1,132 | |||||
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 | menu_item :boards |
|
19 | menu_item :boards | |
20 | default_search_scope :messages |
|
20 | default_search_scope :messages | |
21 | before_filter :find_board, :only => [:new, :preview] |
|
21 | before_filter :find_board, :only => [:new, :preview] | |
22 | before_filter :find_message, :except => [:new, :preview] |
|
22 | before_filter :find_message, :except => [:new, :preview] | |
23 | before_filter :authorize, :except => [:preview, :edit, :destroy] |
|
23 | before_filter :authorize, :except => [:preview, :edit, :destroy] | |
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 | verify :xhr => true, :only => :quote |
|
26 | verify :xhr => true, :only => :quote | |
27 |
|
27 | |||
28 | helper :watchers |
|
28 | helper :watchers | |
29 | helper :attachments |
|
29 | helper :attachments | |
30 | include AttachmentsHelper |
|
30 | include AttachmentsHelper | |
31 |
|
31 | |||
32 | # Show a topic and its replies |
|
32 | # Show a topic and its replies | |
33 | def show |
|
33 | def show | |
34 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}]) |
|
34 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}]) | |
35 | @replies.reverse! if User.current.wants_comments_in_reverse_order? |
|
35 | @replies.reverse! if User.current.wants_comments_in_reverse_order? | |
36 | @reply = Message.new(:subject => "RE: #{@message.subject}") |
|
36 | @reply = Message.new(:subject => "RE: #{@message.subject}") | |
37 | render :action => "show", :layout => false if request.xhr? |
|
37 | render :action => "show", :layout => false if request.xhr? | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | # Create a new topic |
|
40 | # Create a new topic | |
41 | def new |
|
41 | def new | |
42 | @message = Message.new(params[:message]) |
|
42 | @message = Message.new(params[:message]) | |
43 | @message.author = User.current |
|
43 | @message.author = User.current | |
44 | @message.board = @board |
|
44 | @message.board = @board | |
45 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) |
|
45 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) | |
46 | @message.locked = params[:message]['locked'] |
|
46 | @message.locked = params[:message]['locked'] | |
47 | @message.sticky = params[:message]['sticky'] |
|
47 | @message.sticky = params[:message]['sticky'] | |
48 | end |
|
48 | end | |
49 | if request.post? && @message.save |
|
49 | if request.post? && @message.save | |
50 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) |
|
50 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) | |
51 | attach_files(@message, params[:attachments]) |
|
51 | attach_files(@message, params[:attachments]) | |
52 | redirect_to :action => 'show', :id => @message |
|
52 | redirect_to :action => 'show', :id => @message | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | # Reply to a topic |
|
56 | # Reply to a topic | |
57 | def reply |
|
57 | def reply | |
58 | @reply = Message.new(params[:reply]) |
|
58 | @reply = Message.new(params[:reply]) | |
59 | @reply.author = User.current |
|
59 | @reply.author = User.current | |
60 | @reply.board = @board |
|
60 | @reply.board = @board | |
61 | @topic.children << @reply |
|
61 | @topic.children << @reply | |
62 | if !@reply.new_record? |
|
62 | if !@reply.new_record? | |
63 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
|
63 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) | |
64 | attach_files(@reply, params[:attachments]) |
|
64 | attach_files(@reply, params[:attachments]) | |
65 | end |
|
65 | end | |
66 | redirect_to :action => 'show', :id => @topic |
|
66 | redirect_to :action => 'show', :id => @topic | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | # Edit a message |
|
69 | # Edit a message | |
70 | def edit |
|
70 | def edit | |
71 | render_403 and return false unless @message.editable_by?(User.current) |
|
71 | render_403 and return false unless @message.editable_by?(User.current) | |
72 | if params[:message] |
|
72 | if params[:message] | |
73 | @message.locked = params[:message]['locked'] |
|
73 | @message.locked = params[:message]['locked'] | |
74 | @message.sticky = params[:message]['sticky'] |
|
74 | @message.sticky = params[:message]['sticky'] | |
75 | end |
|
75 | end | |
76 | if request.post? && @message.update_attributes(params[:message]) |
|
76 | if request.post? && @message.update_attributes(params[:message]) | |
77 | attach_files(@message, params[:attachments]) |
|
77 | attach_files(@message, params[:attachments]) | |
78 | flash[:notice] = l(:notice_successful_update) |
|
78 | flash[:notice] = l(:notice_successful_update) | |
79 | @message.reload |
|
79 | @message.reload | |
80 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root |
|
80 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | # Delete a messages |
|
84 | # Delete a messages | |
85 | def destroy |
|
85 | def destroy | |
86 | render_403 and return false unless @message.destroyable_by?(User.current) |
|
86 | render_403 and return false unless @message.destroyable_by?(User.current) | |
87 | @message.destroy |
|
87 | @message.destroy | |
88 | redirect_to @message.parent.nil? ? |
|
88 | redirect_to @message.parent.nil? ? | |
89 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : |
|
89 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : | |
90 | { :action => 'show', :id => @message.parent } |
|
90 | { :action => 'show', :id => @message.parent } | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def quote |
|
93 | def quote | |
94 | user = @message.author |
|
94 | user = @message.author | |
95 | text = @message.content |
|
95 | text = @message.content | |
96 | subject = @message.subject.gsub('"', '\"') |
|
96 | subject = @message.subject.gsub('"', '\"') | |
|
97 | subject = "RE: #{subject}" unless subject.starts_with?('RE:') | |||
97 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
98 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " | |
98 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" |
|
99 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" | |
99 | render(:update) { |page| |
|
100 | render(:update) { |page| | |
100 |
page << "$('reply_subject').value = \" |
|
101 | page << "$('reply_subject').value = \"#{subject}\";" | |
101 | page.<< "$('message_content').value = \"#{content}\";" |
|
102 | page.<< "$('message_content').value = \"#{content}\";" | |
102 | page.show 'reply' |
|
103 | page.show 'reply' | |
103 | page << "Form.Element.focus('message_content');" |
|
104 | page << "Form.Element.focus('message_content');" | |
104 | page << "Element.scrollTo('reply');" |
|
105 | page << "Element.scrollTo('reply');" | |
105 | page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" |
|
106 | page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" | |
106 | } |
|
107 | } | |
107 | end |
|
108 | end | |
108 |
|
109 | |||
109 | def preview |
|
110 | def preview | |
110 | message = @board.messages.find_by_id(params[:id]) |
|
111 | message = @board.messages.find_by_id(params[:id]) | |
111 | @attachements = message.attachments if message |
|
112 | @attachements = message.attachments if message | |
112 | @text = (params[:message] || params[:reply])[:content] |
|
113 | @text = (params[:message] || params[:reply])[:content] | |
113 | render :partial => 'common/preview' |
|
114 | render :partial => 'common/preview' | |
114 | end |
|
115 | end | |
115 |
|
116 | |||
116 | private |
|
117 | private | |
117 | def find_message |
|
118 | def find_message | |
118 | find_board |
|
119 | find_board | |
119 | @message = @board.messages.find(params[:id], :include => :parent) |
|
120 | @message = @board.messages.find(params[:id], :include => :parent) | |
120 | @topic = @message.root |
|
121 | @topic = @message.root | |
121 | rescue ActiveRecord::RecordNotFound |
|
122 | rescue ActiveRecord::RecordNotFound | |
122 | render_404 |
|
123 | render_404 | |
123 | end |
|
124 | end | |
124 |
|
125 | |||
125 | def find_board |
|
126 | def find_board | |
126 | @board = Board.find(params[:board_id], :include => :project) |
|
127 | @board = Board.find(params[:board_id], :include => :project) | |
127 | @project = @board.project |
|
128 | @project = @board.project | |
128 | rescue ActiveRecord::RecordNotFound |
|
129 | rescue ActiveRecord::RecordNotFound | |
129 | render_404 |
|
130 | render_404 | |
130 | end |
|
131 | end | |
131 | end |
|
132 | end |
General Comments 0
You need to be logged in to leave comments.
Login now