diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 431a86e94..5677ae7d5 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -16,6 +16,10 @@ class Champs::PieceJustificativeChamp < Champ "image/jpeg" ] + def main_value_name + :piece_justificative_file + end + def search_terms # We don’t know how to search inside documents yet end @@ -51,8 +55,4 @@ class Champs::PieceJustificativeChamp < Champ piece_justificative_file.service_url end end - - def html_label? - false - end end diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb index 4d5054b7e..0d4b5e5ff 100644 --- a/app/views/attachments/destroy.js.erb +++ b/app/views/attachments/destroy.js.erb @@ -1,3 +1,3 @@ <%= render_flash(timeout: 5000, sticky: true) %> -<%= remove_element("#attachment_#{@attachment_id}") %> -<%= show_element("#attachment_file_#{@attachment_id}") %> +<%= remove_element(".attachment-actions-#{@attachment_id}") %> +<%= show_element(".attachment-input-#{@attachment_id}") %> diff --git a/app/views/shared/attachment/_edit.html.haml b/app/views/shared/attachment/_edit.html.haml index 2a12e2f74..e250fd6e8 100644 --- a/app/views/shared/attachment/_edit.html.haml +++ b/app/views/shared/attachment/_edit.html.haml @@ -13,17 +13,16 @@ = link_to('le modèle suivant', url_for(template), target: '_blank', rel: 'noopener') - if persisted - .attachment-actions{ id: "attachment_#{attachment_id}" } + .attachment-actions{ class: "attachment-actions-#{attachment_id}" } .attachment-action = render partial: "shared/attachment/show", locals: { attachment: attachment, user_can_upload: true } - if user_can_destroy .attachment-action = link_to 'Supprimer', attachment_url(attachment.id, { signed_id: attachment.blob.signed_id }), remote: true, method: :delete, class: 'button small danger' .attachment-action - = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#attachment_file_#{attachment_id}" } + = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': ".attachment-input-#{attachment_id}" } = form.file_field attached_file.name, - id: "attachment_file_#{attachment_id}", - class: "attachment-input #{'hidden' if persisted}", + class: "attachment-input attachment-input-#{attachment_id} #{'hidden' if persisted}", accept: accept, direct_upload: true diff --git a/spec/features/users/brouillon_spec.rb b/spec/features/users/brouillon_spec.rb index af96dc834..9de07012e 100644 --- a/spec/features/users/brouillon_spec.rb +++ b/spec/features/users/brouillon_spec.rb @@ -167,7 +167,7 @@ feature 'The user' do fill_individual # Add an attachment - find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') + find_field('Pièce justificative').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') click_on 'Enregistrer le brouillon' expect(page).to have_content('Votre brouillon a bien été sauvegardé') expect(page).to have_text('file.pdf') @@ -182,7 +182,7 @@ feature 'The user' do # Replace the attachment within('.attachment') { click_on 'Remplacer' } - find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf') + find_field('Pièce justificative').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf') click_on 'Enregistrer le brouillon' expect(page).to have_no_text('file.pdf') expect(page).to have_text('RIB.pdf')