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.

memos_controller.rb 5.9 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
​
​
​
​
​
13 years ago
​
​
13 years ago
​
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
13 years ago
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. class MemosController < ApplicationController
  2. default_search_scope :memos
  3. before_filter :find_forum, :only => [:new, :create, :preview]
  4. before_filter :find_attachments, :only => [:preview]
  5. before_filter :find_memo, :except => [:new, :create, :preview]
  6. before_filter :authenticate_user_edit, :only => [:edit, :update]
  7. before_filter :authenticate_user_destroy, :only => [:destroy]
  8. before_filter :require_login, :only => [:new, :create]
  9. helper :attachments
  10. include AttachmentsHelper
  11. layout 'base_memos'
  12. def quote
  13. @subject = @memo.subject
  14. @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
  15. @content = "#{ll(Setting.default_language, :text_user_wrote, @memo.author)} <br/> &nbsp; "
  16. @content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "</blockquote>\n\n<br/>"
  17. @content = "<blockquote>" << @content
  18. end
  19. def new
  20. @memo = Memo.new
  21. @memo.forum_id = @forum.id
  22. respond_to do |format|
  23. format.html {
  24. render action: :new ,layout: 'base'
  25. }
  26. format.json { render json: @memo }
  27. end
  28. end
  29. def create
  30. @memo = Memo.new(params[:memo])
  31. @memo.forum_id = params[:forum_id]
  32. @memo.author_id = User.current.id
  33. @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
  34. respond_to do |format|
  35. if @memo.save
  36. format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
  37. format.json { render json: @memo, status: :created, location: @memo }
  38. else
  39. flash[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
  40. # back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
  41. pre_count = REPLIES_PER_PAGE
  42. @memo_new = @memo.dup
  43. @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
  44. @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
  45. page = params[:page]
  46. if params[:r] && page.nil?
  47. offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
  48. page = 1 + offset / pre_count
  49. else
  50. end
  51. @reply_count = @memo.children.count
  52. @reply_pages = Paginator.new @reply_count, pre_count, page
  53. @replies = @memo.children.
  54. includes(:author, :attachments).
  55. reorder("#{Memo.table_name}.created_at ASC").
  56. limit(@reply_pages.per_page).
  57. offset(@reply_pages.offset).
  58. all
  59. format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
  60. # format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
  61. format.json { render json: @memo.errors, status: :unprocessable_entity }
  62. end
  63. end
  64. end
  65. REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
  66. def show
  67. pre_count = REPLIES_PER_PAGE
  68. @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
  69. @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
  70. page = params[:page]
  71. if params[:r] && page.nil?
  72. offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
  73. page = 1 + offset / pre_count
  74. else
  75. end
  76. @reply_count = @memo.children.count
  77. @reply_pages = Paginator.new @reply_count, pre_count, page
  78. @replies = @memo.children.
  79. includes(:author, :attachments).
  80. reorder("#{Memo.table_name}.created_at DESC").
  81. limit(@reply_pages.per_page).
  82. offset(@reply_pages.offset).
  83. all
  84. @memo_new = Memo.new
  85. # @memo = Memo.find_by_id(params[:id])
  86. # @forum = Forum.find(params[:forum_id])
  87. # @replies = @memo.replies
  88. # @mome_new = Memo.new
  89. respond_to do |format|
  90. format.html # show.html.erb
  91. format.json { render json: @memo }
  92. format.xml { render xml: @memo }
  93. end
  94. end
  95. def edit
  96. @replying = false
  97. end
  98. def update
  99. respond_to do |format|
  100. if( @memo.update_column(:subject, params[:memo][:subject]) &&
  101. @memo.update_column(:content, params[:memo][:content]) &&
  102. @memo.update_column(:sticky, params[:memo][:sticky]) &&
  103. @memo.update_column(:lock, params[:memo][:lock]))
  104. @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
  105. # @memo.root.update_attribute(:updated_at, @memo.updated_at)
  106. format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"}
  107. else
  108. format.html { render action: "edit" }
  109. format.json { render json: @person.errors, status: :unprocessable_entity }
  110. end
  111. end
  112. end
  113. def destroy
  114. @memo.destroy
  115. respond_to do |format|
  116. # format.html { redirect_to @back_url }
  117. format.html { redirect_to back_memo_or_forum_url }
  118. format.json { head :no_content }
  119. end
  120. end
  121. private
  122. def find_memo
  123. return unless find_forum
  124. #@memo = @forum.memos.find(params[:id])
  125. @memo = Memo.find(params[:id])
  126. rescue ActiveRecord::RecordNotFound
  127. render_404
  128. nil
  129. end
  130. def find_forum
  131. @forum = Forum.find(params[:forum_id])
  132. rescue ActiveRecord::RecordNotFound
  133. render_404
  134. nil
  135. end
  136. def authenticate_user_edit
  137. find_memo
  138. render_403 unless @memo.editable_by? User.current
  139. end
  140. def authenticate_user_destroy
  141. find_memo
  142. render_403 unless @memo.destroyable_by? User.current
  143. end
  144. def back_memo_url
  145. forum_memo_path(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))
  146. end
  147. def back_memo_or_forum_url
  148. @memo.parent_id.nil? ? forum_url(@forum) : forum_memo_url(@forum, @memo.parent_id)
  149. end
  150. end

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