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-03-05 11:05:28 +01:00
|
|
|
@mails = mails
|
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])
|
2017-05-03 11:46:41 +02:00
|
|
|
@mail_template_name = 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])
|
2017-01-24 14:36:43 +01:00
|
|
|
mail_template.update_attributes(update_params)
|
|
|
|
redirect_to admin_procedure_mail_templates_path
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-03-05 11:05:28 +01:00
|
|
|
def mails
|
2017-05-27 00:50:00 +02:00
|
|
|
[
|
|
|
|
@procedure.initiated_mail,
|
|
|
|
@procedure.received_mail,
|
|
|
|
@procedure.closed_mail,
|
|
|
|
@procedure.refused_mail,
|
|
|
|
@procedure.without_continuation_mail
|
|
|
|
]
|
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:52:32 +02:00
|
|
|
mails.find { |m| m.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],
|
|
|
|
object: params[:mail_template][:object],
|
|
|
|
body: params[:mail_template][:body],
|
|
|
|
}
|
2016-08-31 16:07:11 +02:00
|
|
|
end
|
2017-01-24 10:19:42 +01:00
|
|
|
end
|