comparison app/controllers/messages_controller.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents 5f33065ddc4b
children 3e4c3460b6ca
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 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.
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 helper :boards
26 verify :xhr => true, :only => :quote
27
28 helper :watchers 26 helper :watchers
29 helper :attachments 27 helper :attachments
30 include AttachmentsHelper 28 include AttachmentsHelper
31 29
32 REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) 30 REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
55 def new 53 def new
56 @message = Message.new 54 @message = Message.new
57 @message.author = User.current 55 @message.author = User.current
58 @message.board = @board 56 @message.board = @board
59 @message.safe_attributes = params[:message] 57 @message.safe_attributes = params[:message]
60 if request.post? && @message.save 58 if request.post?
61 call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) 59 @message.save_attachments(params[:attachments])
62 attachments = Attachment.attach_files(@message, params[:attachments]) 60 if @message.save
63 render_attachment_warning_if_needed(@message) 61 call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
64 redirect_to :action => 'show', :id => @message 62 render_attachment_warning_if_needed(@message)
63 redirect_to board_message_path(@board, @message)
64 end
65 end 65 end
66 end 66 end
67 67
68 # Reply to a topic 68 # Reply to a topic
69 def reply 69 def reply
75 if !@reply.new_record? 75 if !@reply.new_record?
76 call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) 76 call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
77 attachments = Attachment.attach_files(@reply, params[:attachments]) 77 attachments = Attachment.attach_files(@reply, params[:attachments])
78 render_attachment_warning_if_needed(@reply) 78 render_attachment_warning_if_needed(@reply)
79 end 79 end
80 redirect_to :action => 'show', :id => @topic, :r => @reply 80 redirect_to board_message_path(@board, @topic, :r => @reply)
81 end 81 end
82 82
83 # Edit a message 83 # Edit a message
84 def edit 84 def edit
85 (render_403; return false) unless @message.editable_by?(User.current) 85 (render_403; return false) unless @message.editable_by?(User.current)
87 if request.post? && @message.save 87 if request.post? && @message.save
88 attachments = Attachment.attach_files(@message, params[:attachments]) 88 attachments = Attachment.attach_files(@message, params[:attachments])
89 render_attachment_warning_if_needed(@message) 89 render_attachment_warning_if_needed(@message)
90 flash[:notice] = l(:notice_successful_update) 90 flash[:notice] = l(:notice_successful_update)
91 @message.reload 91 @message.reload
92 redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) 92 redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
93 end 93 end
94 end 94 end
95 95
96 # Delete a messages 96 # Delete a messages
97 def destroy 97 def destroy
98 (render_403; return false) unless @message.destroyable_by?(User.current) 98 (render_403; return false) unless @message.destroyable_by?(User.current)
99 r = @message.to_param
99 @message.destroy 100 @message.destroy
100 redirect_to @message.parent.nil? ? 101 if @message.parent
101 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : 102 redirect_to board_message_path(@board, @message.parent, :r => r)
102 { :action => 'show', :id => @message.parent, :r => @message } 103 else
104 redirect_to project_board_path(@project, @board)
105 end
103 end 106 end
104 107
105 def quote 108 def quote
106 user = @message.author 109 @subject = @message.subject
107 text = @message.content 110 @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
108 subject = @message.subject.gsub('"', '\"') 111
109 subject = "RE: #{subject}" unless subject.starts_with?('RE:') 112 @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
110 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " 113 @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
111 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
112 render(:update) { |page|
113 page << "$('message_subject').value = \"#{subject}\";"
114 page.<< "$('message_content').value = \"#{content}\";"
115 page.show 'reply'
116 page << "Form.Element.focus('message_content');"
117 page << "Element.scrollTo('reply');"
118 page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
119 }
120 end 114 end
121 115
122 def preview 116 def preview
123 message = @board.messages.find_by_id(params[:id]) 117 message = @board.messages.find_by_id(params[:id])
124 @attachements = message.attachments if message 118 @attachements = message.attachments if message
125 @text = (params[:message] || params[:reply])[:content] 119 @text = (params[:message] || params[:reply])[:content]
120 @previewed = message
126 render :partial => 'common/preview' 121 render :partial => 'common/preview'
127 end 122 end
128 123
129 private 124 private
130 def find_message 125 def find_message