2017-12-14 16:23:15 +01:00
|
|
|
|
module ChampHelper
|
2018-06-18 11:30:26 +02:00
|
|
|
|
def has_label?(champ)
|
2018-08-28 16:22:34 +02:00
|
|
|
|
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
|
2018-06-18 11:30:26 +02:00
|
|
|
|
!types_without_label.include?(champ.type_champ)
|
2017-12-14 16:23:15 +01:00
|
|
|
|
end
|
2018-10-17 12:07:25 +02:00
|
|
|
|
|
2019-02-19 16:14:42 +01:00
|
|
|
|
def champ_carte_params(champ)
|
|
|
|
|
if champ.persisted?
|
|
|
|
|
{ champ_id: champ.id }
|
|
|
|
|
else
|
|
|
|
|
{ type_de_champ_id: champ.type_de_champ_id }
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-09-26 17:40:52 +02:00
|
|
|
|
|
|
|
|
|
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
|
2019-11-20 20:47:36 +01:00
|
|
|
|
|
2022-05-07 17:49:27 +02:00
|
|
|
|
def auto_attach_url(object)
|
|
|
|
|
if object.is_a?(Champ)
|
2020-04-02 17:30:59 +02:00
|
|
|
|
champs_piece_justificative_url(object.id)
|
2022-08-11 14:01:26 +02:00
|
|
|
|
elsif object.is_a?(TypeDeChamp)
|
|
|
|
|
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id)
|
2020-03-30 15:34:56 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-09 17:32:20 +02:00
|
|
|
|
|
2022-05-07 17:49:27 +02:00
|
|
|
|
def autosave_available?(champ)
|
|
|
|
|
# FIXME: enable autosave on champs private? once we figured out how to batch audit events
|
2022-07-28 11:47:55 +02:00
|
|
|
|
champ.dossier.brouillon? && !champ.repetition?
|
2022-05-07 17:49:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-07-21 17:59:20 +02:00
|
|
|
|
def editable_champ_controller(champ)
|
|
|
|
|
if !champ.repetition? && !champ.non_fillable?
|
|
|
|
|
# This is an editable champ. Lets find what controllers it might need.
|
|
|
|
|
controllers = []
|
|
|
|
|
|
|
|
|
|
# This is a public champ – it can have an autosave controller.
|
|
|
|
|
if champ.public?
|
|
|
|
|
# This is a champ on dossier in draft state. Activate autosave.
|
2022-07-28 11:47:55 +02:00
|
|
|
|
if champ.dossier.brouillon?
|
2022-07-21 17:59:20 +02:00
|
|
|
|
controllers << 'autosave'
|
|
|
|
|
# This is a champ on a dossier in en_construction state. Enable conditions checker.
|
2022-07-28 11:47:55 +02:00
|
|
|
|
elsif champ.public? && champ.dossier.en_construction?
|
2022-07-21 17:59:20 +02:00
|
|
|
|
controllers << 'check-conditions'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# This is a dropdown champ. Activate special behaviours it might have.
|
|
|
|
|
if champ.simple_drop_down_list? || champ.linked_drop_down_list?
|
|
|
|
|
controllers << 'champ-dropdown'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if controllers.present?
|
|
|
|
|
{ controller: controllers.join(' ') }
|
|
|
|
|
end
|
2022-07-12 18:32:16 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
def geo_area_label(geo_area)
|
|
|
|
|
case geo_area.source
|
|
|
|
|
when GeoArea.sources.fetch(:cadastre)
|
2022-07-13 11:18:05 +02:00
|
|
|
|
safe_join ["Parcelle n° #{geo_area.numero} - Feuille #{geo_area.prefixe} #{geo_area.section} - #{geo_area.surface.round} m", tag.sup("2")]
|
2020-04-15 15:43:38 +02:00
|
|
|
|
when GeoArea.sources.fetch(:selection_utilisateur)
|
|
|
|
|
if geo_area.polygon?
|
2020-09-20 13:18:36 +02:00
|
|
|
|
if geo_area.area.present?
|
2022-07-13 11:18:05 +02:00
|
|
|
|
safe_join ["Une aire de surface #{geo_area.area} m", tag.sup("2")]
|
2020-09-20 13:18:36 +02:00
|
|
|
|
else
|
|
|
|
|
"Une aire de surface inconnue"
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|
|
|
|
|
elsif geo_area.line?
|
2020-09-20 13:18:36 +02:00
|
|
|
|
if geo_area.length.present?
|
|
|
|
|
"Une ligne longue de #{geo_area.length} m"
|
|
|
|
|
else
|
|
|
|
|
"Une ligne de longueur inconnue"
|
|
|
|
|
end
|
2020-04-15 15:43:38 +02:00
|
|
|
|
elsif geo_area.point?
|
|
|
|
|
"Un point situé à #{geo_area.location}"
|
|
|
|
|
end
|
2020-04-09 17:32:20 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-14 16:23:15 +01:00
|
|
|
|
end
|