2023-11-14 17:46:52 +01:00
|
|
|
module Administrateurs
|
|
|
|
class AttestationTemplateV2sController < AdministrateurController
|
2023-12-22 14:13:20 +01:00
|
|
|
include UninterlacePngConcern
|
|
|
|
|
2023-11-15 10:33:48 +01:00
|
|
|
before_action :retrieve_procedure, :retrieve_attestation_template, :ensure_feature_active
|
2023-11-14 17:46:52 +01:00
|
|
|
|
|
|
|
def show
|
|
|
|
json_body = @attestation_template.json_body&.deep_symbolize_keys
|
2023-12-20 22:10:51 +01:00
|
|
|
@body = TiptapService.new.to_html(json_body, {})
|
2023-11-14 17:46:52 +01:00
|
|
|
|
2023-11-15 09:55:33 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render layout: 'attestation'
|
|
|
|
end
|
|
|
|
|
|
|
|
format.pdf do
|
|
|
|
html = render_to_string('/administrateurs/attestation_template_v2s/show', layout: 'attestation', formats: [:html])
|
|
|
|
|
|
|
|
result = Typhoeus.post(WEASYPRINT_URL,
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
body: { html: html }.to_json)
|
|
|
|
|
|
|
|
send_data(result.body, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline')
|
|
|
|
end
|
|
|
|
end
|
2023-11-14 17:46:52 +01:00
|
|
|
end
|
|
|
|
|
2023-11-15 09:53:07 +01:00
|
|
|
def edit
|
2023-11-28 11:44:32 +01:00
|
|
|
@buttons = [
|
|
|
|
[
|
|
|
|
['Gras', 'bold', 'bold'],
|
|
|
|
['Italic', 'italic', 'italic'],
|
|
|
|
['Souligner', 'underline', 'underline']
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['Titre', 'title', 'h-1'],
|
|
|
|
['Sous titre', 'heading2', 'h-2'],
|
|
|
|
['Titre de section', 'heading3', 'h-3']
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['Liste à puces', 'bulletList', 'list-unordered'],
|
|
|
|
['Liste numérotée', 'orderedList', 'list-ordered']
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['Aligner à gauche', 'left', 'align-left'],
|
|
|
|
['Aligner au centre', 'center', 'align-center'],
|
|
|
|
['Aligner à droite', 'right', 'align-right']
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['Undo', 'undo', 'arrow-go-back-line'],
|
|
|
|
['Redo', 'redo', 'arrow-go-forward-line']
|
|
|
|
]
|
|
|
|
]
|
2023-11-15 09:53:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2023-12-22 14:13:20 +01:00
|
|
|
attestation_params = editor_params
|
|
|
|
logo_file = attestation_params.delete(:logo)
|
|
|
|
signature_file = attestation_params.delete(:signature)
|
|
|
|
|
|
|
|
if logo_file
|
|
|
|
attestation_params[:logo] = uninterlace_png(logo_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
if signature_file
|
|
|
|
attestation_params[:signature] = uninterlace_png(signature_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
@attestation_template.update!(attestation_params)
|
2023-11-15 09:53:07 +01:00
|
|
|
end
|
|
|
|
|
2024-01-12 12:49:49 +01:00
|
|
|
def create
|
|
|
|
@attestation_template.update!(editor_params)
|
|
|
|
end
|
|
|
|
|
2023-11-14 17:46:52 +01:00
|
|
|
private
|
|
|
|
|
2023-11-15 10:33:48 +01:00
|
|
|
def ensure_feature_active
|
|
|
|
redirect_to root_path if !@procedure.feature_enabled?(:attestation_v2)
|
|
|
|
end
|
|
|
|
|
2023-11-14 17:46:52 +01:00
|
|
|
def retrieve_attestation_template
|
2024-01-10 13:37:55 +01:00
|
|
|
@attestation_template = @procedure.attestation_template_v2 || @procedure.build_attestation_template_v2
|
2023-11-14 17:46:52 +01:00
|
|
|
end
|
2023-11-15 09:53:07 +01:00
|
|
|
|
|
|
|
def editor_params
|
2023-12-22 14:13:20 +01:00
|
|
|
params.required(:attestation_template).permit(:official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated)
|
2023-11-15 09:53:07 +01:00
|
|
|
end
|
|
|
|
end
|
2023-11-14 17:46:52 +01:00
|
|
|
end
|