2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-26 22:05:26 +01:00
|
|
|
module ChampValidateConcern
|
2024-04-02 10:56:43 +02:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
protected
|
|
|
|
|
|
|
|
# Champs public/private must be validated depending on the context
|
|
|
|
def valid_champ_value?
|
|
|
|
valid?(public? ? :champs_public_value : :champs_private_value)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_champ_value?
|
|
|
|
case validation_context
|
|
|
|
when :champs_public_value
|
2024-11-26 22:05:26 +01:00
|
|
|
public? && can_validate? && visible?
|
2024-04-02 10:56:43 +02:00
|
|
|
when :champs_private_value
|
2024-11-26 22:05:26 +01:00
|
|
|
private? && can_validate? && visible?
|
2024-04-02 10:56:43 +02:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-26 22:05:26 +01:00
|
|
|
def can_validate?
|
|
|
|
in_dossier_revision? && is_same_type_as_revision? && !row? && !in_discarded_row?
|
2024-04-02 10:56:43 +02:00
|
|
|
end
|
2024-09-20 14:54:26 +02:00
|
|
|
|
2024-11-26 22:05:26 +01:00
|
|
|
def validate_champ_value_or_prefill?
|
|
|
|
validate_champ_value? || validation_context == :prefill
|
2024-09-20 14:54:26 +02:00
|
|
|
end
|
2024-04-02 10:56:43 +02:00
|
|
|
end
|
|
|
|
end
|