Add repetition to apercu

This commit is contained in:
Paul Chavard 2019-02-07 10:44:15 +01:00
parent 0791deebab
commit a0a1ce11c8
6 changed files with 27 additions and 17 deletions

View file

@ -120,17 +120,11 @@ class Dossier < ApplicationRecord
end
def build_default_champs
procedure.types_de_champ.each do |type_de_champ|
champ = type_de_champ.champ.build
if type_de_champ.repetition?
champ.add_row
end
procedure.build_champs.each do |champ|
champs << champ
end
procedure.types_de_champ_private.each do |type_de_champ|
champs_private << type_de_champ.champ.build
procedure.build_champs_private.each do |champ|
champs_private << champ
end
end

View file

@ -138,10 +138,15 @@ class Procedure < ApplicationRecord
# Warning: dossier after_save build_default_champs must be removed
# to save a dossier created from this method
def new_dossier
champs = types_de_champ.map { |tdc| tdc.champ.build }
champs_private = types_de_champ_private.map { |tdc| tdc.champ.build }
Dossier.new(procedure: self, champs: build_champs, champs_private: build_champs_private)
end
Dossier.new(procedure: self, champs: champs, champs_private: champs_private)
def build_champs
types_de_champ.map(&:build_champ)
end
def build_champs_private
types_de_champ_private.map(&:build_champ)
end
def default_path

View file

@ -120,6 +120,10 @@ class TypeDeChamp < ApplicationRecord
}
end
def build_champ
dynamic_type.build_champ
end
def self.type_de_champs_list_fr
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
end

View file

@ -1,2 +1,7 @@
class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
def build_champ
champ = super
champ.add_row
champ
end
end

View file

@ -19,4 +19,8 @@ class TypesDeChamp::TypeDeChampBase
}
]
end
def build_champ
@type_de_champ.champ.build
end
end

View file

@ -5,11 +5,9 @@
= form.fields_for :champs, champ do |form|
= render partial: 'shared/dossiers/editable_champs/editable_champ', locals: { champ: form.object, form: form }
= form.hidden_field :_destroy, disabled: true
%button.button.danger.remove-row
Supprimer
- if champ.persisted?
%button.button.danger.remove-row
Supprimer
- if champ.persisted?
= link_to "Ajouter une ligne pour « #{champ.libelle} »", champs_repetition_path(form.index), class: 'button add-row', data: { remote: true, method: 'POST', params: { champ_id: champ&.id }.to_query }
- else
%button.button.add-row{ disabled: true }
= "Ajouter une ligne pour « #{champ.libelle} »"