2016-08-31 16:07:11 +02:00
|
|
|
class MailTemplate < ActiveRecord::Base
|
|
|
|
belongs_to :procedure
|
|
|
|
|
2016-09-01 10:27:22 +02:00
|
|
|
enum tags: {
|
2016-08-31 16:07:11 +02:00
|
|
|
numero_dossier: {
|
|
|
|
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
2016-09-01 10:27:22 +02:00
|
|
|
},
|
|
|
|
libelle_procedure: {
|
|
|
|
description: "Permet d'afficher le libellé de la procédure."
|
2016-08-31 16:07:11 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-01 10:27:22 +02:00
|
|
|
|
|
|
|
def self.replace_tags string, dossier
|
|
|
|
@dossier = dossier
|
|
|
|
|
|
|
|
tags.inject(string) do |acc, tag|
|
|
|
|
acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym)) || acc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def self.replace_tag tag
|
|
|
|
case tag
|
|
|
|
when :numero_dossier
|
|
|
|
@dossier.id.to_s
|
|
|
|
when :libelle_procedure
|
|
|
|
@dossier.procedure.libelle
|
|
|
|
else
|
|
|
|
'--BALISE_NON_RECONNUE--'
|
|
|
|
end
|
|
|
|
end
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|