55 lines
1.6 KiB
Ruby
55 lines
1.6 KiB
Ruby
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
|
|
#flash[:notice] = 'success'
|
|
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
|
|
|
|
end
|
|
|
|
def index
|
|
@documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc")
|
|
end
|
|
def update
|
|
|
|
end
|
|
|
|
def add_reply
|
|
@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_content]
|
|
@document.children << @comment
|
|
@document.save
|
|
end
|
|
|
|
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
|
|
end
|
|
end
|