[Fix #3064] Add a preview button for state notifications emails

This commit is contained in:
Mathieu Magnin 2019-03-14 14:58:01 +01:00
parent e91b412254
commit 14c3fb7224
4 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,33 @@
module NewAdministrateur
class MailTemplatesController < AdministrateurController
include ActionView::Helpers::SanitizeHelper
def preview
@procedure = procedure
mail_template = find_mail_template_by_slug(params[:id])
@dossier = Dossier.new(id: 0)
render(html: sanitize(mail_template.body), layout: 'mailers/notification')
end
private
def procedure
@procedure = current_administrateur.procedures.find(params[:procedure_id])
end
def mail_templates
[
@procedure.initiated_mail_template,
@procedure.received_mail_template,
@procedure.closed_mail_template,
@procedure.refused_mail_template,
@procedure.without_continuation_mail_template
]
end
def find_mail_template_by_slug(slug)
mail_templates.find { |template| template.class.const_get(:SLUG) == slug }
end
end
end

View file

@ -15,6 +15,7 @@
.text-right
= link_to "Annuler", admin_procedure_mail_templates_path(@procedure), class: "btn btn-default"
= f.button :submit, 'Mettre à jour', class: "btn-success"
= link_to "Prévisualiser", preview_procedure_mail_template_path(@procedure, @mail_template.class.const_get(:SLUG)), class: "btn btn-primary", target: "_blank"
.row
.col-md-12

View file

@ -378,6 +378,10 @@ Rails.application.routes.draw do
patch :move
end
end
resources :mail_templates, only: [] do
get 'preview', on: :member
end
end
resources :services, except: [:show] do

View file

@ -10,6 +10,7 @@ describe 'admin/mail_templates/edit.html.haml', type: :view do
allow(view).to receive(:admin_procedure_mail_templates_path).and_return("/toto")
assign(:mail_template, mail_template)
assign(:procedure, procedure)
end
context "Champs are listed in the page" do