refresh list of pj when adding new one

This commit is contained in:
Tanguy PATTE 2015-11-20 14:17:38 +01:00
parent bcf712828e
commit bd5dc1e35a
5 changed files with 38 additions and 23 deletions

View file

@ -0,0 +1,16 @@
= f.fields_for :types_de_piece_justificative, types_de_piece_justificative do |ff|
.form-inline
.form-group
%h4 Libellé
=ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
.form-group
%h4 Description
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
-if ff.object.id.nil?
.form-group#add_type_de_piece_justificative_button
%br  
= f.submit('Ajouter la pièce')

View file

@ -1,16 +1,7 @@
= form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure) , remote: true do |f|
#liste_piece_justificative
= render partial: 'fields', locals:{ types_de_piece_justificative: @procedure.types_de_piece_justificative, f: f }
%hr
= f.fields_for :types_de_piece_justificative, types_de_piece_justificative do |ff|
.form-inline
.form-group
%h4 Libellé
=ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
.form-group
%h4 Description
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
-if ff.object.id.nil?
.form-group#add_type_de_piece_justificative_button
%br  
= f.submit('Ajouter la pièce')
#new_type_de_piece_justificative
= render partial: 'fields', locals:{ types_de_piece_justificative: TypeDePieceJustificative.new, f: f }

View file

@ -3,10 +3,5 @@
%li= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
%li.active= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
= form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure) , remote: true do |f|
#liste_piece_justificative
= render partial: 'form', locals:{ types_de_piece_justificative: @procedure.types_de_piece_justificative, f: f }
%hr
#new_type_de_piece_justificative
= render partial: 'form', locals:{ types_de_piece_justificative: TypeDePieceJustificative.new, f: f }
#piece_justificative_form
= render 'form'

View file

@ -0,0 +1 @@
$('#piece_justificative_form').html("<%= escape_javascript(render partial: 'form', locals: { procedure: @procedure } ) %>");

View file

@ -12,7 +12,9 @@ feature 'add a new type de piece justificative', js: true do
visit admin_procedure_pieces_justificatives_path(procedure)
end
scenario 'displays a form to add new type de piece justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle')
within '#new_type_de_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle')
end
end
context 'when user fills field and submit' do
let(:libelle) { 'ma piece' }
@ -31,6 +33,16 @@ feature 'add a new type de piece justificative', js: true do
expect(subject.libelle).to eq(libelle)
expect(subject.description).to eq(description)
end
scenario 'displays new created pj' do
within '#liste_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle')
expect(page.body).to match(libelle)
expect(page.body).to match(description)
end
within '#new_type_de_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
end
end
end
end
end