2018-08-14 15:17:22 +02:00
|
|
|
|
module ProcedureHelper
|
|
|
|
|
def procedure_lien(procedure)
|
2019-09-16 16:59:10 +02:00
|
|
|
|
if procedure.brouillon?
|
|
|
|
|
commencer_test_url(path: procedure.path)
|
|
|
|
|
else
|
|
|
|
|
commencer_url(path: procedure.path)
|
2018-08-14 15:17:22 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def procedure_libelle(procedure)
|
2021-04-17 18:49:00 +02:00
|
|
|
|
parts = procedure.brouillon? ? [tag.span(t('helpers.procedure.testing_procedure'), class: 'badge')] : []
|
2018-09-18 14:10:15 +02:00
|
|
|
|
parts << procedure.libelle
|
|
|
|
|
safe_join(parts, ' ')
|
2018-08-14 15:17:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-10-12 16:17:01 +02:00
|
|
|
|
def procedure_publish_label(procedure, key)
|
2021-02-02 15:48:53 +01:00
|
|
|
|
# i18n-tasks-use t('modal.publish.body.publish')
|
|
|
|
|
# i18n-tasks-use t('modal.publish.body.reopen')
|
|
|
|
|
# i18n-tasks-use t('modal.publish.submit.publish')
|
|
|
|
|
# i18n-tasks-use t('modal.publish.submit.reopen')
|
|
|
|
|
# i18n-tasks-use t('modal.publish.title.publish')
|
|
|
|
|
# i18n-tasks-use t('modal.publish.title.reopen')
|
2019-11-14 09:43:45 +01:00
|
|
|
|
action = procedure.close? ? :reopen : :publish
|
2018-08-14 15:17:22 +02:00
|
|
|
|
t(action, scope: [:modal, :publish, key])
|
|
|
|
|
end
|
2018-12-27 13:29:39 +01:00
|
|
|
|
|
2021-11-24 11:09:58 +01:00
|
|
|
|
# Returns a hash of { attribute: full_message } errors.
|
|
|
|
|
def procedure_publication_errors(procedure)
|
|
|
|
|
procedure.validate(:publication)
|
|
|
|
|
procedure.errors.to_hash(full_messages: true).except(:path)
|
|
|
|
|
end
|
|
|
|
|
|
2018-11-14 16:28:02 +01:00
|
|
|
|
def types_de_champ_data(procedure)
|
|
|
|
|
{
|
2019-03-20 14:28:13 +01:00
|
|
|
|
isAnnotation: false,
|
2020-02-20 13:25:32 +01:00
|
|
|
|
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
2022-05-20 12:27:26 +02:00
|
|
|
|
typeDeChamps: procedure.draft_revision.types_de_champ_public_as_json,
|
2020-07-07 12:03:32 +02:00
|
|
|
|
baseUrl: admin_procedure_types_de_champ_path(procedure),
|
2021-06-10 14:39:54 +02:00
|
|
|
|
directUploadUrl: rails_direct_uploads_url,
|
|
|
|
|
continuerUrl: admin_procedure_path(procedure)
|
2018-11-14 16:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def types_de_champ_private_data(procedure)
|
|
|
|
|
{
|
2019-03-20 14:28:13 +01:00
|
|
|
|
isAnnotation: true,
|
2020-02-20 13:25:32 +01:00
|
|
|
|
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
2022-05-20 12:27:26 +02:00
|
|
|
|
typeDeChamps: procedure.draft_revision.types_de_champ_private_as_json,
|
2020-07-07 12:03:32 +02:00
|
|
|
|
baseUrl: admin_procedure_types_de_champ_path(procedure),
|
2021-06-10 14:39:54 +02:00
|
|
|
|
directUploadUrl: rails_direct_uploads_url,
|
|
|
|
|
continuerUrl: admin_procedure_path(procedure)
|
2018-11-14 16:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-27 18:04:22 +02:00
|
|
|
|
def procedure_auto_archive_date(procedure)
|
2020-05-27 11:25:43 +02:00
|
|
|
|
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-27 18:04:22 +02:00
|
|
|
|
def procedure_auto_archive_time(procedure)
|
|
|
|
|
"à 23 h 59 (heure de " + Rails.application.config.time_zone + ")"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def procedure_auto_archive_datetime(procedure)
|
|
|
|
|
procedure_auto_archive_date(procedure) + ' ' + procedure_auto_archive_time(procedure)
|
|
|
|
|
end
|
2021-09-15 10:37:19 +02:00
|
|
|
|
|
|
|
|
|
def can_manage_groupe_instructeurs?(procedure)
|
2021-09-27 14:55:26 +02:00
|
|
|
|
procedure.routee? && current_administrateur&.owns?(procedure)
|
2021-09-15 10:37:19 +02:00
|
|
|
|
end
|
2021-09-23 15:03:20 +02:00
|
|
|
|
|
|
|
|
|
def can_send_groupe_message?(procedure)
|
|
|
|
|
procedure.dossiers
|
|
|
|
|
.state_brouillon
|
|
|
|
|
.includes(:groupe_instructeur)
|
|
|
|
|
.exists?(groupe_instructeur: current_instructeur.groupe_instructeurs)
|
|
|
|
|
end
|
2022-04-25 17:38:30 +02:00
|
|
|
|
|
|
|
|
|
def url_or_email_to_lien_dpo(procedure)
|
|
|
|
|
URI::MailTo.build([procedure.lien_dpo, "subject="]).to_s
|
|
|
|
|
rescue URI::InvalidComponentError
|
|
|
|
|
uri = URI.parse(procedure.lien_dpo)
|
|
|
|
|
return "//#{uri}" if uri.scheme.nil?
|
|
|
|
|
uri.to_s
|
|
|
|
|
end
|
2018-08-14 15:17:22 +02:00
|
|
|
|
end
|