Do not reload page when instructeur change dossier state

fix #2425
This commit is contained in:
Paul Chavard 2018-09-13 17:13:09 +02:00
parent 467268f4dd
commit 44511acfed
8 changed files with 61 additions and 40 deletions

View file

@ -77,14 +77,14 @@ module NewGestionnaire
current_gestionnaire.follow(dossier)
flash.notice = 'Dossier passé en instruction.'
redirect_to gestionnaire_dossier_path(procedure, dossier)
render partial: 'state_button_refresh', locals: { dossier: dossier }
end
def repasser_en_construction
dossier.en_construction!
flash.notice = 'Dossier repassé en construction.'
redirect_to gestionnaire_dossier_path(procedure, dossier)
render partial: 'state_button_refresh', locals: { dossier: dossier }
end
def terminer
@ -113,7 +113,7 @@ module NewGestionnaire
NotificationMailer.send_closed_notification(dossier).deliver_later
end
redirect_to gestionnaire_dossier_path(procedure, dossier)
render partial: 'state_button_refresh', locals: { dossier: dossier }
end
def create_commentaire

View file

@ -1,6 +1,7 @@
import $ from 'jquery';
export function showMotivation(state) {
export function showMotivation(event, state) {
event.preventDefault();
$(`.motivation.${state}`).show();
$('.dropdown-items').hide();
}

View file

@ -17,7 +17,8 @@
= link_to "Uniquement cet onglet", "#", onclick: "window.print()", class: "menu-item menu-link"
= render partial: "new_gestionnaire/procedures/dossier_actions", locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: current_gestionnaire&.follow?(dossier) }
= render partial: "state_button", locals: { dossier: dossier }
%span.state-button
= render partial: "state_button", locals: { dossier: dossier }
%ul.tabs
- notifications_summary = current_gestionnaire.notifications_for_dossier(dossier)

View file

@ -11,7 +11,7 @@
%h4 En construction
Vous permettez à l'usager de modifier ses réponses au formulaire
%li
= link_to passer_en_instruction_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do
= link_to passer_en_instruction_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, data: { remote: true, confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do
%span.icon.in-progress
.description
%h4 Passer en instruction
@ -19,7 +19,7 @@
- if dossier.en_instruction?
%li
= link_to repasser_en_construction_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en construction de ce dossier ?" } do
= link_to repasser_en_construction_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, data: { remote:true, confirm: "Confirmer vous le passage en construction de ce dossier ?" } do
%span.icon.edit
.description
%h4 Repasser en construction
@ -29,21 +29,24 @@
.description
%h4 En instruction
L'usager ne peut modifier son dossier pendant l'instruction
%li{ onclick: "DS.showMotivation('accept');" }
%span.icon.accept
.description
%h4 Accepter
L'usager sera notifié que son dossier a été accepté
%li{ onclick: "DS.showMotivation('without-continuation');" }
%span.icon.without-continuation
.description
%h4 Classer sans suite
L'usager sera notifié que son dossier a été classé sans suite
%li{ onclick: "DS.showMotivation('refuse');" }
%span.icon.refuse
.description
%h4 Refuser
L'usager sera notifié que son dossier a été refusé
%li
%a{ href: '#', onclick: "DS.showMotivation(event, 'accept');" }
%span.icon.accept
.description
%h4 Accepter
L'usager sera notifié que son dossier a été accepté
%li
%a{ href: '#', onclick: "DS.showMotivation(event, 'without-continuation');" }
%span.icon.without-continuation
.description
%h4 Classer sans suite
L'usager sera notifié que son dossier a été classé sans suite
%li
%a{ href: '#', onclick: "DS.showMotivation(event, 'refuse');" }
%span.icon.refuse
.description
%h4 Refuser
L'usager sera notifié que son dossier a été refusé
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Accepter le dossier', popup_class: 'accept', process_action: 'accepter', title: 'Accepter', confirm: "Confirmez-vous l'acceptation ce dossier ?" }
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Classer le dossier sans suite', popup_class: 'without-continuation', process_action: 'classer_sans_suite', title: 'Classer sans suite', confirm: 'Confirmez-vous le classement sans suite de ce dossier ?' }
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Refuser le dossier', popup_class: 'refuse', process_action: 'refuser', title: 'Refuser', confirm: 'Confirmez-vous le refus de ce dossier ?' }

View file

@ -3,7 +3,7 @@
%span.icon{ class: popup_class }
#{popup_title}
= form_tag(terminer_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, class: 'form') do
= form_tag(terminer_gestionnaire_dossier_path(dossier.procedure, dossier), remote: true, method: :post, class: 'form') do
- if title == 'Accepter'
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)', required: false
%p.help

