Front to add TypeDePieceJustificative for a procedure

Back not implement for this commit
This commit is contained in:
Xavier J 2015-10-28 15:55:31 +01:00
parent e673fe6ae2
commit 059211755a
6 changed files with 120 additions and 1 deletions

View file

@ -7,6 +7,13 @@ ready = function () {
e.stopPropagation();
return false;
});
$("#add_type_de_piece_justificative_procedure").on('click', function (e) {
add_new_type_de_piece_justificative();
e.stopPropagation();
return false;
});
};
$(document).ready(ready);
@ -41,3 +48,28 @@ function add_new_type_de_champs() {
$("#new_type_de_champs #add_type_de_champs_button").remove();
$("#new_type_de_champs .form-inline").append($("#add_type_de_champs_button"))
}
function add_new_type_de_piece_justificative() {
var index_id = "#type_de_piece_justificative_" + types_de_piece_justificative_index;
$("#liste_piece_justificative").append($(index_id));
$("#new_type_de_piece_justificative").append($(index_id).clone());
types_de_piece_justificative_index++;
$("#new_type_de_piece_justificative .form-inline").attr('id', 'type_de_piece_justificative_' + types_de_piece_justificative_index);
$("#new_type_de_piece_justificative #libelle").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][libelle]');
$("#new_type_de_piece_justificative #libelle").val('');
$("#new_type_de_piece_justificative #description").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][description]');
$("#new_type_de_piece_justificative #description").val('');
$("#new_type_de_piece_justificative #id_type_de_piece_justificative").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][id_type_de_piece_justificative]');
$("#new_type_de_piece_justificative #id_type_de_piece_justificative").val('')
$("#new_type_de_piece_justificative #delete").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][delete]');
$("#new_type_de_piece_justificative #delete").val('false')
$("#new_type_de_piece_justificative #add_type_de_piece_justificative_button").remove();
$("#new_type_de_piece_justificative .form-inline").append($("#add_type_de_piece_justificative_button"))
}

View file

@ -37,6 +37,7 @@
%h3.text-info
Liste des pièces justificatives à fournir pour un dossier
=render partial: 'admin/procedures/types_de_piece_justificative/liste', locals: {f: f}
%br
%div.small{style:'text-align:right'}

View file

@ -0,0 +1,18 @@
.form-inline{id:"type_de_piece_justificative_#{index}", style: 'padding-bottom:8px'}
.form-group{ style: 'padding-right: 2%' }
%h4 Libellé
%input.form-control#libelle{ type: 'text', placeholder: 'Libelle', name:"type_de_piece_justificative[#{index}][libelle]", size: 40, value: ("#{ type_de_piece_justificative.libelle }" unless type_de_piece_justificative.nil? ) }
.form-group{ style: 'padding-right: 2%' }
%h4
Description
%textarea.form-control#description{cols: 60, placeholder: 'Description', name: "type_de_piece_justificative[#{index}][description]"}
=("#{ type_de_piece_justificative.description }" unless type_de_piece_justificative.nil? )
%input#id_type_de_piece_justificative{type: 'hidden', name: "type_de_piece_justificative[#{index}][id_type_de_piece_justificative]", value: (("#{ type_de_piece_justificative.id}" unless type_de_piece_justificative.nil?))}
%input#delete{type: 'hidden', name: "type_de_piece_justificative[#{index}][delete]", value: 'false'}
-if type_de_piece_justificative.nil?
.form-group#add_type_de_piece_justificative_button
%br  
%button.form-control.btn.btn-success#add_type_de_piece_justificative_procedure Ajouter

View file

@ -0,0 +1,10 @@
#liste_piece_justificative
-if @procedure.types_de_piece_justificative.size > 0
- @procedure.types_de_piece_justificative.order(:order_place).each_with_index do |type_de_piece_justificative, index|
=render partial: 'admin/procedures/types_de_piece_justificative/form', locals:{ type_de_piece_justificative: type_de_piece_justificative, index: index }
#new_type_de_piece_justificative
=render partial: 'admin/procedures/types_de_piece_justificative/form', locals:{ type_de_piece_justificative: nil, index: @procedure.types_de_piece_justificative.size }
%script{ type:'text/javascript' }
="var types_de_piece_justificative_index = #{@procedure.types_de_piece_justificative.size}"

View file

@ -28,7 +28,7 @@ feature 'add a new type de champs', js: true do
before do
page.find_by_id('type_de_champs_0').find_by_id('libelle').set 'Libelle de test'
page.find_by_id('type_de_champs_0').find_by_id('description').set 'Description de test'
page.click_on 'Ajouter'
page.click_on 'add_type_de_champs_procedure'
end
scenario 'a new champs type line is appeared with increment index id' do

View file

@ -0,0 +1,58 @@
require 'spec_helper'
feature 'add a new type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when create a new procedure' do
before do
visit new_admin_procedure_path
end
scenario 'page have form to created new type de champs' do
expect(page).to have_css('#type_de_piece_justificative_0')
expect(page).to have_css('input[name="type_de_piece_justificative[0][libelle]"]')
expect(page).to have_css('textarea[name="type_de_piece_justificative[0][description]"]')
expect(page).to have_css('input[name="type_de_piece_justificative[0][id_type_de_piece_justificative]"]', visible: false)
expect(page).to have_css('input[name="type_de_piece_justificative[0][delete]"]', visible: false)
expect(page).to have_css('#new_type_de_piece_justificative #add_type_de_piece_justificative_button')
end
context 'when user add a new champs type' do
before do
page.find_by_id('type_de_piece_justificative_0').find_by_id('libelle').set 'Libelle de test'
page.find_by_id('type_de_piece_justificative_0').find_by_id('description').set 'Description de test'
page.click_on 'add_type_de_piece_justificative_procedure'
end
scenario 'a new champs type line is appeared with increment index id' do
expect(page).to have_css('#type_de_piece_justificative_1')
expect(page).to have_css('input[name="type_de_piece_justificative[1][libelle]"]')
expect(page).to have_css('textarea[name="type_de_piece_justificative[1][description]"]')
expect(page).to have_css('input[name="type_de_piece_justificative[1][id_type_de_piece_justificative]"]', visible: false)
expect(page).to have_css('input[name="type_de_piece_justificative[1][delete]"]', visible: false)
end
scenario 'the first line is filled' do
expect(page.find_by_id('type_de_piece_justificative_0').find_by_id('libelle').value).to eq('Libelle de test')
expect(page.find_by_id('type_de_piece_justificative_0').find_by_id('description').value).to eq('Description de test')
end
scenario 'the new line is empty' do
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('libelle').value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('description').value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('id_type_de_piece_justificative', visible: false).value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('delete', visible: false).value).to eq('false')
end
scenario 'the button Ajouter is at side new line' do
expect(page).to have_css('#new_type_de_piece_justificative #type_de_piece_justificative_1 #add_type_de_piece_justificative_button')
expect(page).not_to have_css('#type_de_piece_justificative_0 #add_type_de_piece_justificative_button')
end
end
end
end