Delegate mandatory? to type_de_champ

This commit is contained in:
Paul Chavard 2018-02-09 17:42:53 +01:00
parent 82e7d33e2f
commit f80a9466b9
16 changed files with 16 additions and 20 deletions

View file

@ -5,7 +5,7 @@ class Champ < ActiveRecord::Base
belongs_to :type_de_champ, inverse_of: :champ belongs_to :type_de_champ, inverse_of: :champ
has_many :commentaires has_many :commentaires
delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, to: :type_de_champ
before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' } before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' }
before_save :format_datetime, if: Proc.new { type_champ == 'datetime' } before_save :format_datetime, if: Proc.new { type_champ == 'datetime' }
@ -15,10 +15,6 @@ class Champ < ActiveRecord::Base
scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) } scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) }
scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) } scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) }
def mandatory?
mandatory
end
def public? def public?
!private? !private?
end end

View file

@ -1,4 +1,4 @@
= form.text_field :value, = form.text_field :value,
'data-address': 'true', 'data-address': 'true',
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,6 +1,6 @@
= form.label :value do = form.label :value do
#{champ.libelle} #{champ.libelle}
- if champ.mandatory - if champ.mandatory?
%span.mandatory * %span.mandatory *
- if champ.updated_at.present? - if champ.updated_at.present?

View file

@ -1,5 +1,5 @@
= form.check_box :value, = form.check_box :value,
{ required: champ.mandatory }, { required: champ.mandatory? },
'on', 'on',
'off' 'off'

View file

@ -1,4 +1,4 @@
= form.date_field :value, = form.date_field :value,
value: champ.value, value: champ.value,
placeholder: 'JJ/MM/AAAA', placeholder: 'JJ/MM/AAAA',
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.select :value, = form.select :value,
Champ.departements, Champ.departements,
required: champ.mandatory required: champ.mandatory?

View file

@ -8,7 +8,7 @@
placeholder: "Numéro de dossier", placeholder: "Numéro de dossier",
autocomplete: 'off', autocomplete: 'off',
'data-type': 'dossier-link', 'data-type': 'dossier-link',
required: champ.mandatory required: champ.mandatory?
.help-block .help-block
%p.text-info{ style: show_text_summary ? nil : 'display: none;' } %p.text-info{ style: show_text_summary ? nil : 'display: none;' }

View file

@ -2,4 +2,4 @@
= form.select :value, = form.select :value,
champ.drop_down_list.options, champ.drop_down_list.options,
disabled: champ.drop_down_list.disabled_options, disabled: champ.drop_down_list.disabled_options,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.email_field :value, = form.email_field :value,
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,5 +1,5 @@
= form.check_box :value, = form.check_box :value,
{ required: champ.mandatory }, { required: champ.mandatory? },
'on', 'on',
'off' 'off'

View file

@ -1,3 +1,3 @@
= form.number_field :value, = form.number_field :value,
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.select :value, = form.select :value,
Champ.pays, Champ.pays,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.phone_field :value, = form.phone_field :value,
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.select :value, = form.select :value,
Champ.regions, Champ.regions,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,3 +1,3 @@
= form.text_field :value, = form.text_field :value,
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory required: champ.mandatory?

View file

@ -1,5 +1,5 @@
~ form.text_area :value, ~ form.text_area :value,
row: 6, row: 6,
placeholder: champ.description, placeholder: champ.description,
required: champ.mandatory, required: champ.mandatory?,
value: html_to_string(champ.value) value: html_to_string(champ.value)