2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-01-04 13:09:14 +01:00
|
|
|
module ChampConditionalConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def conditional?
|
|
|
|
type_de_champ.read_attribute_before_type_cast('condition').present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def dependent_conditions?
|
|
|
|
dossier.revision.dependent_conditions(type_de_champ).any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def visible?
|
|
|
|
# Huge gain perf for cascade conditions
|
|
|
|
return @visible if instance_variable_defined? :@visible
|
|
|
|
|
|
|
|
@visible = if conditional?
|
|
|
|
type_de_champ.condition.compute(champs_for_condition)
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-05 17:33:03 +02:00
|
|
|
def reset_visible # recompute after a dossier update
|
|
|
|
remove_instance_variable :@visible if instance_variable_defined? :@visible
|
|
|
|
end
|
|
|
|
|
2023-01-04 13:09:14 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def champs_for_condition
|
|
|
|
dossier.champs.filter { _1.row_id.nil? || _1.row_id == row_id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|