2017-03-06 11:51:34 +01:00
|
|
|
module MailTemplateConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
|
2017-05-27 00:43:47 +02:00
|
|
|
TAGS = []
|
|
|
|
TAGS << TAG_NUMERO_DOSSIER = {
|
|
|
|
name: "numero_dossier",
|
|
|
|
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
|
|
|
}
|
|
|
|
TAGS << TAG_LIEN_DOSSIER = {
|
|
|
|
name: "lien_dossier",
|
|
|
|
description: "Permet d'afficher un lien vers le dossier de l'utilisateur."
|
|
|
|
}
|
|
|
|
TAGS << TAG_LIBELLE_PROCEDURE = {
|
|
|
|
name: "libelle_procedure",
|
|
|
|
description: "Permet d'afficher le libellé de la procédure."
|
|
|
|
}
|
|
|
|
TAGS << TAG_DATE_DE_DECISION = {
|
|
|
|
name: "date_de_decision",
|
|
|
|
description: "Permet d'afficher la date à laquelle la décision finale (acceptation, refus, classement sans suite) sur le dossier a été prise."
|
2017-05-03 11:34:42 +02:00
|
|
|
}
|
2017-05-03 11:46:41 +02:00
|
|
|
|
2017-05-03 11:58:34 +02:00
|
|
|
def object_for_dossier(dossier)
|
2017-03-06 11:51:34 +01:00
|
|
|
replace_tags(object, dossier)
|
|
|
|
end
|
|
|
|
|
2017-05-03 11:58:34 +02:00
|
|
|
def body_for_dossier(dossier)
|
2017-03-06 11:51:34 +01:00
|
|
|
replace_tags(body, dossier)
|
|
|
|
end
|
|
|
|
|
2017-05-03 11:58:34 +02:00
|
|
|
def replace_tags(string, dossier)
|
2017-03-06 11:51:34 +01:00
|
|
|
TAGS.inject(string) do |acc, tag|
|
2017-05-27 00:43:47 +02:00
|
|
|
acc.gsub!("--#{tag[:name]}--", replace_tag(tag, dossier)) || acc
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
2017-03-06 23:18:16 +01:00
|
|
|
def default
|
2017-05-27 01:16:38 +02:00
|
|
|
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
|
2017-03-06 23:18:16 +01:00
|
|
|
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body)
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-05-03 11:58:34 +02:00
|
|
|
def replace_tag(tag, dossier)
|
2017-03-06 11:51:34 +01:00
|
|
|
case tag
|
2017-05-27 00:43:47 +02:00
|
|
|
when TAG_NUMERO_DOSSIER
|
2017-03-06 11:51:34 +01:00
|
|
|
dossier.id.to_s
|
2017-05-27 00:43:47 +02:00
|
|
|
when TAG_LIEN_DOSSIER
|
2017-03-06 11:51:34 +01:00
|
|
|
link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank'
|
2017-05-27 00:43:47 +02:00
|
|
|
when TAG_LIBELLE_PROCEDURE
|
2017-03-06 11:51:34 +01:00
|
|
|
dossier.procedure.libelle
|
2017-05-27 00:43:47 +02:00
|
|
|
when TAG_DATE_DE_DECISION
|
2017-05-11 12:46:42 +02:00
|
|
|
dossier.processed_at.present? ? dossier.processed_at.localtime.strftime("%d/%m/%Y") : ""
|
2017-03-06 11:51:34 +01:00
|
|
|
else
|
|
|
|
'--BALISE_NON_RECONNUE--'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|