2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-11-25 16:26:55 +01:00
|
|
|
|
module Administrateurs
|
2019-03-14 14:58:01 +01:00
|
|
|
|
class MailTemplatesController < AdministrateurController
|
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2024-02-13 16:52:09 +01:00
|
|
|
|
before_action :retrieve_procedure
|
|
|
|
|
before_action :preload_revisions
|
2019-03-14 14:58:01 +01:00
|
|
|
|
|
2020-08-06 16:32:51 +02:00
|
|
|
|
def index
|
|
|
|
|
@mail_templates = mail_templates
|
2022-11-02 10:03:10 +01:00
|
|
|
|
@mail_templates.each(&:validate)
|
2020-08-06 16:32:51 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-08-25 11:40:24 +02:00
|
|
|
|
def edit
|
|
|
|
|
@mail_template = find_mail_template_by_slug(params[:id])
|
2022-11-02 10:03:10 +01:00
|
|
|
|
if !@mail_template.valid?
|
|
|
|
|
flash.now.alert = @mail_template.errors.full_messages
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
2024-02-13 16:52:09 +01:00
|
|
|
|
redirect_to edit_admin_procedure_mail_template_path(@procedure.id, params[:id])
|
2020-08-25 11:40:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
mail_template = find_mail_template_by_slug(params[:id])
|
|
|
|
|
|
|
|
|
|
if mail_template.update(update_params)
|
|
|
|
|
flash.notice = "Email mis à jour"
|
2022-11-02 10:03:10 +01:00
|
|
|
|
redirect_to edit_admin_procedure_mail_template_path(mail_template.procedure_id, params[:id])
|
2020-08-25 11:40:24 +02:00
|
|
|
|
else
|
2022-12-16 14:56:46 +01:00
|
|
|
|
flash.now.alert = "L’email contient des erreurs et n’a pas pu être enregistré. Veuiller les corriger"
|
2022-11-02 10:03:10 +01:00
|
|
|
|
mail_template.rich_body = mail_template.body
|
2020-08-25 11:40:24 +02:00
|
|
|
|
|
2022-11-02 10:03:10 +01:00
|
|
|
|
@mail_template = mail_template
|
|
|
|
|
render :edit
|
|
|
|
|
end
|
2020-08-25 11:40:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-14 14:58:01 +01:00
|
|
|
|
def preview
|
2019-07-23 15:26:55 +02:00
|
|
|
|
mail_template = find_mail_template_by_slug(params[:id])
|
2024-02-13 16:52:09 +01:00
|
|
|
|
dossier = @procedure.active_revision.dossier_for_preview(current_user)
|
2019-07-23 15:26:55 +02:00
|
|
|
|
|
|
|
|
|
@dossier = dossier
|
2024-02-13 16:52:09 +01:00
|
|
|
|
@logo_url = @procedure.logo_url
|
|
|
|
|
@service = @procedure.service
|
2023-02-06 09:41:45 +01:00
|
|
|
|
@rendered_template = sanitize(mail_template.body_for_dossier(dossier), scrubber: Sanitizers::MailScrubber.new)
|
2019-07-23 15:26:55 +02:00
|
|
|
|
@actions = mail_template.actions_for_dossier(dossier)
|
2019-03-14 14:58:01 +01:00
|
|
|
|
|
2019-07-22 15:49:11 +02:00
|
|
|
|
render(template: 'notification_mailer/send_notification', layout: 'mailers/notifications_layout')
|
2019-03-14 14:58:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def mail_templates
|
|
|
|
|
[
|
2024-02-13 16:52:09 +01:00
|
|
|
|
@procedure.passer_en_construction_email_template,
|
|
|
|
|
@procedure.passer_en_instruction_email_template,
|
|
|
|
|
@procedure.accepter_email_template,
|
|
|
|
|
@procedure.refuser_email_template,
|
|
|
|
|
@procedure.classer_sans_suite_email_template,
|
|
|
|
|
@procedure.repasser_en_instruction_email_template
|
2019-03-14 14:58:01 +01:00
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_mail_template_by_slug(slug)
|
|
|
|
|
mail_templates.find { |template| template.class.const_get(:SLUG) == slug }
|
|
|
|
|
end
|
2020-08-25 11:40:24 +02:00
|
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
|
mail_template_id = params[:id]
|
|
|
|
|
{
|
|
|
|
|
procedure_id: params[:procedure_id],
|
|
|
|
|
subject: params["mails_#{mail_template_id}"] ? params["mails_#{mail_template_id}"][:subject] : params["mails_#{mail_template_id}_mail"][:subject],
|
|
|
|
|
body: params["mails_#{mail_template_id}"] ? params["mails_#{mail_template_id}"][:rich_body] : params["mails_#{mail_template_id}_mail"][:rich_body]
|
|
|
|
|
}
|
|
|
|
|
end
|
2019-03-14 14:58:01 +01:00
|
|
|
|
end
|
|
|
|
|
end
|