Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

messages_controller.rb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class MessagesController < ApplicationController
  18. menu_item :boards
  19. before_filter :find_board, :only => [:new, :preview]
  20. before_filter :find_message, :except => [:new, :preview]
  21. before_filter :authorize, :except => [:preview, :edit, :destroy]
  22. verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
  23. verify :xhr => true, :only => :quote
  24. helper :watchers
  25. helper :attachments
  26. include AttachmentsHelper
  27. # Show a topic and its replies
  28. def show
  29. @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}])
  30. @replies.reverse! if User.current.wants_comments_in_reverse_order?
  31. @reply = Message.new(:subject => "RE: #{@message.subject}")
  32. render :action => "show", :layout => false if request.xhr?
  33. end
  34. # Create a new topic
  35. def new
  36. @message = Message.new(params[:message])
  37. @message.author = User.current
  38. @message.board = @board
  39. if params[:message] && User.current.allowed_to?(:edit_messages, @project)
  40. @message.locked = params[:message]['locked']
  41. @message.sticky = params[:message]['sticky']
  42. end
  43. if request.post? && @message.save
  44. attach_files(@message, params[:attachments])
  45. redirect_to :action => 'show', :id => @message
  46. end
  47. end
  48. # Reply to a topic
  49. def reply
  50. @reply = Message.new(params[:reply])
  51. @reply.author = User.current
  52. @reply.board = @board
  53. @topic.children << @reply
  54. if !@reply.new_record?
  55. attach_files(@reply, params[:attachments])
  56. end
  57. redirect_to :action => 'show', :id => @topic
  58. end
  59. # Edit a message
  60. def edit
  61. render_403 and return false unless @message.editable_by?(User.current)
  62. if params[:message]
  63. @message.locked = params[:message]['locked']
  64. @message.sticky = params[:message]['sticky']
  65. end
  66. if request.post? && @message.update_attributes(params[:message])
  67. attach_files(@message, params[:attachments])
  68. flash[:notice] = l(:notice_successful_update)
  69. @message.reload
  70. redirect_to :action => 'show', :board_id => @message.board, :id => @message.root
  71. end
  72. end
  73. # Delete a messages
  74. def destroy
  75. render_403 and return false unless @message.destroyable_by?(User.current)
  76. @message.destroy
  77. redirect_to @message.parent.nil? ?
  78. { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
  79. { :action => 'show', :id => @message.parent }
  80. end
  81. def quote
  82. user = @message.author
  83. text = @message.content
  84. content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
  85. content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
  86. render(:update) { |page|
  87. page.<< "$('message_content').value = \"#{content}\";"
  88. page.show 'reply'
  89. page << "Form.Element.focus('message_content');"
  90. page << "Element.scrollTo('reply');"
  91. page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
  92. }
  93. end
  94. def preview
  95. message = @board.messages.find_by_id(params[:id])
  96. @attachements = message.attachments if message
  97. @text = (params[:message] || params[:reply])[:content]
  98. render :partial => 'common/preview'
  99. end
  100. private
  101. def find_message
  102. find_board
  103. @message = @board.messages.find(params[:id], :include => :parent)
  104. @topic = @message.root
  105. rescue ActiveRecord::RecordNotFound
  106. render_404
  107. end
  108. def find_board
  109. @board = Board.find(params[:board_id], :include => :project)
  110. @project = @board.project
  111. rescue ActiveRecord::RecordNotFound
  112. render_404
  113. end
  114. end