From 1ecdf5f5440ba949574e9c931003c32d554a7fef Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Mon, 19 Dec 2022 16:13:59 +0100 Subject: [PATCH] remove manipulating checkbox with JS and set just one form instead of 2 --- .../batch_operation_component.html.haml | 11 +++++------ .../controllers/batch_operation_controller.ts | 5 ----- app/views/instructeurs/procedures/show.html.haml | 3 ++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/components/dossiers/batch_operation_component/batch_operation_component.html.haml b/app/components/dossiers/batch_operation_component/batch_operation_component.html.haml index 1862fd1a5..8548247a2 100644 --- a/app/components/dossiers/batch_operation_component/batch_operation_component.html.haml +++ b/app/components/dossiers/batch_operation_component/batch_operation_component.html.haml @@ -1,7 +1,7 @@ - if available_operations[:options].present? - if available_operations[:options].count == 1 - opt = available_operations[:options].dig(0) - = form_for(BatchOperation.new, url: instructeur_batch_operations_path(procedure_id: procedure.id), method: :post, html: { class: 'flex justify-end', id: "#{dom_id(BatchOperation.new)}_#{opt[:operation]}" }, data: { "batch-operation-target" => "form"}) do |form| + = form_for(BatchOperation.new, url: instructeur_batch_operations_path(procedure_id: procedure.id), method: :post, html: { class: 'flex justify-end', id: "#{dom_id(BatchOperation.new)}" }, data: { "batch-operation-target" => "form"}) do |form| = form.button opt[:label], class: ['fr-btn fr-btn--icon-left', icons[opt[:operation].to_sym]], disabled: :disabled, name: "#{form.object_name}[operation]", data: { "batch-operation-target" => "submit", "submitter-operation" => opt[:operation] } -else @@ -12,11 +12,10 @@ Actions multiples #state-menu.dropdown-content.fade-in-down{ data: { menu_button_target: 'menu' } } - - %ul.dropdown-items - - available_operations[:options].each do |opt| - %li{ 'data-turbo': 'true' } - = form_for(BatchOperation.new, url: instructeur_batch_operations_path(procedure_id: procedure.id), method: :post, html: { class: 'flex justify-end form', id: "#{dom_id(BatchOperation.new)}_#{opt[:operation]}" }, data: { "batch-operation-target" => "form"}) do |form| + = form_for(BatchOperation.new, url: instructeur_batch_operations_path(procedure_id: procedure.id), method: :post, html: { class: 'flex justify-end form', id: "#{dom_id(BatchOperation.new)}" }, data: { "batch-operation-target" => "form"}) do |form| + %ul.dropdown-items + - available_operations[:options].each do |opt| + %li{ 'data-turbo': 'true' } - if opt[:operation] == 'accepter' .wrapper %a{ href: '#', onclick: "DS.showMotivation(event, 'accept');", class: ['fr-btn--icon-left', icons[opt[:operation].to_sym]] } diff --git a/app/javascript/controllers/batch_operation_controller.ts b/app/javascript/controllers/batch_operation_controller.ts index 1950749e2..91f109ac3 100644 --- a/app/javascript/controllers/batch_operation_controller.ts +++ b/app/javascript/controllers/batch_operation_controller.ts @@ -20,11 +20,6 @@ export class BatchOperationController extends ApplicationController { const submitter = event.submitter as HTMLInputElement; submitter.setAttribute('value', submitter.dataset.submitterOperation || ''); - this.inputTargets.forEach((e) => - e.setAttribute( - 'form', - `new_batch_operation_${submitter.dataset.submitterOperation}` - )); return event; } diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index ff8078a30..5086470f5 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -69,6 +69,7 @@ - if @dossiers_count > 0 %span.dossiers-export = render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count, export_url: method(:download_export_instructeur_procedure_path)) + %hr.fr-mt-5v - if @filtered_sorted_paginated_ids.present? || @current_filters.count > 0 - batch_operation_component = Dossiers::BatchOperationComponent.new(statut: @statut, procedure: @procedure) @@ -124,7 +125,7 @@ - if p.batch_operation_id.present? = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, true, disabled: true, id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), aria: {label: t('views.instructeurs.dossiers.batch_operation.disabled')} - else - = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, false, data: { "batch-operation-target" => "input", "action" => "batch-operation#onCheckOne"}, id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), aria: {label: t('views.instructeurs.dossiers.batch_operation.enabled')} + = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, false, data: { "batch-operation-target" => "input", "action" => "batch-operation#onCheckOne"}, form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), aria: {label: t('views.instructeurs.dossiers.batch_operation.enabled')} - if @not_archived_notifications_dossier_ids.include?(p.dossier_id) %span.notifications{ 'aria-label': 'notifications' }