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.

org_document_comments_controller.rb 7.3 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. class OrgDocumentCommentsController < ApplicationController
  2. before_filter :find_organization, :only => [:new, :create, :show, :index]
  3. before_filter :authorize_allowed, :only => [:create, :add_reply, :add_reply_in_doc]
  4. helper :attachments,:organizations
  5. layout 'base_org'
  6. def new
  7. @org_document_comment = OrgDocumentComment.new
  8. end
  9. def create
  10. @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
  11. @org_document_comment.title = params[:org_document_comment][:title]
  12. @org_document_comment.content = params[:org_document_comment][:content]
  13. @org_document_comment.status = params[:org_document_comment][:status] == "on" ? 1 : 0
  14. @org_document_comment.save_attachments(params[:attachments])
  15. if params[:field_id]
  16. @org_document_comment.org_subfield_id = params[:field_id].to_i
  17. end
  18. if @org_document_comment.save
  19. flash.keep[:notice] = l(:notice_successful_create)
  20. EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at)
  21. if params[:field_id]
  22. @org_subfield = OrgSubfield.find(params[:field_id])
  23. if @org_subfield.subfield_subdomain_dir.nil?
  24. redirect_to organization_path(@organization, :org_subfield_id => params[:field_id])
  25. else
  26. redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name)
  27. end
  28. else
  29. redirect_to organization_org_document_comments_path(@organization)
  30. end
  31. else
  32. redirect_to new_org_document_comment_path(:organization_id => @organization.id)
  33. end
  34. end
  35. def show
  36. @document = OrgDocumentComment.find(params[:id])
  37. @org_subfield = OrgSubfield.where(:id => @document.org_subfield_id).first
  38. @subfield_content = @organization.org_subfields.order("priority")
  39. all_comments = []
  40. @replies = OrgDocumentComment.where("root_id = #{@document.id}").reorder("created_at desc")
  41. @reply_count = @replies.count
  42. @replies = get_no_children_comments_all @replies
  43. @limit_count = @replies.count
  44. @page = params[:page] ? params[:page].to_i + 1 : 0
  45. @limit = 10
  46. @replies = @replies[@page * @limit..@page * @limit + 9]
  47. respond_to do |format|
  48. format.js
  49. format.html {render :layout => (@organization.switch_type && @document && !@document.org_subfield_id.blank?) ? 'base_org_custom' : 'base_org'}
  50. end
  51. end
  52. def index
  53. if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
  54. @documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc")
  55. else
  56. render_403
  57. end
  58. end
  59. def update
  60. @org_document = OrgDocumentComment.find(params[:id])
  61. @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
  62. Attachment.attach_files(@org_document, params[:attachments])
  63. # @org_document.save_attachments(params[:attachments])
  64. if @org_document.parent.nil?
  65. act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
  66. act.update_attributes(:updated_at => @org_document.updated_at)
  67. EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now)
  68. end
  69. respond_to do |format|
  70. format.html {
  71. if params[:flag].to_i == 0
  72. redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)
  73. else
  74. if params[:flag].to_i == 1
  75. redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id)
  76. else
  77. redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id])
  78. end
  79. end
  80. }
  81. end
  82. end
  83. def edit
  84. @org_document = OrgDocumentComment.find(params[:id])
  85. @flag = params[:flag]
  86. @organization = Organization.find(params[:organization_id])
  87. end
  88. def add_reply
  89. @document = OrgDocumentComment.find(params[:id]).root
  90. @act = OrgActivity.find(params[:act_id])
  91. @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
  92. @comment.content = params[:org_content]
  93. @comment.root_id = @document.id
  94. @document.children << @comment
  95. @document.save
  96. end
  97. def add_reply_in_doc
  98. @document = OrgDocumentComment.find(params[:id]).root
  99. @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
  100. if params[:org_comment].blank?
  101. @comment.content = params[:org_content]
  102. else
  103. @comment.content = params[:org_comment][:org_content]
  104. end
  105. @comment.root_id = @document.id
  106. @document.children << @comment
  107. @document.save
  108. respond_to do |format|
  109. format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
  110. end
  111. end
  112. def find_organization
  113. @organization = Organization.find(params[:organization_id])
  114. end
  115. def authorize_allowed
  116. unless User.current.logged?
  117. redirect_to signin_url
  118. return
  119. end
  120. end
  121. def destroy
  122. @org_document_comment = OrgDocumentComment.find(params[:id])
  123. @org_sub_id = @org_document_comment.org_subfield_id
  124. org = @org_document_comment.root.organization
  125. if @org_document_comment.id == org.home_id
  126. org.update_attributes(:home_id => nil)
  127. end
  128. if params[:user_activity_id]
  129. @act = OrgActivity.find(params[:user_activity_id])
  130. @document = @org_document_comment.root
  131. end
  132. if @org_document_comment.destroy
  133. end
  134. respond_to do |format|
  135. format.js
  136. end
  137. end
  138. def delete_reply
  139. @org_document_comment = OrgDocumentComment.find(params[:id])
  140. @document = @org_document_comment.root
  141. org = @org_document_comment.organization
  142. @org_document_comment.destroy
  143. respond_to do |format|
  144. format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
  145. end
  146. end
  147. def quote
  148. @org_comment = OrgDocumentComment.find(params[:id])
  149. @temp = OrgDocumentComment.new
  150. respond_to do | format|
  151. format.js
  152. end
  153. end
  154. def reply
  155. @document = OrgDocumentComment.find(params[:id])
  156. @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
  157. @org_document.title = params[:org_document_comment][:title]
  158. @org_document.content = params[:org_document_comment][:content]
  159. @org_document.root_id = @document.root_id.nil? ? @document.id : @document.root_id
  160. @document.children << @org_document
  161. @document = @document.root
  162. @user_activity_id = params[:user_activity_id]
  163. @act = OrgActivity.find(@user_activity_id) if @user_activity_id
  164. respond_to do |format|
  165. format.html {
  166. redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
  167. }
  168. format.js
  169. end
  170. end
  171. end

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