Merge pull request #2581 from tchak/do-not-reload-page-on-state-change

Do not reload page when instructeur change dossier state
This commit is contained in:
Paul Chavard 2018-10-04 10:01:13 +00:00 committed by GitHub
commit cac5035ddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 40 deletions

View file

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

View file

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

View file

@ -17,7 +17,8 @@
= link_to "Uniquement cet onglet", "#", onclick: "window.print()", class: "menu-item menu-link" = 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: "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 %ul.tabs
- notifications_summary = current_gestionnaire.notifications_for_dossier(dossier) - notifications_summary = current_gestionnaire.notifications_for_dossier(dossier)

View file

@ -11,7 +11,7 @@
%h4 En construction %h4 En construction
Vous permettez à l'usager de modifier ses réponses au formulaire Vous permettez à l'usager de modifier ses réponses au formulaire
%li %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 %span.icon.in-progress
.description .description
%h4 Passer en instruction %h4 Passer en instruction
@ -19,7 +19,7 @@
- if dossier.en_instruction? - if dossier.en_instruction?
%li %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 %span.icon.edit
.description .description
%h4 Repasser en construction %h4 Repasser en construction
@ -29,21 +29,24 @@
.description .description
%h4 En instruction %h4 En instruction
L'usager ne peut modifier son dossier pendant l'instruction L'usager ne peut modifier son dossier pendant l'instruction
%li{ onclick: "DS.showMotivation('accept');" } %li
%span.icon.accept %a{ href: '#', onclick: "DS.showMotivation(event, 'accept');" }
.description %span.icon.accept
%h4 Accepter .description
L'usager sera notifié que son dossier a été accepté %h4 Accepter
%li{ onclick: "DS.showMotivation('without-continuation');" } L'usager sera notifié que son dossier a été accepté
%span.icon.without-continuation %li
.description %a{ href: '#', onclick: "DS.showMotivation(event, 'without-continuation');" }
%h4 Classer sans suite %span.icon.without-continuation
L'usager sera notifié que son dossier a été classé sans suite .description
%li{ onclick: "DS.showMotivation('refuse');" } %h4 Classer sans suite
%span.icon.refuse L'usager sera notifié que son dossier a été classé sans suite
.description %li
%h4 Refuser %a{ href: '#', onclick: "DS.showMotivation(event, 'refuse');" }
L'usager sera notifié que son dossier a été refusé %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: '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: '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 ?' } = 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 } %span.icon{ class: popup_class }
#{popup_title} #{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' - if title == 'Accepter'
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)', required: false = text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)', required: false
%p.help %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 before do
dossier.en_construction! dossier.en_construction!
sign_in gestionnaire 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 dossier.reload
end end
it { expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) } 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 } it { expect(gestionnaire.follow?(dossier)).to be true }
end end
@ -122,7 +122,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire sign_in gestionnaire
end 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 it 'change state to en_construction' do
subject subject
@ -131,7 +131,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
expect(dossier.state).to eq(Dossier.states.fetch(:en_construction)) expect(dossier.state).to eq(Dossier.states.fetch(:en_construction))
end end
it { is_expected.to redirect_to gestionnaire_dossier_path(procedure, dossier) } it { expect(subject.body).to include('.state-button') }
end end
describe '#terminer' do describe '#terminer' do
@ -141,7 +141,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire sign_in gestionnaire
end 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 it 'change state to refuse' do
subject subject
@ -158,7 +158,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
subject subject
end end
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) } it { expect(subject.body).to include('.state-button') }
end end
context "with classer_sans_suite" do context "with classer_sans_suite" do
@ -167,7 +167,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
sign_in gestionnaire sign_in gestionnaire
end 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 it 'change state to sans_suite' do
subject subject
@ -184,7 +184,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
subject subject
end end
it { is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) } it { expect(subject.body).to include('.state-button') }
end end
context "with accepter" do context "with accepter" do
@ -199,7 +199,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
expect(NotificationMailer).to receive(:deliver_later) expect(NotificationMailer).to receive(:deliver_later)
end 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 it 'change state to accepte' do
subject subject
@ -223,16 +223,14 @@ describe NewGestionnaire::DossiersController, type: :controller do
end end
it 'The gestionnaire is sent back to the dossier page' do it 'The gestionnaire is sent back to the dossier page' do
subject expect(subject.body).to include('.state-button')
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
end end
context 'and the dossier has already an attestation' do context 'and the dossier has already an attestation' do
it 'should not crash' do it 'should not crash' do
dossier.attestation = Attestation.new dossier.attestation = Attestation.new
dossier.save dossier.save
expect(subject).to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier) expect(subject.body).to include('.state-button')
end end
end end
end end
@ -248,7 +246,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
procedure_id: procedure.id, procedure_id: procedure.id,
dossier_id: dossier.id, dossier_id: dossier.id,
dossier: { motivation: "Yallah" } dossier: { motivation: "Yallah" }
} }, format: 'js'
end end
before do before do

View file

@ -9,7 +9,7 @@ feature 'The gestionnaire part' do
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
let!(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure) } 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) log_in(gestionnaire.email, password)
expect(page).to have_current_path(gestionnaire_procedures_path) expect(page).to have_current_path(gestionnaire_procedures_path)
@ -20,15 +20,31 @@ feature 'The gestionnaire part' do
click_on dossier.user.email click_on dossier.user.email
expect(page).to have_current_path(gestionnaire_dossier_path(procedure, dossier)) 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 dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) 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 within('.accept.motivation') do
fill_in('dossier_motivation', with: 'a good reason') 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 end
expect(page).to have_text('Dossier traité avec succès.')
dossier.reload dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:accepte)) expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
expect(dossier.motivation).to eq('a good reason') expect(dossier.motivation).to eq('a good reason')