2017-03-06 11:51:34 +01:00
|
|
|
module MailTemplateConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2018-01-04 10:37:40 +01:00
|
|
|
include TagsSubstitutionConcern
|
2017-05-03 11:46:41 +02:00
|
|
|
|
2019-07-22 15:21:05 +02:00
|
|
|
module Actions
|
|
|
|
SHOW = :show
|
|
|
|
ASK_QUESTION = :ask_question
|
|
|
|
REPLY = :reply
|
|
|
|
end
|
|
|
|
|
2018-01-08 17:26:13 +01:00
|
|
|
def subject_for_dossier(dossier)
|
2023-02-09 17:49:43 +01:00
|
|
|
replace_tags(subject, dossier).presence || replace_tags(self.class::DEFAULT_SUBJECT, dossier)
|
2017-03-06 11:51:34 +01:00
|
|
|
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
|
|
|
|
|
2019-07-22 15:21:05 +02:00
|
|
|
def actions_for_dossier(dossier)
|
|
|
|
[MailTemplateConcern::Actions::SHOW, MailTemplateConcern::Actions::ASK_QUESTION]
|
|
|
|
end
|
|
|
|
|
2022-05-10 16:23:22 +02:00
|
|
|
def attachment_for_dossier(dossier)
|
|
|
|
nil
|
|
|
|
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
|
|
|
|
|
2023-07-05 23:22:05 +02:00
|
|
|
class_methods do
|
2017-12-22 21:37:08 +01:00
|
|
|
def default_for_procedure(procedure)
|
2018-03-16 18:32:43 +01:00
|
|
|
template_name = default_template_name_for_procedure(procedure)
|
2022-04-19 09:39:24 +02:00
|
|
|
rich_body = ActionController::Base.render template: template_name
|
2020-08-25 11:40:24 +02:00
|
|
|
trix_rich_body = rich_body.gsub(/(?<!^|[.-])(?<!<\/strong>)\n/, '')
|
2023-07-05 23:22:05 +02:00
|
|
|
new(subject: const_get(:DEFAULT_SUBJECT), body: trix_rich_body, rich_body: trix_rich_body, procedure: procedure)
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
2018-03-16 18:32:43 +01:00
|
|
|
|
|
|
|
def default_template_name_for_procedure(procedure)
|
|
|
|
const_get(:DEFAULT_TEMPLATE_NAME)
|
|
|
|
end
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
|
2018-01-04 10:37:40 +01:00
|
|
|
def dossier_tags
|
2018-01-18 11:52:48 +01:00
|
|
|
TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|