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
|
|
|
|
|
|
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
|
|
|
|
|
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-15 13:08:20 +01:00
|
|
|
|
flash.now.alert = "L’email contient des erreurs et n’a pas pu être enregistré, veuillez 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])
|
2022-11-02 10:03:10 +01:00
|
|
|
|
dossier = procedure.active_revision.dossier_for_preview(current_user)
|
2019-07-23 15:26:55 +02:00
|
|
|
|
|
|
|
|
|
@dossier = dossier
|
2019-08-20 11:28:07 +02:00
|
|
|
|
@logo_url = procedure.logo_url
|
2019-03-21 15:39:37 +01:00
|
|
|
|
@service = procedure.service
|
2022-11-02 10:03:10 +01:00
|
|
|
|
@rendered_template = sanitize(mail_template.body_for_dossier(dossier))
|
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 procedure
|
2019-07-23 15:26:55 +02:00
|
|
|
|
@procedure ||= current_administrateur.procedures.find(params[:procedure_id])
|
2019-03-14 14:58:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def mail_templates
|
|
|
|
|
[
|
2019-07-23 15:26:55 +02:00
|
|
|
|
procedure.initiated_mail_template,
|
|
|
|
|
procedure.received_mail_template,
|
|
|
|
|
procedure.closed_mail_template,
|
|
|
|
|
procedure.refused_mail_template,
|
|
|
|
|
procedure.without_continuation_mail_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
|