demarches-normaliennes/app/helpers/champ_helper.rb
Pierre de La Morinerie ded65cfdb9 dossier: fix rendering of piece_justificative in repetition
In repetitions we can't render the piece_justificative champ in the way
we do for normal champs (which was already a bit hackish).

Instead we render the whole form partial – and then extract the champ
from the form. In this way, we're sure to render the champ as it
appears in the form, without any hacks to reproduce the form structure.
2020-04-06 11:50:31 +02:00

40 lines
1.1 KiB
Ruby

module ChampHelper
def has_label?(champ)
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
!types_without_label.include?(champ.type_champ)
end
def geo_data(champ)
# rubocop:disable Rails/OutputSafety
raw(champ.to_render_data.to_json)
# rubocop:enable Rails/OutputSafety
end
def champ_carte_params(champ)
if champ.persisted?
{ champ_id: champ.id }
else
{ type_de_champ_id: champ.type_de_champ_id }
end
end
def format_text_value(text)
sanitized_text = sanitize(text)
auto_linked_text = Anchored::Linker.auto_link(sanitized_text, target: '_blank', rel: 'noopener') do |link_href|
truncate(link_href, length: 60)
end
simple_format(auto_linked_text, {}, sanitize: false)
end
def describedby_id(champ)
if champ.description.present?
"desc-#{champ.type_de_champ.id}-#{champ.row}"
end
end
def auto_attach_url(form, object)
if feature_enabled?(:autoupload_dossier_attachments) && object.is_a?(Champ) && object.persisted? && object.public?
champs_piece_justificative_url(object.id)
end
end
end