comparison app/controllers/messages_controller.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 513646585e45
children 5f33065ddc4b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 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
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 REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) 32 REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
33 33
34 # Show a topic and its replies 34 # Show a topic and its replies
35 def show 35 def show
36 page = params[:page] 36 page = params[:page]
37 # Find the page of the requested reply 37 # Find the page of the requested reply
38 if params[:r] && page.nil? 38 if params[:r] && page.nil?
39 offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) 39 offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
40 page = 1 + offset / REPLIES_PER_PAGE 40 page = 1 + offset / REPLIES_PER_PAGE
41 end 41 end
42 42
43 @reply_count = @topic.children.count 43 @reply_count = @topic.children.count
44 @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page 44 @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page
45 @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}], 45 @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}],
46 :order => "#{Message.table_name}.created_on ASC", 46 :order => "#{Message.table_name}.created_on ASC",
47 :limit => @reply_pages.items_per_page, 47 :limit => @reply_pages.items_per_page,
48 :offset => @reply_pages.current.offset) 48 :offset => @reply_pages.current.offset)
49 49
50 @reply = Message.new(:subject => "RE: #{@message.subject}") 50 @reply = Message.new(:subject => "RE: #{@message.subject}")
51 render :action => "show", :layout => false if request.xhr? 51 render :action => "show", :layout => false if request.xhr?
52 end 52 end
53 53
54 # Create a new topic 54 # Create a new topic
55 def new 55 def new
56 @message = Message.new(params[:message]) 56 @message = Message.new(params[:message])
57 @message.author = User.current 57 @message.author = User.current
58 @message.board = @board 58 @message.board = @board
95 flash[:notice] = l(:notice_successful_update) 95 flash[:notice] = l(:notice_successful_update)
96 @message.reload 96 @message.reload
97 redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) 97 redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id)
98 end 98 end
99 end 99 end
100 100
101 # Delete a messages 101 # Delete a messages
102 def destroy 102 def destroy
103 (render_403; return false) unless @message.destroyable_by?(User.current) 103 (render_403; return false) unless @message.destroyable_by?(User.current)
104 @message.destroy 104 @message.destroy
105 redirect_to @message.parent.nil? ? 105 redirect_to @message.parent.nil? ?
106 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : 106 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
107 { :action => 'show', :id => @message.parent, :r => @message } 107 { :action => 'show', :id => @message.parent, :r => @message }
108 end 108 end
109 109
110 def quote 110 def quote
111 user = @message.author 111 user = @message.author
112 text = @message.content 112 text = @message.content
113 subject = @message.subject.gsub('"', '\"') 113 subject = @message.subject.gsub('"', '\"')
114 subject = "RE: #{subject}" unless subject.starts_with?('RE:') 114 subject = "RE: #{subject}" unless subject.starts_with?('RE:')
115 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " 115 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
116 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" 116 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
117 render(:update) { |page| 117 render(:update) { |page|
118 page << "$('reply_subject').value = \"#{subject}\";" 118 page << "$('message_subject').value = \"#{subject}\";"
119 page.<< "$('message_content').value = \"#{content}\";" 119 page.<< "$('message_content').value = \"#{content}\";"
120 page.show 'reply' 120 page.show 'reply'
121 page << "Form.Element.focus('message_content');" 121 page << "Form.Element.focus('message_content');"
122 page << "Element.scrollTo('reply');" 122 page << "Element.scrollTo('reply');"
123 page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" 123 page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
124 } 124 }
125 end 125 end
126 126
127 def preview 127 def preview
128 message = @board.messages.find_by_id(params[:id]) 128 message = @board.messages.find_by_id(params[:id])
129 @attachements = message.attachments if message 129 @attachements = message.attachments if message
130 @text = (params[:message] || params[:reply])[:content] 130 @text = (params[:message] || params[:reply])[:content]
131 render :partial => 'common/preview' 131 render :partial => 'common/preview'
132 end 132 end
133 133
134 private 134 private
135 def find_message 135 def find_message
136 find_board 136 find_board
137 @message = @board.messages.find(params[:id], :include => :parent) 137 @message = @board.messages.find(params[:id], :include => :parent)
138 @topic = @message.root 138 @topic = @message.root
139 rescue ActiveRecord::RecordNotFound 139 rescue ActiveRecord::RecordNotFound
140 render_404 140 render_404
141 end 141 end
142 142
143 def find_board 143 def find_board
144 @board = Board.find(params[:board_id], :include => :project) 144 @board = Board.find(params[:board_id], :include => :project)
145 @project = @board.project 145 @project = @board.project
146 rescue ActiveRecord::RecordNotFound 146 rescue ActiveRecord::RecordNotFound
147 render_404 147 render_404