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
|
2017-12-14 16:23:15 +01:00
|
|
|
|
end
|