2020-03-23 20:46:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Formulario de contacto
|
|
|
|
class ContactMailer < ApplicationMailer
|
2020-05-30 19:43:25 +00:00
|
|
|
attr_reader :form
|
|
|
|
|
2020-03-25 18:50:07 +00:00
|
|
|
# Enviar el formulario de contacto a les usuaries
|
2020-03-23 20:46:19 +00:00
|
|
|
def notify_usuaries
|
2020-05-30 19:43:25 +00:00
|
|
|
subject = "[#{site.title}] #{params[:form_name].humanize}"
|
|
|
|
params[:form_definition] = site.form(params[:form_name])
|
|
|
|
|
|
|
|
attachments[params[:form_name] + '.csv'] = generate_csv
|
|
|
|
|
|
|
|
mail to: params[:usuaries_emails],
|
|
|
|
reply_to: params[:form][:from],
|
|
|
|
subject: subject
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# El CSV es un archivo adjunto con dos filas, una con las etiquetas de
|
|
|
|
# los campos en la cabecera y otra con los valores.
|
|
|
|
def generate_csv
|
|
|
|
csv = ["\xEF\xBB\xBF"]
|
|
|
|
csv << params[:form].keys.map do |field|
|
|
|
|
params[:form_definition].t(field)
|
|
|
|
end.to_csv(col_sep: ';', force_quotes: true)
|
|
|
|
|
|
|
|
csv << params[:form].values.to_csv(col_sep: ';', force_quotes: true)
|
|
|
|
|
|
|
|
{
|
|
|
|
mime_type: 'text/csv; charset=utf-8',
|
|
|
|
content: csv.join
|
|
|
|
}
|
2020-03-23 20:46:19 +00:00
|
|
|
end
|
|
|
|
end
|