demarches-normaliennes/app/models/concerns/mail_template_concern.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

module MailTemplateConcern
extend ActiveSupport::Concern
include TagsSubstitutionConcern
2019-07-22 15:21:05 +02:00
module Actions
SHOW = :show
ASK_QUESTION = :ask_question
REPLY = :reply
end
def subject_for_dossier(dossier)
replace_tags(subject, dossier)
end
def body_for_dossier(dossier)
replace_tags(body, dossier)
end
2019-07-22 15:21:05 +02:00
def actions_for_dossier(dossier)
[MailTemplateConcern::Actions::SHOW, MailTemplateConcern::Actions::ASK_QUESTION]
end
2019-04-10 15:21:08 +02:00
def update_rich_body
self.rich_body = self.body
end
2019-04-10 15:21:08 +02:00
included do
has_rich_text :rich_body
2019-04-10 15:21:08 +02:00
before_save :update_rich_body
2019-04-10 15:21:08 +02:00
end
module ClassMethods
def default_for_procedure(procedure)
template_name = default_template_name_for_procedure(procedure)
body = ActionController::Base.new.render_to_string(template: template_name)
2018-03-16 18:30:23 +01:00
new(subject: const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure)
end
def default_template_name_for_procedure(procedure)
const_get(:DEFAULT_TEMPLATE_NAME)
end
end
def dossier_tags
TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
end
end