Merge pull request #41 from sgmap/field_paragraph

Field explication
This commit is contained in:
Mathieu Magnin 2017-03-16 14:41:12 +01:00 committed by GitHub
commit 7f789b1487
12 changed files with 82 additions and 48 deletions

View file

@ -23,13 +23,13 @@ function destroy_action(){
}
function on_change_type_de_champ_select (){
$("select.form-control.type_champ").on('change', function(e){
parent = $(this).parent().parent();
parent.removeClass('header_section');
parent.children(".drop_down_list").removeClass('show_inline');
$('.mandatory', parent).show();
switch(this.value){
case 'header_section':
@ -38,7 +38,9 @@ function on_change_type_de_champ_select (){
case 'drop_down_list':
parent.children(".drop_down_list").addClass('show_inline');
break;
case 'explication':
$('.mandatory', parent).hide();
break;
}
})
});
}

View file

@ -23,6 +23,10 @@
}
#liste_champ{
.form-inline {
margin-bottom: 30px;
}
.show_inline {
display: inline-block !important;
}
@ -30,4 +34,16 @@
.form-group.drop_down_list{
display: none;
}
.form-group {
vertical-align: top;
margin-right: 15px;
}
.description {
padding: 0;
textarea {
padding: 6px 12px;
}
}
}

View file

@ -3,11 +3,19 @@ class TypeDeChampDecorator < Draper::Decorator
delegate_all
def button_up params
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index], params[:private])
h.link_to '', params[:url], class: up_classes,
id: "btn_up_#{params[:index]}",
remote: true,
method: :post,
style: display_up_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;'
end
def button_down params
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index], params[:private])
h.link_to '', params[:url], class: down_classes,
id: "btn_down_#{params[:index]}",
remote: true,
method: :post,
style: display_down_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;'
end
private

View file

@ -16,7 +16,8 @@ class TypeDeChamp < ActiveRecord::Base
regions: 'regions',
departements: 'departements',
engagement: 'engagement',
header_section: 'header_section'
header_section: 'header_section',
explication: 'explication'
}
belongs_to :procedure
@ -29,7 +30,7 @@ class TypeDeChamp < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
before_validation :change_header_section_mandatory
before_validation :check_mandatory
def self.type_de_champs_list_fr
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
@ -39,8 +40,8 @@ class TypeDeChamp < ActiveRecord::Base
!(type_champ == 'textarea' || type_champ == 'header_section')
end
def change_header_section_mandatory
self.mandatory = false if self.type_champ == 'header_section'
def check_mandatory
self.mandatory = false if %w(header_section explication).include?(self.type_champ)
true
end
end

View file

@ -1,5 +1,5 @@
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
.form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"}
.form-inline{ class: (ff.object.object.type_champ == 'header_section' ? 'header_section' : '') }
.form-group.libelle
%h4 Libellé
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
@ -10,15 +10,17 @@
.form-group.description
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 2
= ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 3
.form-group.drop_down_list{class:"#{ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''}",style:'margin-right: 5px'}
.form-group.drop_down_list{ class: (ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''), style: 'margin-right: 5px' }
%h4 Liste déroulante
= ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff|
= fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne.\nEcrire --valeur-- pour un séparateur.", rows: 3, cols: 30
= fff.hidden_field :id
- unless ff.object.object.class == TypeDeChampPrivate
.form-group.mandatory
- hide_mandatory = (ff.object.object.class == TypeDeChampPrivate || ff.object.object.type_champ == 'explication')
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : '' }
%h4 Obligatoire ?
.center
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'

View file

