2017-03-06 11:51:34 +01:00
|
|
|
module MailTemplateConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
include ActionView::Helpers::UrlHelper
|
2018-01-04 10:37:40 +01:00
|
|
|
include TagsSubstitutionConcern
|
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
|
|
|
|
|
2018-01-04 10:37:40 +01:00
|
|
|
# TODO: remove legacy argument when removing legacy tags
|
|
|
|
def tags(reject_legacy: true, is_dossier_termine: self.class.const_get(:IS_DOSSIER_TERMINE))
|
|
|
|
super(is_dossier_termine: is_dossier_termine)
|
|
|
|
.reject { |tag| reject_legacy && tag[:is_legacy] }
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
2017-12-22 21:37:08 +01:00
|
|
|
def default_for_procedure(procedure)
|
2017-05-27 01:16:38 +02:00
|
|
|
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
|
2017-12-22 21:37:08 +01:00
|
|
|
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body, procedure: procedure)
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-01-04 10:37:40 +01:00
|
|
|
def dossier_tags
|
|
|
|
super +
|
|
|
|
[{ libelle: 'lien dossier', description: '', lambda: -> (d) { users_dossier_recapitulatif_link(d) } },
|
|
|
|
# TODO: remove legacy tags
|
|
|
|
{ libelle: 'numero_dossier', description: '', target: :id, is_legacy: true },
|
|
|
|
{ libelle: 'lien_dossier', description: '', lambda: -> (d) { users_dossier_recapitulatif_link(d) }, is_legacy: true },
|
|
|
|
{ libelle: 'libelle_procedure', description: '', lambda: -> (d) { d.procedure.libelle }, is_legacy: true },
|
|
|
|
{ libelle: 'date_de_decision', description: '',
|
|
|
|
lambda: -> (d) { d.processed_at.present? ? d.processed_at.localtime.strftime('%d/%m/%Y') : '' },
|
|
|
|
dossier_termine_only: true, is_legacy: true }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def users_dossier_recapitulatif_link(dossier)
|
|
|
|
url = users_dossier_recapitulatif_url(dossier)
|
|
|
|
link_to(url, url, target: '_blank')
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|