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 8.1 kB

​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. include ApplicationHelper
  12. # layout 'base_memos'
  13. def quote
  14. # @subject = @memo.subject
  15. # @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
  16. #
  17. # @content = "#{ll(Setting.default_language, :text_user_wrote, @memo.author)} <br/> &nbsp; "
  18. # @content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "</blockquote>\n\n<br/>"
  19. # @content = "<blockquote style='word-break: break-all;word-wrap: break-word;'>" << @content
  20. # #@content = "> #{ll(Setting.default_language, :text_user_wrote, @memo.author)}\n> "
  21. # #@content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  22. # #@content_html = textilizable(@content)
  23. # @temp = Memo.new
  24. # @temp.content = @content
  25. end
  26. def new
  27. @memo = Memo.new
  28. @memo.forum_id = @forum.id
  29. respond_to do |format|
  30. format.html {
  31. render action: :new ,layout: 'base'
  32. }
  33. format.json { render json: @memo }
  34. end
  35. end
  36. def create
  37. if params[:quote].nil?
  38. @quote = ""
  39. else
  40. @quote = params[:quote]
  41. end
  42. #unless params[:quote].nil?
  43. # @quote = params[:quote][:quote]
  44. #end
  45. @memo = Memo.new(params[:memo])
  46. @memo.forum_id = params[:forum_id]
  47. @memo.author_id = User.current.id
  48. if params[:memo][:parent_id]
  49. @memo.root_id = (Memo.find params[:memo][:parent_id]).root_id.nil? ? params[:memo][:parent_id].to_i : (Memo.find params[:memo][:parent_id]).root_id
  50. end
  51. @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
  52. @memo.content = @quote + @memo.content
  53. respond_to do |format|
  54. if @memo.save
  55. # Time 2015-03-24 14:47:05
  56. # Author lizanle
  57. # Description after save后需要进行资源记录的更新
  58. # owner_type = 1 对应的是 memo
  59. if !params[:asset_id].nil?
  60. ids = params[:asset_id].split(',')
  61. ids.each do |id|
  62. asset = Kindeditor::Asset.find(id.to_i)
  63. asset.owner_id = @memo.id
  64. asset.owner_type = 1
  65. asset.save
  66. end
  67. end
  68. #end
  69. format.js
  70. format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
  71. format.json { render json: @memo, status: :created, location: @memo }
  72. else
  73. flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
  74. format.js
  75. format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
  76. format.json { render json: @memo.errors, status: :unprocessable_entity }
  77. #end
  78. end
  79. end
  80. end
  81. REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
  82. def show
  83. # 更新贴吧帖子留言对应的memo_messages的viewed字段
  84. unless @memo.children.blank?
  85. @memo.children.each do |child|
  86. child.memo_messages.each do |memo_message|
  87. if User.current.id == memo_message.user_id
  88. memo_message.update_attributes(:viewed => true)
  89. end
  90. end
  91. end
  92. end
  93. query_memo_messages = @memo.memo_messages
  94. query_memo_messages.each do |query_memo_message|
  95. if User.current.id == query_memo_message.user_id
  96. query_memo_message.update_attributes(:viewed => true)
  97. end
  98. end
  99. pre_count = REPLIES_PER_PAGE
  100. @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
  101. @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
  102. # page = params[:page]
  103. # if params[:r] && page.nil?
  104. # offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
  105. # page = 1 + offset / pre_count
  106. # else
  107. # end
  108. # @reply_count = @memo.children.count
  109. # @reply_pages = Paginator.new @reply_count, pre_count, page
  110. # @replies = @memo.children.
  111. # includes(:author, :attachments).
  112. # reorder("#{Memo.table_name}.created_at DESC").
  113. # limit(@reply_pages.per_page).
  114. # offset(@reply_pages.offset).
  115. # all
  116. @replies = Memo.where("root_id = #{@memo.id}").reorder("created_at desc")
  117. @reply_count = @replies.count
  118. @replies = get_no_children_comments_all @replies
  119. @limit_count = @replies.count
  120. @page = params[:page] ? params[:page].to_i + 1 : 0
  121. @limit = 10
  122. @replies = @replies[@page * @limit..@page * @limit + 9]
  123. @memo_new = Memo.new
  124. @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
  125. @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
  126. respond_to do |format|
  127. format.js
  128. format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums',
  129. format.json { render json: @memo }
  130. format.xml { render xml: @memo }
  131. end
  132. end
  133. def edit
  134. @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
  135. @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
  136. @replying = false
  137. respond_to do |format|
  138. format.html {render :layout=>'base_forums'}
  139. end
  140. end
  141. def update
  142. @flag = false
  143. respond_to do |format|
  144. if( #@memo.update_column(:subject, params[:memo][:subject]) &&
  145. @memo.update_column(:content, params[:memo][:content]) &&
  146. @memo.update_column(:sticky, params[:memo][:sticky]) &&
  147. @memo.update_column(:lock, params[:memo][:lock]) &&
  148. @memo.update_column(:subject,params[:memo][:subject]) &&
  149. @memo.update_column(:updated_at,Time.now))
  150. @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
  151. @flag = @memo.save
  152. # @memo.root.update_attribute(:updated_at, @memo.updated_at)
  153. format.js
  154. format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"}
  155. else
  156. format.js
  157. format.html { render action: "edit" }
  158. format.json { render json: @person.errors, status: :unprocessable_entity }
  159. end
  160. end
  161. end
  162. def destroy
  163. @memo.destroy
  164. respond_to do |format|
  165. # format.html { redirect_to @back_url }
  166. format.html { redirect_to back_memo_or_forum_url }
  167. format.json { head :no_content }
  168. end
  169. end
  170. private
  171. def find_memo
  172. return unless find_forum
  173. #@memo = @forum.memos.find(params[:id])
  174. @memo = Memo.find(params[:id])
  175. rescue ActiveRecord::RecordNotFound
  176. render_404
  177. nil
  178. end
  179. def find_forum
  180. @forum = Forum.find(params[:forum_id])
  181. rescue ActiveRecord::RecordNotFound
  182. render_404
  183. nil
  184. end
  185. def authenticate_user_edit
  186. find_memo
  187. render_403 unless @memo.editable_by? User.current
  188. end
  189. def authenticate_user_destroy
  190. find_memo
  191. render_403 unless @memo.destroyable_by? User.current
  192. end
  193. def back_memo_url
  194. forum_memo_path(@forum, (@memo.root.nil? ? @memo : @memo.root))
  195. end
  196. def back_memo_or_forum_url
  197. @memo.parent_id.nil? ? forum_url(@forum) : forum_memo_url(@forum, @memo.parent_id)
  198. end
  199. end

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