Form: use rails form helper
This commit is contained in:
parent
c4234744cd
commit
74c71a3776
22 changed files with 92 additions and 122 deletions
|
@ -32,19 +32,19 @@ class RootController < ApplicationController
|
|||
end
|
||||
|
||||
def patron
|
||||
@all_champs = TypeDeChamp.type_champs
|
||||
all_champs = TypeDeChamp.type_champs
|
||||
.map { |name, _| TypeDeChamp.new(type_champ: name, libelle: name, mandatory: true) }
|
||||
.map { |type_de_champ| Champ.new(type_de_champ: type_de_champ) }
|
||||
.map { |type_de_champ| ChampPublic.new(type_de_champ: type_de_champ) }
|
||||
.map.with_index do |champ, i|
|
||||
champ.id = i
|
||||
champ
|
||||
end
|
||||
|
||||
@all_champs
|
||||
all_champs
|
||||
.select { |champ| champ.type_champ == 'header_section' }
|
||||
.each { |champ| champ.type_de_champ.libelle = 'un super titre de section' }
|
||||
|
||||
@all_champs
|
||||
all_champs
|
||||
.select { |champ| %w(drop_down_list multiple_drop_down_list).include?(champ.type_champ) }
|
||||
.each do |champ|
|
||||
champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ)
|
||||
|
@ -64,9 +64,11 @@ option C"
|
|||
}
|
||||
|
||||
type_champ_values.each do |(type_champ, value)|
|
||||
@all_champs
|
||||
all_champs
|
||||
.select { |champ| champ.type_champ == type_champ.to_s }
|
||||
.each { |champ| champ.value = value }
|
||||
end
|
||||
|
||||
@dossier = Dossier.new(champs: all_champs)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,6 +43,8 @@ class Dossier < ActiveRecord::Base
|
|||
belongs_to :procedure
|
||||
belongs_to :user
|
||||
|
||||
accepts_nested_attributes_for :champs
|
||||
|
||||
default_scope { where(hidden_at: nil) }
|
||||
scope :state_brouillon, -> { where(state: BROUILLON) }
|
||||
scope :state_not_brouillon, -> { where.not(state: BROUILLON) }
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'text',
|
||||
= form.text_field :value,
|
||||
'data-address': 'true',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
placeholder: champ.libelle,
|
||||
value: champ.value,
|
||||
required: champ.mandatory }
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1 +1 @@
|
|||
%label{ for: :"champs_#{champ.id}" }> #{champ.libelle} #{champ.mandatory ? '*' : nil}
|
||||
= form.label :value, "#{champ.libelle} #{champ.mandatory ? '*' : nil}"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'checkbox',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
checked: ('checked' if champ.value == 'on'),
|
||||
required: champ.mandatory }
|
||||
= form.check_box :value,
|
||||
{ required: champ.mandatory },
|
||||
'on',
|
||||
'off'
|
||||
|
||||
%br
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%div
|
||||
%label
|
||||
= radio_button_tag "champs['#{champ.id}']", "M.", champ.value == 'Mme' ? false : true
|
||||
= form.radio_button :value, 'M.'
|
||||
Monsieur
|
||||
|
||||
%label
|
||||
= radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme'
|
||||
= form.radio_button :value, 'Mme.'
|
||||
Madame
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ name: "champs['#{champ.id}']",
|
||||
placeholder: "JJ/MM/AAAA",
|
||||
id: "champs_#{champ.id}",
|
||||
= form.date_field :value,
|
||||
value: champ.value,
|
||||
type: "date",
|
||||
required: champ.mandatory }
|
||||
placeholder: 'JJ/MM/AAAA',
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,22 +1,6 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
- parsed_value = champ.value.present? ? DateTime.parse(champ.value) : DateTime.now
|
||||
|
||||
.datetime
|
||||
%input{ name: "champs['#{champ.id}']",
|
||||
placeholder: champ.libelle,
|
||||
id: "champs_#{champ.id}",
|
||||
value: (champ.value.split(/[ ][0-9]*:[0-9]*/).first unless champ.value.nil?),
|
||||
type: 'date',
|
||||
required: champ.mandatory }
|
||||
|
||||
%select{ name: "time_hour['#{champ.id}']", id: "time_hour_#{champ.id}", required: champ.mandatory }
|
||||
- (0..23).each do |num|
|
||||
- num = "%.2i" %num
|
||||
%option{ value: num, selected: (:selected if champ.same_hour?(num)) }
|
||||
= num
|
||||
h
|
||||
%select{ name: "time_minute['#{champ.id}']", id: "time_minute_#{champ.id}", required: champ.mandatory }
|
||||
- (0..55).step(5) do |num|
|
||||
- num = "%.2i" %num
|
||||
%option{ value: num, selected: (:selected if champ.same_minute?(num)) }
|
||||
= num
|
||||
min
|
||||
= form.datetime_select(:value, selected: parsed_value, start_year: 1950, end_year: 2100, minute_step: 5)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
= select_tag("champs['#{champ.id}']",
|
||||
options_for_select(Champ.departements, selected: champ.value))
|
||||
= form.select :value,
|
||||
Champ.departements,
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
- dossier = Dossier.find_by(id: champ.value)
|
||||
- show_text_summary = dossier.present?
|
||||
|
@ -6,14 +6,11 @@
|
|||
- text_summary = dossier.try(:text_summary)
|
||||
|
||||
.dossier-link
|
||||
%input{ name: "champs['#{ champ.id }']",
|
||||
= form.number_field :value,
|
||||
placeholder: "Numéro de dossier",
|
||||
id: "champs_#{ champ.id }",
|
||||
value: champ.value,
|
||||
type: 'number',
|
||||
'autocomplete' => 'off',
|
||||
'data-type' => 'dossier-link',
|
||||
required: champ.mandatory }
|
||||
autocomplete: 'off',
|
||||
'data-type': 'dossier-link',
|
||||
required: champ.mandatory
|
||||
|
||||
.help-block
|
||||
%p.text-info{ style: show_text_summary ? nil : 'display: none;' }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
- if champ.drop_down_list && champ.drop_down_list.options.any?
|
||||
= select_tag("champs['#{champ.id}']",
|
||||
options_for_select(champ.drop_down_list.options,
|
||||
selected: champ.drop_down_list.selected_options_without_decorator(champ),
|
||||
disabled: champ.drop_down_list.disabled_options),
|
||||
multiple: false)
|
||||
= form.select :value,
|
||||
champ.drop_down_list.options,
|
||||
disabled: champ.drop_down_list.disabled_options,
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'email',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
= form.email_field :value,
|
||||
placeholder: champ.libelle,
|
||||
value: champ.value,
|
||||
required: champ.mandatory }
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'checkbox',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
checked: ('checked' if champ.value == 'on'),
|
||||
required: champ.mandatory }
|
||||
= form.check_box :value,
|
||||
{ required: champ.mandatory },
|
||||
'on',
|
||||
'off'
|
||||
|
||||
%br
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
- if champ.drop_down_list && champ.drop_down_list.options.any?
|
||||
= select_tag("champs['#{champ.id}']",
|
||||
options_for_select(champ.drop_down_list.options,
|
||||
selected: champ.drop_down_list.selected_options_without_decorator(champ),
|
||||
disabled: champ.drop_down_list.disabled_options),
|
||||
= form.select :value,
|
||||
champ.drop_down_list.options,
|
||||
{ selected: champ.drop_down_list.selected_options_without_decorator(champ),
|
||||
disabled: champ.drop_down_list.disabled_options },
|
||||
multiple: true,
|
||||
class: 'select2')
|
||||
class: 'select2'
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'number',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
= form.number_field :value,
|
||||
placeholder: champ.libelle,
|
||||
value: champ.value,
|
||||
required: champ.mandatory }
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
= select_tag("champs['#{champ.id}']",
|
||||
options_for_select(Champ.pays, selected: champ.value))
|
||||
= form.select :value,
|
||||
Champ.pays,
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'tel',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
= form.phone_field :value,
|
||||
placeholder: champ.libelle,
|
||||
value: champ.value,
|
||||
required: champ.mandatory }
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
= select_tag("champs['#{champ.id}']",
|
||||
options_for_select(Champ.regions, selected: champ.value))
|
||||
= form.select :value,
|
||||
Champ.regions,
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%input{ type: 'text',
|
||||
name: "champs['#{champ.id}']",
|
||||
id: "champs_#{champ.id}",
|
||||
= form.text_field :value,
|
||||
placeholder: champ.libelle,
|
||||
value: champ.value,
|
||||
required: champ.mandatory }
|
||||
required: champ.mandatory
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%textarea{ name: "champs['#{champ.id}']",
|
||||
= form.text_area :value,
|
||||
row: 6,
|
||||
placeholder: champ.description,
|
||||
id: "champs_#{champ.id}",
|
||||
row: '6',
|
||||
required: champ.mandatory }
|
||||
= sanitize(champ.value)
|
||||
required: champ.mandatory,
|
||||
value: sanitize(champ.value)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
|
||||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
%div
|
||||
%label
|
||||
= radio_button_tag "champs['#{champ.id}']", "true", champ.value == 'true'
|
||||
= form.radio_button :value, true
|
||||
Oui
|
||||
|
||||
%label
|
||||
= radio_button_tag "champs['#{champ.id}']", "false", champ.value == 'false'
|
||||
= form.radio_button :value, false
|
||||
Non
|
||||
|
|
|
@ -11,12 +11,16 @@
|
|||
%h1 Formulaires
|
||||
|
||||
%form.form
|
||||
- @all_champs.each do |champ|
|
||||
= render partial: "new_gestionnaire/dossiers/champs/#{champ.type_champ}", locals: { champ: champ }
|
||||
%input{ type: "password", value: "12345678" }
|
||||
.send-wrapper
|
||||
%input.button.send{ type: "submit", value: "Enregistrer un brouillon (formnovalidate)", formnovalidate: true }
|
||||
%input.button.send{ type: "submit", value: "Envoyer" }
|
||||
= form_for @dossier, url: '', html: { class: 'form' } do |f|
|
||||
= f.fields_for :champs do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "new_gestionnaire/dossiers/champs/#{champ.type_champ}",
|
||||
locals: { champ: champ, form: champ_form }
|
||||
|
||||
%input{ type: "password", value: "12345678" }
|
||||
.send-wrapper
|
||||
= f.submit 'Enregistrer un brouillon (formnovalidate)', formnovalidate: true, class: 'button send'
|
||||
= f.submit 'Envoyer', class: 'button send'
|
||||
|
||||
%h1 Boutons
|
||||
|
||||
|
|
Loading…
Reference in a new issue