%table.table
  - dossier.types_de_piece_justificative.order('order_place ASC').each do |tpj|
    %tr
      %th.piece-libelle
        = tpj.mandatory ? tpj.libelle + ' *' : tpj.libelle
        %br
        .piece-description= tpj.description

      %td
        - if tpj.lien_demarche.present?
          %em
            Récupérer le formulaire vierge pour mon dossier :
            = link_to "Télécharger", tpj.lien_demarche, target: :blank

      %td
        - if tpj.api_entreprise
          %span.text-success{ id: "piece_justificative_#{tpj.id}" } Nous l'avons récupéré pour vous.
        - else
          - if !dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id)
            = file_field_tag "piece_justificative_#{tpj.id}", accept:  PieceJustificative.accept_format, :max_file_size => 6.megabytes
          - else
            - pj = dossier.retrieve_last_piece_justificative_by_type(tpj.id)
            %a{ href: pj.content_url, target: '_blank' }
              = pj.original_filename
            %span.btn.btn-sm.btn-file.btn-success
              Modifier
              = file_field_tag "piece_justificative_#{tpj.id}", accept:  PieceJustificative.accept_format, :max_file_size => 6.megabytes
