Real index and edit for mail_templates

This commit is contained in:
Mathieu Magnin 2017-01-24 10:19:42 +01:00
parent 7e24adbca0
commit 0e5c90cb0c
6 changed files with 66 additions and 26 deletions

View file

@ -2,11 +2,15 @@ class Admin::MailsController < AdminController
before_action :retrieve_procedure
def index
@mail_templates = @procedure.mail_templates
end
def edit
@mail_template = @procedure.mail_templates.find(params[:id])
end
def update
mail = current_administrateur.procedures.find(params[:procedure_id]).mail_templates.find(params[:id])
mail = @procedure.mail_templates.find(params[:id])
mail.update_attributes(update_params)
redirect_to admin_procedure_mails_path
@ -17,4 +21,4 @@ class Admin::MailsController < AdminController
def update_params
params.require(:mail_received).permit(:body, :object)
end
end
end

View file

@ -0,0 +1,27 @@
.white-back
%h3
E-mail d'accusé de réception
= @mail_template.type
= form_for @mail_template, url: {controller: 'admin/mails', action: 'update', id: @procedure.mail_received.id} do |f|
=f.text_field :object, {class:'form-control', style:'width: 40%'}
%br
=f.text_area :body, {class: 'form-control wysihtml5'}
%br
=f.submit 'Mettre à jour', {class:'btn btn-success', style:'float: right'}
%table.table{style:'width: 50%'}
%tr
%th
Balise
%th
Description
- MailTemplate.tags.each do |balise|
%tr
%td.center
%b.text-success
\--
= balise.first
\--
%td
=balise.second[:description]

View file

@ -1,28 +1,13 @@
.row.white-back
%h3
E-mail d'accusé de réception
%h1 Emails personnalisables
- unless @procedure.mail_received.blank?
= form_for @procedure.mail_received, url: {controller: 'admin/mails', action: 'update', id: @procedure.mail_received.id} do |f|
=f.text_field :object, {class:'form-control', style:'width: 40%'}
%br
=f.text_area :body, {class: 'form-control wysihtml5'}
%br
=f.submit 'Mettre à jour', {class:'btn btn-success', style:'float: right'}
%table.table{style:'width: 50%'}
%table.table
%tr
%th
Balise
%th
Description
- MailTemplate.tags.each do |balise|
%th{ colspan: 2 }
Type d'email
- @procedure.mail_templates.each do |mt|
%tr
%td.center
%b.text-success
\--
= balise.first
\--
%td
=balise.second[:description]
= mt.type
%td.text-right
= link_to "Personnaliser l'email", edit_admin_procedure_mail_path(@procedure, mt)

View file

@ -8,9 +8,13 @@ describe Admin::MailsController, type: :controller do
end
describe 'GET index' do
render_views
subject { get :index, params: {procedure_id: procedure.id} }
it { expect(subject.status).to eq 200 }
it { expect(subject.body).to include("Emails personnalisables") }
it { expect(subject.body).to include(*procedure.mail_templates.pluck(:type)) }
end
describe 'PATCH update' do
@ -39,4 +43,4 @@ describe Admin::MailsController, type: :controller do
end
end
end
end
end

View file

@ -0,0 +1,19 @@
FactoryGirl.define do
factory :mail_template do
object "Object, voila voila"
body "Blabla ceci est mon body"
type 'MailValidated'
trait :dossier_submitted do
type 'MailSubmitted'
end
trait :dossier_refused do
type 'MailRefused'
end
trait :dossier_received do
type 'MailReceived'
end
end
end

View file

@ -8,6 +8,7 @@ FactoryGirl.define do
direction "direction SGMAP"
published false
administrateur { create(:administrateur) }
mail_templates { [create(:mail_template, :dossier_received)]}
after(:build) do |procedure, _evaluator|
if procedure.module_api_carto.nil?