2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2023-01-19 09:43:19 +01:00
|
|
|
|
class EditableChamp::EpciComponent < EditableChamp::EditableChampBaseComponent
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
2023-08-21 16:18:31 +02:00
|
|
|
|
def dsfr_champ_container
|
|
|
|
|
:fieldset
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-19 09:43:19 +01:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def departement_options
|
2023-10-23 10:31:52 +02:00
|
|
|
|
APIGeoService.departements.filter(&method(:departement_with_epci?)).map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
2023-01-19 09:43:19 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def epci_options
|
|
|
|
|
if @champ.departement?
|
|
|
|
|
APIGeoService.epcis(@champ.code_departement).map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
|
|
|
|
else
|
|
|
|
|
[]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def departement_select_options
|
|
|
|
|
{ selected: @champ.code_departement }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def epci_select_options
|
|
|
|
|
{ selected: @champ.code }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
|
|
|
|
|
end
|
2023-10-23 10:31:52 +02:00
|
|
|
|
|
|
|
|
|
def departement_with_epci?(departement)
|
|
|
|
|
code = departement[:code]
|
|
|
|
|
!code.start_with?('98') && !code.in?(['99', '975', '977', '978'])
|
|
|
|
|
end
|
2023-01-19 09:43:19 +01:00
|
|
|
|
end
|