2015-11-12 09:32:00 +08:00
|
|
|
class OrgDocumentCommentsController < ApplicationController
|
|
|
|
before_filter :find_organization, :only => [:new, :create, :show, :index]
|
2016-05-27 14:44:28 +08:00
|
|
|
before_filter :authorize_allowed, :only => [:create, :add_reply]
|
2016-03-10 12:47:10 +08:00
|
|
|
helper :attachments,:organizations
|
2015-11-12 09:32:00 +08:00
|
|
|
layout 'base_org'
|
|
|
|
|
|
|
|
def new
|
|
|
|
@org_document_comment = OrgDocumentComment.new
|
|
|
|
end
|
|
|
|
|
2015-12-23 10:40:50 +08:00
|
|
|
|
2015-11-12 09:32:00 +08:00
|
|
|
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]
|
2016-05-24 09:40:16 +08:00
|
|
|
@org_document_comment.status = params[:org_document_comment][:status] == "on" ? 1 : 0
|
2015-12-23 10:40:50 +08:00
|
|
|
@org_document_comment.save_attachments(params[:attachments])
|
2015-12-09 09:23:22 +08:00
|
|
|
if params[:field_id]
|
|
|
|
@org_document_comment.org_subfield_id = params[:field_id].to_i
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
if @org_document_comment.save
|
2015-11-19 10:08:11 +08:00
|
|
|
flash.keep[:notice] = l(:notice_successful_create)
|
2015-11-30 16:04:43 +08:00
|
|
|
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at)
|
2015-12-09 09:23:22 +08:00
|
|
|
if params[:field_id]
|
2016-01-14 10:33:15 +08:00
|
|
|
@org_subfield = OrgSubfield.find(params[:field_id])
|
|
|
|
if @org_subfield.subfield_subdomain_dir.nil?
|
|
|
|
redirect_to organization_path(@organization, :org_subfield_id => params[:field_id])
|
|
|
|
else
|
|
|
|
redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name)
|
|
|
|
end
|
2015-12-09 09:23:22 +08:00
|
|
|
else
|
|
|
|
redirect_to organization_org_document_comments_path(@organization)
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
else
|
|
|
|
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
|
|
|
|
end
|
|
|
|
end
|
2015-12-24 11:09:57 +08:00
|
|
|
|
2015-11-12 09:32:00 +08:00
|
|
|
def show
|
2015-11-20 10:52:26 +08:00
|
|
|
@document = OrgDocumentComment.find(params[:id])
|
2016-06-07 15:40:28 +08:00
|
|
|
@org_subfield = OrgSubfield.where(:id => @document.org_subfield_id).first
|
|
|
|
@subfield_content = @organization.org_subfields.order("priority")
|
|
|
|
respond_to do |format|
|
2016-06-08 11:23:16 +08:00
|
|
|
format.html {render :layout => (@organization.switch_type && @document && !@document.org_subfield_id.blank?) ? 'base_org_custom' : 'base_org'}
|
2016-06-07 15:40:28 +08:00
|
|
|
end
|
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
|
2015-12-24 11:09:57 +08:00
|
|
|
|
2015-11-12 09:32:00 +08:00
|
|
|
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-12-24 11:09:57 +08:00
|
|
|
Attachment.attach_files(@org_document, params[:attachments])
|
|
|
|
# @org_document.save_attachments(params[:attachments])
|
2015-11-20 16:16:46 +08:00
|
|
|
if @org_document.parent.nil?
|
|
|
|
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
|
|
|
|
act.update_attributes(:updated_at => @org_document.updated_at)
|
2015-11-30 16:04:43 +08:00
|
|
|
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now)
|
2015-11-20 16:16:46 +08:00
|
|
|
end
|
2015-11-12 14:55:31 +08:00
|
|
|
respond_to do |format|
|
2015-11-27 10:43:21 +08:00
|
|
|
format.html {
|
2015-11-27 15:25:49 +08:00
|
|
|
if params[:flag].to_i == 0
|
2015-11-27 10:43:21 +08:00
|
|
|
redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)
|
|
|
|
else
|
2015-11-30 16:04:43 +08:00
|
|
|
if params[:flag].to_i == 1
|
|
|
|
redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id)
|
|
|
|
else
|
2015-12-09 10:48:15 +08:00
|
|
|
redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id])
|
2015-11-30 16:04:43 +08:00
|
|
|
end
|
2015-11-27 10:43:21 +08:00
|
|
|
end
|
|
|
|
}
|
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])
|
2015-11-27 10:43:21 +08:00
|
|
|
@flag = params[:flag]
|
2015-11-12 17:52:47 +08:00
|
|
|
@organization = Organization.find(params[:organization_id])
|
2015-11-12 09:32:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_reply
|
|
|
|
@document = OrgDocumentComment.find(params[:id]).root
|
2016-05-13 20:01:45 +08:00
|
|
|
@act = OrgActivity.find(params[:act_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])
|
2016-06-08 10:02:10 +08:00
|
|
|
if params[:org_comment].blank?
|
|
|
|
@comment.content = params[:org_content]
|
|
|
|
else
|
|
|
|
@comment.content = params[:org_comment][:org_content]
|
|
|
|
end
|
|
|
|
|
2015-11-20 10:52:26 +08:00
|
|
|
@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
|
|
|
|
|
2016-05-27 14:44:28 +08:00
|
|
|
def authorize_allowed
|
|
|
|
unless User.current.logged?
|
|
|
|
redirect_to signin_url
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-12 09:32:00 +08:00
|
|
|
def destroy
|
2016-05-20 22:07:33 +08:00
|
|
|
@org_document_comment = OrgDocumentComment.find(params[:id])
|
|
|
|
@org_sub_id = @org_document_comment.org_subfield_id
|
2016-07-14 17:23:48 +08:00
|
|
|
org = @org_document_comment.root.organization
|
2016-05-20 22:07:33 +08:00
|
|
|
if @org_document_comment.id == org.home_id
|
|
|
|
org.update_attributes(:home_id => nil)
|
|
|
|
end
|
2016-07-14 17:23:48 +08:00
|
|
|
if params[:user_activity_id]
|
|
|
|
@act = OrgActivity.find(params[:user_activity_id])
|
|
|
|
@document = @org_document_comment.root
|
|
|
|
end
|
2016-05-20 22:07:33 +08:00
|
|
|
if @org_document_comment.destroy
|
|
|
|
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])
|
|
|
|
@temp = OrgDocumentComment.new
|
|
|
|
respond_to do | format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply
|
2016-07-14 17:23:48 +08:00
|
|
|
@document = OrgDocumentComment.find(params[:id])
|
2015-11-20 10:52:26 +08:00
|
|
|
@org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
|
|
|
|
|
|
|
|
@org_document.title = params[:org_document_comment][:title]
|
|
|
|
@org_document.content = params[:org_document_comment][:content]
|
2016-07-14 17:23:48 +08:00
|
|
|
|
2015-11-20 10:52:26 +08:00
|
|
|
@document.children << @org_document
|
2016-07-14 17:23:48 +08:00
|
|
|
@document = @document.root
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
|
|
|
@act = OrgActivity.find(@user_activity_id) if @user_activity_id
|
2015-11-20 10:52:26 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
|
|
|
|
}
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
2015-11-12 09:32:00 +08:00
|
|
|
end
|