@ -1,5 +1,5 @@
%div.row
.col-lg-12.col-md-12.col-sm-12.col-xs-12
.col-xs-12
- if @facade.procedure.for_individual?
.row.title-row
%div.col-xs-4.split-hr
@ -7,24 +7,25 @@
%div.col-xs-4.split-hr
.row
%div.col-xs-6.depositaire-label Civilité
%div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-"
%div.col-xs-1.comments-off= "-"
%div.col-xs-5.depositaire-info= @facade.individual.gender
.row
%div.col-xs-6.depositaire-label Nom
%div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-"
%div.col-xs-1.comments-off= "-"
%div.col-xs-5.depositaire-info= @facade.individual.nom
.row
%div.col-xs-6.depositaire-label Prénom
%div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-"
%div.col-xs-1.comments-off= "-"
%div.col-xs-5.despositaire-info= @facade.individual.prenom
.row
%div.col-xs-6.depositaire-label Date de naissance
%div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-"
%div.col-xs-1.comments-off= "-"
%div.col-xs-5.depositaire-info= @facade.individual.birthdate
.row.margin-top-20
- unless @facade.champs.nil?
- @facade.champs.each do |champ|
- next if champ.type_champ == 'explication'
- if champ.type_champ == 'header_section'
.row.title-row.margin-top-40
%div.col-xs-3.split-hr

View file

@ -1,9 +1,9 @@
.default_data_block.default_visible
%div.row.show-block.infos
%div.header
%div.col-lg-12.col-md-12.col-sm-12.col-xs-12.title
%div.carret-right
%div.carret-down
.row.show-block.infos
.header
.col-xs-12.title
.carret-right
.carret-down
=libelle
%div.body
.body
= render partial: 'users/description/champs/render_list_champs', locals: {champs: champs, order_place: order_place}

View file

@ -41,6 +41,8 @@
- elsif champ.type_champ == 'departements'
= render partial: 'users/description/champs/departements', locals: { champ: champ }
- elsif champ.type_champ == 'explication'
- else
%input.form-control{name:"champs['#{ champ.id }']",
placeholder: champ.libelle,

View file

@ -22,3 +22,4 @@ fr:
departements: 'Départements'
engagement: 'Engagement'
header_section: 'Titre de section'
explication: 'Explication'

View file

@ -16,8 +16,8 @@ describe TypeDeChampDecorator do
subject { type_de_champ_0.decorate }
let(:button_up) { type_de_champ_.decorate }
it 'returns a button up' do
expect(subject.button_up(params)).to be(nil)
it 'hide a button up' do
expect(subject.button_up(params)).to include('visibility: hidden')
end
it 'returns a button down' do
expect(subject.button_down(params)).to match(/fa-chevron-down/)
@ -45,8 +45,9 @@ describe TypeDeChampDecorator do
it 'returns a button up' do
expect(subject.button_up(params)).to match(/fa-chevron-up/)
end
it 'returns a button down' do
expect(subject.button_down(params)).to be(nil)
it 'hide a button down' do
expect(subject.button_down(params)).to include('visibility: hidden')
end
end
end

View file

@ -33,8 +33,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
end
context 'when there is only one field in database' do
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
it { expect(subject).not_to have_css('#btn_down_0') }
it { expect(subject).not_to have_css('#btn_up_0') }
it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') }
it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') }
it { expect(subject).not_to have_css('#btn_up_1') }
it { expect(subject).not_to have_css('#btn_down_1') }
end
@ -42,9 +42,9 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
it { expect(subject).to have_css('#btn_down_0') }
it { expect(subject).not_to have_css('#btn_up_0') }
it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') }
it { expect(subject).to have_css('#btn_up_1') }
it { expect(subject).not_to have_css('#btn_down_1') }
it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') }
end
end
end

View file

@ -30,7 +30,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
describe 'mandatory checkbox' do
it 'no mandatory checkbox are present' do
expect(subject).not_to have_css('.form-group.mandatory')
expect(subject).to have_css('.form-group.mandatory[style*="visibility: hidden"]')
end
end
@ -41,8 +41,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
end
context 'when there is only one field in database' do
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
it { expect(subject).not_to have_css('#btn_down_0') }
it { expect(subject).not_to have_css('#btn_up_0') }
it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') }
it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') }
it { expect(subject).not_to have_css('#btn_up_1') }
it { expect(subject).not_to have_css('#btn_down_1') }
end
@ -50,9 +50,9 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
it { expect(subject).to have_css('#btn_down_0') }
it { expect(subject).not_to have_css('#btn_up_0') }
it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') }
it { expect(subject).to have_css('#btn_up_1') }
it { expect(subject).not_to have_css('#btn_down_1') }
it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') }
end
end
end