add motivation field to batch operation accepter
This commit is contained in:
parent
d7ebb67889
commit
1bc0609543
5 changed files with 29 additions and 5 deletions
|
@ -16,5 +16,18 @@
|
||||||
%ul.dropdown-items
|
%ul.dropdown-items
|
||||||
- available_operations[:options].each do |opt|
|
- available_operations[:options].each do |opt|
|
||||||
%li{ 'data-turbo': 'true' }
|
%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_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.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]}
|
- 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]}
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Instructeurs
|
||||||
|
|
||||||
def batch_operation_params
|
def batch_operation_params
|
||||||
params.require(:batch_operation)
|
params.require(:batch_operation)
|
||||||
.permit(:operation, dossier_ids: [])
|
.permit(:operation, :motivation, dossier_ids: [])
|
||||||
.merge(instructeur: current_instructeur)
|
.merge(instructeur: current_instructeur)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ class BatchOperation < ApplicationRecord
|
||||||
has_many :groupe_instructeurs, through: :dossier_operations
|
has_many :groupe_instructeurs, through: :dossier_operations
|
||||||
belongs_to :instructeur
|
belongs_to :instructeur
|
||||||
|
|
||||||
|
store_accessor :payload, :motivation
|
||||||
|
|
||||||
validates :operation, presence: true
|
validates :operation, presence: true
|
||||||
|
|
||||||
before_create :build_operations
|
before_create :build_operations
|
||||||
|
@ -71,7 +73,7 @@ class BatchOperation < ApplicationRecord
|
||||||
when BatchOperation.operations.fetch(:passer_en_instruction)
|
when BatchOperation.operations.fetch(:passer_en_instruction)
|
||||||
dossier.passer_en_instruction(instructeur: instructeur)
|
dossier.passer_en_instruction(instructeur: instructeur)
|
||||||
when BatchOperation.operations.fetch(:accepter)
|
when BatchOperation.operations.fetch(:accepter)
|
||||||
dossier.accepter(instructeur: instructeur)
|
dossier.accepter(instructeur: instructeur, motivation: motivation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
|
||||||
context 'statut suivis' do
|
context 'statut suivis' do
|
||||||
let(:statut) { 'suivis' }
|
let(:statut) { 'suivis' }
|
||||||
it { is_expected.to have_button('Actions multiples', disabled: true) }
|
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
|
end
|
||||||
|
|
||||||
context 'statut tous' do
|
context 'statut tous' do
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe BatchOperationProcessOneJob, type: :job do
|
||||||
context 'when operation is "accepter"' do
|
context 'when operation is "accepter"' do
|
||||||
let(:batch_operation) do
|
let(:batch_operation) do
|
||||||
create(:batch_operation, :accepter,
|
create(:batch_operation, :accepter,
|
||||||
options.merge(instructeur: create(:instructeur)))
|
options.merge(instructeur: create(:instructeur), motivation: 'motivation'))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts the dossier in the batch' do
|
it 'accepts the dossier in the batch' do
|
||||||
|
@ -58,6 +58,13 @@ describe BatchOperationProcessOneJob, type: :job do
|
||||||
.from(false)
|
.from(false)
|
||||||
.to(true)
|
.to(true)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do
|
context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue