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 78ef660da..34fcd4ae2 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 @@ -16,5 +16,18 @@ %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', id: "#{dom_id(BatchOperation.new)}_#{opt[:operation]}" }, data: { "batch-operation-target" => "form"}) do |form| - = form.button opt[:label], class: ['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]} + = 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| + - if opt[:operation] == 'accepter' + .wrapper + %a{ href: '#', onclick: "DS.showMotivation(event, 'accept');", class: ['fr-btn--icon-left', icons[opt[:operation].to_sym]] } + = opt[:label] + + .motivation.hidden{ class: 'accept' } + = form.text_area :motivation, class: 'motivation-text-area' + + .text-right + %span{ onclick: 'DS.motivationCancel();', class: 'fr-btn fr-btn--secondary' } Annuler + + = form.button "Valider la décision", class: ['fr-btn'], disabled: :disabled, name: "#{form.object_name}[operation]", data: { "batch-operation-target" => "submit", "submitter-operation" => opt[:operation]} + - else + = form.button opt[:label], class: ['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]} diff --git a/app/controllers/instructeurs/batch_operations_controller.rb b/app/controllers/instructeurs/batch_operations_controller.rb index 554c43d84..2a55050f1 100644 --- a/app/controllers/instructeurs/batch_operations_controller.rb +++ b/app/controllers/instructeurs/batch_operations_controller.rb @@ -13,7 +13,7 @@ module Instructeurs def batch_operation_params params.require(:batch_operation) - .permit(:operation, dossier_ids: []) + .permit(:operation, :motivation, dossier_ids: []) .merge(instructeur: current_instructeur) end diff --git a/app/models/batch_operation.rb b/app/models/batch_operation.rb index 2f3621e5f..f839b1c56 100644 --- a/app/models/batch_operation.rb +++ b/app/models/batch_operation.rb @@ -27,6 +27,8 @@ class BatchOperation < ApplicationRecord has_many :groupe_instructeurs, through: :dossier_operations belongs_to :instructeur + store_accessor :payload, :motivation + validates :operation, presence: true before_create :build_operations @@ -71,7 +73,7 @@ class BatchOperation < ApplicationRecord when BatchOperation.operations.fetch(:passer_en_instruction) dossier.passer_en_instruction(instructeur: instructeur) when BatchOperation.operations.fetch(:accepter) - dossier.accepter(instructeur: instructeur) + dossier.accepter(instructeur: instructeur, motivation: motivation) end end diff --git a/spec/components/dossiers/batch_operation_component_spec.rb b/spec/components/dossiers/batch_operation_component_spec.rb index 4547fbc01..c7633f86b 100644 --- a/spec/components/dossiers/batch_operation_component_spec.rb +++ b/spec/components/dossiers/batch_operation_component_spec.rb @@ -21,6 +21,8 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do context 'statut suivis' do let(:statut) { 'suivis' } it { is_expected.to have_button('Actions multiples', disabled: true) } + it { is_expected.to have_button('Passer en instruction les dossiers sélectionnés', disabled: true) } + it { is_expected.to have_link('Accepter les dossiers sélectionnés') } end context 'statut tous' do diff --git a/spec/jobs/batch_operation_process_one_job_spec.rb b/spec/jobs/batch_operation_process_one_job_spec.rb index b0616d032..6b8b44896 100644 --- a/spec/jobs/batch_operation_process_one_job_spec.rb +++ b/spec/jobs/batch_operation_process_one_job_spec.rb @@ -49,7 +49,7 @@ describe BatchOperationProcessOneJob, type: :job do context 'when operation is "accepter"' do let(:batch_operation) do create(:batch_operation, :accepter, - options.merge(instructeur: create(:instructeur))) + options.merge(instructeur: create(:instructeur), motivation: 'motivation')) end it 'accepts the dossier in the batch' do @@ -58,6 +58,13 @@ describe BatchOperationProcessOneJob, type: :job do .from(false) .to(true) end + + it 'accepts the dossier in the batch with a motivation' do + expect { subject.perform_now } + .to change { dossier_job.reload.motivation } + .from(nil) + .to('motivation') + end end context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do