2016-08-31 16:07:11 +02:00
|
|
|
class MailTemplate < ActiveRecord::Base
|
2017-01-26 12:12:52 +01:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
|
2016-08-31 16:07:11 +02:00
|
|
|
belongs_to :procedure
|
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
TAGS = {
|
|
|
|
numero_dossier: {
|
|
|
|
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
|
|
|
},
|
|
|
|
lien_dossier: {
|
|
|
|
description: "Permet d'afficher un lien vers le dossier de l'utilisateur."
|
|
|
|
},
|
|
|
|
libelle_procedure: {
|
|
|
|
description: "Permet d'afficher le libellé de la procédure."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def object_for_dossier dossier
|
|
|
|
replace_tags(object, dossier)
|
|
|
|
end
|
2016-09-01 10:27:22 +02:00
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
def body_for_dossier dossier
|
|
|
|
replace_tags(body, dossier)
|
|
|
|
end
|
2016-09-01 10:27:22 +02:00
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
def replace_tags string, dossier
|
|
|
|
TAGS.inject(string) do |acc, tag|
|
|
|
|
acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym, dossier)) || acc
|
2016-09-01 10:27:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
def replace_tag tag, dossier
|
2016-09-01 10:27:22 +02:00
|
|
|
case tag
|
|
|
|
when :numero_dossier
|
2017-01-26 12:12:52 +01:00
|
|
|
dossier.id.to_s
|
|
|
|
when :lien_dossier
|
2017-02-20 14:11:12 +01:00
|
|
|
# TPS::Application::URL # quickfix
|
|
|
|
link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank'
|
2016-09-01 10:27:22 +02:00
|
|
|
when :libelle_procedure
|
2017-01-26 12:12:52 +01:00
|
|
|
dossier.procedure.libelle
|
2016-09-01 10:27:22 +02:00
|
|
|
else
|
|
|
|
'--BALISE_NON_RECONNUE--'
|
|
|
|
end
|
|
|
|
end
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|