DossierLink: add edition template

This commit is contained in:
Simon Lehericey 2017-03-28 15:09:03 +02:00
parent 785219c956
commit 3228737a87
5 changed files with 121 additions and 0 deletions

View file

@ -0,0 +1,36 @@
(function() {
var showNotFound = function() {
$('.dossier-link .text-info').hide();
$('.dossier-link .text-warning').show();
};
var showData = function(data) {
$('.dossier-link .procedureLibelle').text(data.procedureLibelle);
$('.dossier-link .text-info').show();
$('.dossier-link .text-warning').hide();
};
var hideEverything = function() {
$('.dossier-link .text-info').hide();
$('.dossier-link .text-warning').hide();
};
var fetchProcedureLibelle = function(e) {
var dossierId = $(e.target).val();
if(dossierId) {
$.get('/users/dossiers/' + dossierId + '/procedure_libelle')
.done(showData)
.fail(showNotFound);
} else {
hideEverything();
}
};
var timeOut = null;
var debounceFetchProcedureLibelle = function(e) {
if(timeOut){ clearTimeout(timeOut); }
timeOut = setTimeout(function() { fetchProcedureLibelle(e); }, 300);
};
$(document).on('input', '[data-type=dossier-link]', debounceFetchProcedureLibelle);
})();

View file

@ -0,0 +1,21 @@
- dossier = Dossier.find_by(id: champ.value)
- show_procedure_libelle = dossier ? true : false
- show_warning = !show_procedure_libelle && champ.value.present?
- procedure_libelle = dossier.nil? ? '' : dossier.procedure.libelle
.dossier-link
%input.form-control{ name: "champs['#{ champ.id }']",
placeholder: champ.libelle,
id: "champs_#{ champ.id }",
value: champ.value,
type: 'number',
'autocomplete' => 'off',
'data-type' => 'dossier-link' }
.help-block
%p.text-info{ style: show_procedure_libelle ? nil : 'display: none;' }
ce dossier répond à la procédure :
%br
%span.procedureLibelle= procedure_libelle
%p.text-warning{ style: show_warning ? nil : 'display: none;' }
ce dossier est inconnu

View file

@ -41,6 +41,9 @@
- elsif champ.type_champ == 'departements'
= render partial: 'users/description/champs/departements', locals: { champ: champ }
- elsif champ.type_champ == 'dossier_link'
= render partial: 'users/description/champs/dossier_link', locals: { champ: champ }
- elsif champ.type_champ == 'explication'
- else

View file

@ -0,0 +1,47 @@
require 'spec_helper'
describe 'users/description/champs/dossier_link.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) }
before do
render 'users/description/champs/dossier_link.html.haml', champ: champ
end
context 'When no dossier is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a dossier whith a procedure is provided' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: dossier.id) }
it 'should display the procedure libelle' do
expect(rendered).not_to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a unknown dossier id is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: 666) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should display a warning' do
expect(rendered).not_to have_css('.text-warning[style*="display: none"]')
end
end
end

View file

@ -24,4 +24,18 @@ describe 'users/description/champs/render_list_champs.html.haml', type: :view do
expect(rendered).to have_css('input[type=checkbox][checked]')
end
end
context 'with a dossier_link' do
let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should render a number input with the right data-attribute' do
expect(view).to render_template(partial: 'users/description/champs/_dossier_link',
locals: { champ: champ })
end
end
end