View file

@ -0,0 +1,2 @@
<%= render_flash %>
<%= render_to_element('.state-button', partial: "state_button", locals: { dossier: dossier }) %>

View file

@ -107,12 +107,12 @@ describe NewGestionnaire::DossiersController, type: :controller do
before do
dossier.en_construction!
sign_in gestionnaire
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js'
dossier.reload
end
it { expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) }
it { is_expected.to redirect_to gestionnaire_dossier_path(procedure, dossier) }
it { expect(response.body).to include('.state-button') }
it { expect(gestionnaire.follow?(dossier)).to be true }
end
@ -122,7 +122,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire
end
subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
it 'change state to en_construction' do
subject
@ -131,7 +131,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
expect(dossier.state).to eq(Dossier.states.fetch(:en_construction))
end
it { is_expected.to redirect_to gestionnaire_dossier_path(procedure, dossier) }
it { expect(subject.body).to include('.state-button') }
end
describe '#terminer' do
@ -141,7 +141,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire
end
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id } }
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
it 'change state to refuse' do
subject
@ -158,7 +158,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
subject
end
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) }
it { expect(subject.body).to include('.state-button') }
end
context "with classer_sans_suite" do
@ -167,7 +167,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire
end
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id } }
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
it 'change state to sans_suite' do
subject
@ -184,7 +184,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
subject
end
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) }
it { expect(subject.body).to include('.state-button') }
end
context "with accepter" do
@ -199,7 +199,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
expect(NotificationMailer).to receive(:deliver_later)
end
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id } }
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
it 'change state to accepte' do
subject
@ -223,16 +223,14 @@ describe NewGestionnaire::DossiersController, type: :controller do
end
it 'The gestionnaire is sent back to the dossier page' do
subject
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
expect(subject.body).to include('.state-button')
end
context 'and the dossier has already an attestation' do
it 'should not crash' do
dossier.attestation = Attestation.new
dossier.save
expect(subject).to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
expect(subject.body).to include('.state-button')
end
end
end
@ -248,7 +246,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
procedure_id: procedure.id,
dossier_id: dossier.id,
dossier: { motivation: "Yallah" }
}
}, format: 'js'
end
before do

View file

@ -9,7 +9,7 @@ feature 'The gestionnaire part' do
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
let!(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure) }
scenario 'A gestionnaire can accept a dossier' do
scenario 'A gestionnaire can accept a dossier', :js do
log_in(gestionnaire.email, password)
expect(page).to have_current_path(gestionnaire_procedures_path)
@ -20,15 +20,31 @@ feature 'The gestionnaire part' do
click_on dossier.user.email
expect(page).to have_current_path(gestionnaire_dossier_path(procedure, dossier))
click_on 'Passer en instruction'
click_on 'En construction'
accept_confirm do
click_on 'Passer en instruction'
end
expect(page).to have_text('En instruction')
dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction))
click_on 'En instruction'
within('.dropdown-items') do
click_on 'Accepter'
end
within('.accept.motivation') do
fill_in('dossier_motivation', with: 'a good reason')
click_on 'Valider la décision'
accept_confirm do
click_on 'Valider la décision'
end
end
expect(page).to have_text('Dossier traité avec succès.')
dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
expect(dossier.motivation).to eq('a good reason')