Mercurial > hg > soundsoftware-site
diff app/controllers/messages_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 3e4c3460b6ca |
children | 622f24f53b42 261b3d9a4903 |
line wrap: on
line diff
--- a/app/controllers/messages_controller.rb Wed Jan 23 13:11:25 2013 +0000 +++ b/app/controllers/messages_controller.rb Thu Jun 20 13:14:14 2013 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -22,9 +22,7 @@ before_filter :find_message, :except => [:new, :preview] before_filter :authorize, :except => [:preview, :edit, :destroy] - verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } - verify :xhr => true, :only => :quote - + helper :boards helper :watchers helper :attachments include AttachmentsHelper @@ -57,11 +55,13 @@ @message.author = User.current @message.board = @board @message.safe_attributes = params[:message] - if request.post? && @message.save - call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) - attachments = Attachment.attach_files(@message, params[:attachments]) - render_attachment_warning_if_needed(@message) - redirect_to :action => 'show', :id => @message + if request.post? + @message.save_attachments(params[:attachments]) + if @message.save + call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) + render_attachment_warning_if_needed(@message) + redirect_to board_message_path(@board, @message) + end end end @@ -77,7 +77,7 @@ attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) end - redirect_to :action => 'show', :id => @topic, :r => @reply + redirect_to board_message_path(@board, @topic, :r => @reply) end # Edit a message @@ -89,46 +89,41 @@ render_attachment_warning_if_needed(@message) flash[:notice] = l(:notice_successful_update) @message.reload - redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) + redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id)) end end # Delete a messages def destroy (render_403; return false) unless @message.destroyable_by?(User.current) + r = @message.to_param @message.destroy - redirect_to @message.parent.nil? ? - { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : - { :action => 'show', :id => @message.parent, :r => @message } + if @message.parent + redirect_to board_message_path(@board, @message.parent, :r => r) + else + redirect_to project_board_path(@project, @board) + end end def quote - user = @message.author - text = @message.content - subject = @message.subject.gsub('"', '\"') - subject = "RE: #{subject}" unless subject.starts_with?('RE:') - content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " - content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" - render(:update) { |page| - page << "$('message_subject').value = \"#{subject}\";" - page.<< "$('message_content').value = \"#{content}\";" - page.show 'reply' - page << "Form.Element.focus('message_content');" - page << "Element.scrollTo('reply');" - page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" - } + @subject = @message.subject + @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') + + @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " + @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" end def preview message = @board.messages.find_by_id(params[:id]) @attachements = message.attachments if message @text = (params[:message] || params[:reply])[:content] + @previewed = message render :partial => 'common/preview' end private def find_message - find_board + return unless find_board @message = @board.messages.find(params[:id], :include => :parent) @topic = @message.root rescue ActiveRecord::RecordNotFound @@ -140,5 +135,6 @@ @project = @board.project rescue ActiveRecord::RecordNotFound render_404 + nil end end