2015-11-12 09:32:00 +08:00
|
|
|
|
class OrgDocumentCommentsController < ApplicationController
|
|
|
|
|
before_filter :find_organization, :only => [:new, :create, :show, :index]
|
|
|
|
|
|
|
|
|
|
layout 'base_org'
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@org_document_comment = OrgDocumentComment.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
|
|
|
|
|
@org_document_comment.title = params[:org_document_comment][:title]
|
|
|
|
|
@org_document_comment.content = params[:org_document_comment][:content]
|
|
|
|
|
if @org_document_comment.save
|
2015-11-19 10:08:11 +08:00
|
|
|
|
flash.keep[:notice] = l(:notice_successful_create)
|
2015-11-12 09:32:00 +08:00
|
|
|
|
OrgActivity
|
|
|
|
|
redirect_to organization_org_document_comments_path(@organization)
|
|
|
|
|
else
|
|
|
|
|
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def show
|
2015-11-20 10:52:26 +08:00
|
|
|
|
@document = OrgDocumentComment.find(params[:id])
|
2015-11-12 09:32:00 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def index
|
2015-11-20 11:12:45 +08:00
|
|
|
|
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
|
|
|
|
@documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc")
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
|
end
|
|
|
|
|
def update
|
2015-11-12 14:55:31 +08:00
|
|
|
|
@org_document = OrgDocumentComment.find(params[:id])
|
2015-11-12 17:52:47 +08:00
|
|
|
|
@org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
|
2015-11-12 14:55:31 +08:00
|
|
|
|
respond_to do |format|
|
2015-11-12 17:52:47 +08:00
|
|
|
|
format.html {redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)}
|
2015-11-12 14:55:31 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
2015-11-12 17:52:47 +08:00
|
|
|
|
@org_document = OrgDocumentComment.find(params[:id])
|
|
|
|
|
@organization = Organization.find(params[:organization_id])
|
2015-11-12 09:32:00 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def add_reply
|
|
|
|
|
@document = OrgDocumentComment.find(params[:id]).root
|
2015-11-16 17:21:26 +08:00
|
|
|
|
@act = OrgActivity.find(params[:id])
|
2015-11-12 09:32:00 +08:00
|
|
|
|
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
|
|
|
|
@comment.content = params[:org_content]
|
|
|
|
|
@document.children << @comment
|
|
|
|
|
@document.save
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-20 10:52:26 +08:00
|
|
|
|
def add_reply_in_doc
|
|
|
|
|
@document = OrgDocumentComment.find(params[:id]).root
|
|
|
|
|
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
|
|
|
|
@comment.content = params[:org_comment][:org_content]
|
|
|
|
|
@document.children << @comment
|
|
|
|
|
@document.save
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-12 09:32:00 +08:00
|
|
|
|
def find_organization
|
|
|
|
|
@organization = Organization.find(params[:organization_id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
@org_document_comment = OrgDocumentComment.find(params[:id])
|
|
|
|
|
org = @org_document_comment.organization
|
|
|
|
|
if @org_document_comment.destroy
|
|
|
|
|
if @org_document_comment.id == org.id
|
|
|
|
|
org.home_id == nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-11-20 14:50:48 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
|
end
|
2015-11-20 10:52:26 +08:00
|
|
|
|
|
|
|
|
|
def delete_reply
|
|
|
|
|
@org_document_comment = OrgDocumentComment.find(params[:id])
|
|
|
|
|
@document = @org_document_comment.root
|
|
|
|
|
org = @org_document_comment.organization
|
|
|
|
|
@org_document_comment.destroy
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def quote
|
|
|
|
|
@org_comment = OrgDocumentComment.find(params[:id])
|
|
|
|
|
@subject = @org_comment.content
|
|
|
|
|
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
|
|
|
|
|
|
|
|
|
@content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> "
|
|
|
|
|
@temp = OrgDocumentComment.new
|
|
|
|
|
#@course_id = params[:course_id]
|
|
|
|
|
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)} <br/>#{@org_comment.content.html_safe}</blockquote>".html_safe
|
|
|
|
|
respond_to do | format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def reply
|
|
|
|
|
@document = OrgDocumentComment.find(params[:id]).root
|
|
|
|
|
@quote = params[:quote][:quote]
|
|
|
|
|
@org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
|
|
|
|
|
|
|
|
|
|
# params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
|
|
|
|
# params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
|
|
|
|
@org_document.title = params[:org_document_comment][:title]
|
|
|
|
|
@org_document.content = params[:org_document_comment][:content]
|
|
|
|
|
@org_document.content = @quote + @org_document.content
|
|
|
|
|
#@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
|
|
|
|
@document.children << @org_document
|
|
|
|
|
# @user_activity_id = params[:user_activity_id]
|
|
|
|
|
# user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
|
|
|
|
# if user_activity
|
|
|
|
|
# user_activity.updated_at = Time.now
|
|
|
|
|
# user_activity.save
|
|
|
|
|
# end
|
|
|
|
|
# attachments = Attachment.attach_files(@org_document, params[:attachments])
|
|
|
|
|
# render_attachment_warning_if_needed(@org_document)
|
|
|
|
|
#@article.save
|
|
|
|
|
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
# if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
|
|
|
|
# redirect_to syllabus_course_path(:id=>params[:course_id])
|
|
|
|
|
# else
|
|
|
|
|
redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
|
end
|