You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
2.6 KiB

class Doctrine::AnnotationsController < ApplicationController
load_and_authorize_resource :doctrine, class: "Doctrine"
load_and_authorize_resource :annotation, class: "Annotation", through: :doctrine
def create
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
document_id = attrs.delete(:document_id)
document_ids = params[:document_ids].split(",")
@annotation = @doctrine.annotations.new(attrs)
if document_id.present?
@annotation.document = Cdao::Jurisprudence.find(document_id)
end
if document_ids.present?
@documents = Cdao::Jurisprudence.where(id: document_ids)
end
respond_to do |format|
if @annotation.save
@documents.each { |document| @annotation.add_document(document) } if @documents.present?
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine),
notice: "Doctrine Annotation was successfully created." }
else
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine) }
end
end
end
def update
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
document_id = attrs.delete(:document_id)
document_ids = params[:document_ids].split(",")
if document_ids.present?
@documents = Cdao::Jurisprudence.where(id: document_ids)
end
attrs[:document] = Cdao::Jurisprudence.find(document_id) if document_id.present?
respond_to do |format|
if @annotation.update(attrs)
@annotation.annotation_documents.each do |annotation_document|
@annotation.remove_document(annotation_document.document)
end
@documents.each { |document| @annotation.add_document(document) } if @documents.present?
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine),
notice: "Doctrine Annotation was successfully updated." }
else
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine) }
end
end
end
def destroy
document_id = @doctrine.document_id
respond_to do |format|
if @annotation.destroy
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine),
notice: "Doctrine Annotation was successfully destroyed." }
else
format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine),
alert: @annotation.errors.full_messages }
end
end
end
private
def resource_params
params.permit(:document_id, :phil_rep, :editor_notes, :rank, annomark_ids: [])
end
end