From 850f4366c831ee4af7b203aa68957d7d0c414edd Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 18 Feb 2016 15:36:09 +0100 Subject: [PATCH] Add type de champ checkbox (boolean) --- app/decorators/champ_decorator.rb | 12 +++++++ app/models/type_de_champ.rb | 3 +- app/views/dossiers/_infos_dossier.html.haml | 2 +- app/views/users/description/show.html.haml | 36 ++++++++++++--------- spec/models/type_de_champ_spec.rb | 1 + 5 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 app/decorators/champ_decorator.rb diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb new file mode 100644 index 000000000..be8fcb54d --- /dev/null +++ b/app/decorators/champ_decorator.rb @@ -0,0 +1,12 @@ +class ChampDecorator < Draper::Decorator + + def value + if type_champ == 'checkbox' + return object.value == 'on' ? 'Oui' : 'Non' + end + end + + def type_champ + object.type_de_champ.type_champ + end +end \ No newline at end of file diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 3a3e2129e..8bd7c8a95 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -2,7 +2,8 @@ class TypeDeChamp < ActiveRecord::Base enum type_champs: {text: 'text', textarea: 'textarea', datetime: 'datetime', - number: 'number' + number: 'number', + checkbox: 'checkbox' } belongs_to :procedure diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 26819f039..bf1471b30 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -40,7 +40,7 @@ %th{ style: 'width:25%' } =champ.libelle %td - =champ.value + =champ.decorate.value .col-lg-6.col-md-6 =render partial: '/dossiers/pieces_justificatives' %br diff --git a/app/views/users/description/show.html.haml b/app/views/users/description/show.html.haml index 233b7cc30..77a258a71 100644 --- a/app/views/users/description/show.html.haml +++ b/app/views/users/description/show.html.haml @@ -20,22 +20,28 @@ -@champs.each do |champ| .row %div{class: "type_champ-#{champ.type_champ}"} - %h4 - = champ.libelle - - -if champ.type_champ == 'textarea' - %textarea.form-control{name:"champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}"} - =champ.value + -if champ.type_champ == 'checkbox' + %h4{style:'margin-left:15px;'} + = champ.libelle + %input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''} + %input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')} -else - %input.form-control{name:"champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}", - value: champ.value, - type:"#{champ.type_champ}", - 'data-provide' => ('datepicker' if champ.type_champ == 'datetime'), - 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} + %h4 + = champ.libelle + + -if champ.type_champ == 'textarea' + %textarea.form-control{name:"champs['#{champ.id}']", + placeholder: champ.libelle, + id: "champs_#{champ.id}"} + =champ.value + -else + %input.form-control{name:"champs['#{champ.id}']", + placeholder: champ.libelle, + id: "champs_#{champ.id}", + value: champ.value, + type:"#{champ.type_champ}", + 'data-provide' => ('datepicker' if champ.type_champ == 'datetime'), + 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} -if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.pieces_justificatives.size > 1 %br diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index d016ad016..101b2be02 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -28,6 +28,7 @@ describe TypeDeChamp do it { is_expected.to allow_value('textarea').for(:type_champ) } it { is_expected.to allow_value('datetime').for(:type_champ) } it { is_expected.to allow_value('number').for(:type_champ) } + it { is_expected.to allow_value('checkbox').for(:type_champ) } end context 'order_place' do