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