add grouped options for select
This commit is contained in:
parent
1fdeee16ae
commit
6925ca66e6
4 changed files with 69 additions and 3 deletions
|
@ -56,13 +56,22 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def types_of_type_de_champ
|
||||
cat_scope = "activerecord.attributes.type_de_champ.categorie"
|
||||
tdc_scope = "activerecord.attributes.type_de_champ.type_champs"
|
||||
|
||||
TypeDeChamp.type_champs
|
||||
.keys
|
||||
.filter(&method(:filter_type_champ))
|
||||
.filter(&method(:filter_featured_type_champ))
|
||||
.filter(&method(:filter_block_type_champ))
|
||||
.map { |type_champ| [t("activerecord.attributes.type_de_champ.type_champs.#{type_champ}"), type_champ] }
|
||||
.sort_by(&:first)
|
||||
.group_by { TypeDeChamp::TYPE_DE_CHAMP_TO_CATEGORIE.fetch(_1.to_sym) }
|
||||
.sort_by { |k, _v| TypeDeChamp::CATEGORIES.find_index(k) }
|
||||
.to_h do |cat, tdc|
|
||||
[
|
||||
t(cat, scope: cat_scope),
|
||||
tdc.map { [t(_1, scope: tdc_scope), _1] }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def piece_justificative_options(form)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
%span.sr-only Déplacer le champ vers le bas
|
||||
.cell.flex.justify-start.column.flex-grow
|
||||
= form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ)
|
||||
= form.select :type_champ, types_of_type_de_champ, {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
|
||||
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
|
||||
.flex.column.justify-start.flex-grow
|
||||
.cell
|
||||
.flex.align-center
|
||||
|
|
|
@ -20,6 +20,54 @@ class TypeDeChamp < ApplicationRecord
|
|||
FILE_MAX_SIZE = 200.megabytes
|
||||
FEATURE_FLAGS = {}
|
||||
|
||||
CADRE = :cadre
|
||||
STANDARD = :standard
|
||||
CHOICE = :choice
|
||||
ETAT_CIVIL = :etat_civil
|
||||
PAIEMENT_IDENTIFICATION = :paiement_identification
|
||||
REFERENTIEL_EXTERNE = :referentiel_externe
|
||||
LOCALISATION = :localisation
|
||||
|
||||
CATEGORIES = [CADRE, ETAT_CIVIL, LOCALISATION, PAIEMENT_IDENTIFICATION, STANDARD, CHOICE, REFERENTIEL_EXTERNE]
|
||||
|
||||
TYPE_DE_CHAMP_TO_CATEGORIE = {
|
||||
text: STANDARD,
|
||||
textarea: STANDARD,
|
||||
date: STANDARD,
|
||||
datetime: STANDARD,
|
||||
number: STANDARD,
|
||||
decimal_number: STANDARD,
|
||||
integer_number: STANDARD,
|
||||
checkbox: CHOICE,
|
||||
civilite: ETAT_CIVIL,
|
||||
email: ETAT_CIVIL,
|
||||
phone: ETAT_CIVIL,
|
||||
address: LOCALISATION,
|
||||
yes_no: CHOICE,
|
||||
drop_down_list: CHOICE,
|
||||
multiple_drop_down_list: CHOICE,
|
||||
linked_drop_down_list: CHOICE,
|
||||
pays: LOCALISATION,
|
||||
regions: LOCALISATION,
|
||||
departements: LOCALISATION,
|
||||
communes: LOCALISATION,
|
||||
engagement: CADRE,
|
||||
header_section: CADRE,
|
||||
explication: CADRE,
|
||||
dossier_link: CADRE,
|
||||
piece_justificative: STANDARD,
|
||||
siret: PAIEMENT_IDENTIFICATION,
|
||||
carte: REFERENTIEL_EXTERNE,
|
||||
repetition: CADRE,
|
||||
titre_identite: ETAT_CIVIL,
|
||||
iban: PAIEMENT_IDENTIFICATION,
|
||||
annuaire_education: REFERENTIEL_EXTERNE,
|
||||
cnaf: REFERENTIEL_EXTERNE,
|
||||
dgfip: REFERENTIEL_EXTERNE,
|
||||
pole_emploi: REFERENTIEL_EXTERNE,
|
||||
mesri: REFERENTIEL_EXTERNE
|
||||
}
|
||||
|
||||
enum type_champs: {
|
||||
text: 'text',
|
||||
textarea: 'textarea',
|
||||
|
|
|
@ -4,6 +4,15 @@ fr:
|
|||
type_de_champ: 'Type de champ'
|
||||
attributes:
|
||||
type_de_champ:
|
||||
categorie:
|
||||
standard: 'Standard'
|
||||
choice: 'Choix'
|
||||
etat_civil: 'État civil'
|
||||
cadre: 'Cadre'
|
||||
file: 'Fichier'
|
||||
paiement_identification: 'Paiement - Identification'
|
||||
referentiel_externe: 'Référentiel externe'
|
||||
localisation: 'Localisation'
|
||||
type_champs:
|
||||
text: 'Texte'
|
||||
textarea: 'Zone de texte'
|
||||
|
|
Loading…
Add table
Reference in a new issue