2017-01-24 14:36:43 +01:00
|
|
|
class Admin::MailTemplatesController < AdminController
|
2016-08-31 16:07:11 +02:00
|
|
|
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
|
2016-08-31 16:07:11 +02:00
|
|
|
|
2017-01-24 10:19:42 +01:00
|
|
|
def edit
|
2017-05-27 00:50:29 +02:00
|
|
|
@mail_template = find_mail_template_by_slug(params[:id])
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-05-27 00:50:29 +02:00
|
|
|
mail_template = find_mail_template_by_slug(params[:id])
|
2018-03-02 16:27:03 +01:00
|
|
|
mail_template.update(update_params)
|
2017-01-24 14:36:43 +01:00
|
|
|
redirect_to admin_procedure_mail_templates_path
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-05-27 00:54:34 +02:00
|
|
|
def mail_templates
|
2017-05-27 00:50:00 +02:00
|
|
|
[
|
2017-05-27 01:08:01 +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
|
|
|
]
|
2017-03-05 11:05:28 +01:00
|
|
|
end
|
|
|
|
|
2017-05-27 00:50:29 +02:00
|
|
|
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 }
|
2017-03-05 11:05:28 +01:00
|
|
|
end
|
|
|
|
|
2016-08-31 16:07:11 +02:00
|
|
|
def update_params
|
2017-03-05 11:05:28 +01:00
|
|
|
{
|
|
|
|
procedure_id: params[:procedure_id],
|
2018-01-08 17:26:13 +01:00
|
|
|
subject: params[:mail_template][:subject],
|
2017-03-05 11:05:28 +01:00
|
|
|
body: params[:mail_template][:body],
|
|
|
|
}
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|
2017-01-24 10:19:42 +01:00
|
|
|
end
|