You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

messages_controller.rb 5.2 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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. default_search_scope :messages
  20. before_filter :find_board, :only => [:new, :preview]
  21. before_filter :find_attachments, :only => [:preview]
  22. before_filter :find_message, :except => [:new, :preview]
  23. before_filter :authorize, :except => [:preview, :edit, :destroy, :new]
  24. helper :boards
  25. helper :watchers
  26. helper :attachments
  27. include AttachmentsHelper
  28. REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
  29. # Show a topic and its replies
  30. def show
  31. page = params[:page]
  32. # Find the page of the requested reply
  33. if params[:r] && page.nil?
  34. offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
  35. page = 1 + offset / REPLIES_PER_PAGE
  36. end
  37. @reply_count = @topic.children.count
  38. @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
  39. @replies = @topic.children.
  40. includes(:author, :attachments, {:board => :project}).
  41. reorder("#{Message.table_name}.created_on DESC").
  42. limit(@reply_pages.per_page).
  43. offset(@reply_pages.offset).
  44. all
  45. @reply = Message.new(:subject => "RE: #{@message.subject}")
  46. if @course
  47. render :action => "show", :layout => "base_courses"#by young
  48. else
  49. render :action => "show", :layout => "base_projects"#by young
  50. end
  51. end
  52. # Create a new topic
  53. def new
  54. @message = Message.new
  55. @message.author = User.current
  56. @message.board = @board
  57. @message.safe_attributes = params[:message]
  58. if request.post?
  59. @message.save_attachments(params[:attachments])
  60. if @message.save
  61. call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
  62. render_attachment_warning_if_needed(@message)
  63. redirect_to board_message_path(@board, @message)
  64. end
  65. end
  66. end
  67. # Reply to a topic
  68. def reply
  69. @reply = Message.new
  70. @reply.author = User.current
  71. @reply.board = @board
  72. @reply.safe_attributes = params[:reply]
  73. @topic.children << @reply
  74. @topic.update_attribute(:updated_on, Time.now)
  75. if !@reply.new_record?
  76. call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
  77. attachments = Attachment.attach_files(@reply, params[:attachments])
  78. render_attachment_warning_if_needed(@reply)
  79. end
  80. redirect_to board_message_path(@board, @topic, :r => @reply)
  81. end
  82. # Edit a message
  83. def edit
  84. (render_403; return false) unless @message.editable_by?(User.current)
  85. @message.safe_attributes = params[:message]
  86. if request.post? && @message.save
  87. attachments = Attachment.attach_files(@message, params[:attachments])
  88. render_attachment_warning_if_needed(@message)
  89. flash[:notice] = l(:notice_successful_update)
  90. @message.reload
  91. redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
  92. end
  93. end
  94. # Delete a messages
  95. def destroy
  96. (render_403; return false) unless @message.destroyable_by?(User.current)
  97. r = @message.to_param
  98. @message.destroy
  99. if @message.parent
  100. redirect_to board_message_path(@board, @message.parent, :r => r)
  101. else
  102. redirect_to project_board_path(@project, @board)
  103. end
  104. end
  105. def quote
  106. @subject = @message.subject
  107. @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
  108. @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
  109. @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  110. end
  111. def preview
  112. message = @board.messages.find_by_id(params[:id])
  113. @text = (params[:message] || params[:reply])[:content]
  114. @previewed = message
  115. render :partial => 'common/preview'
  116. end
  117. private
  118. def find_message
  119. return unless find_board
  120. @message = @board.messages.find(params[:id], :include => :parent)
  121. @topic = @message.root
  122. rescue ActiveRecord::RecordNotFound
  123. render_404
  124. end
  125. def find_board
  126. #modify by nwb
  127. @board = Board.find(params[:board_id])
  128. if @board.project_id != -1 && @board.project_id != nil
  129. @project = @board.project
  130. elsif @board.course_id
  131. @course = @board.course
  132. end
  133. rescue ActiveRecord::RecordNotFound
  134. render_404
  135. nil
  136. end
  137. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...