demarches-normaliennes/app/controllers/admin/mail_templates_controller.rb

42 lines
975 B
Ruby
Raw Normal View History

class Admin::MailTemplatesController < AdminController
before_action :retrieve_procedure
def index
2017-05-27 00:54:34 +02:00
@mail_templates = mail_templates
2017-01-24 10:19:42 +01:00
end
2017-01-24 10:19:42 +01:00
def edit
@mail_template = find_mail_template_by_slug(params[:id])
end
def update
mail_template = find_mail_template_by_slug(params[:id])
mail_template.update_attributes(update_params)
redirect_to admin_procedure_mail_templates_path
end
private
2017-05-27 00:54:34 +02:00
def mail_templates
2017-05-27 00:50:00 +02:00
[
@procedure.initiated_mail_template,
@procedure.received_mail_template,
@procedure.closed_mail_template,
@procedure.refused_mail_template,
@procedure.without_continuation_mail_template
2017-05-27 00:50:00 +02:00
]
end
def find_mail_template_by_slug(slug)
2017-05-27 00:54:34 +02:00
mail_templates.find { |template| template.class.const_get(:SLUG) == slug }
end
def update_params
{
procedure_id: params[:procedure_id],
object: params[:mail_template][:object],
body: params[:mail_template][:body],
}
end
2017-01-24 10:19:42 +01:00
end