demarches-normaliennes/app/models/champs/repetition_champ.rb

34 lines
705 B
Ruby
Raw Normal View History

class Champs::RepetitionChamp < Champ
before_save :setup_dossier
has_many :champs, -> { ordered }, foreign_key: :parent_id, dependent: :destroy
accepts_nested_attributes_for :champs, allow_destroy: true
def rows
champs.group_by(&:row).values
end
2019-01-30 16:14:15 +01:00
def add_row(row = 0)
type_de_champ.types_de_champ.each do |type_de_champ|
self.champs << type_de_champ.champ.build(row: row)
end
end
def mandatory_and_blank?
mandatory? && champs.empty?
end
def search_terms
# The user cannot enter any information here so it doesnt make much sense to search
end
2019-01-30 16:14:15 +01:00
private
def setup_dossier
champs.each do |champ|
champ.dossier = dossier
end
end
end