Merge pull request #1125 from sgmap/fix-1011
[Fix #1011] Change the “Enregistrer un brouillon” button behaviour
This commit is contained in:
commit
d45724c1af
3 changed files with 36 additions and 15 deletions
|
@ -39,7 +39,7 @@ class Users::DescriptionController < UsersController
|
||||||
errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params)
|
errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params)
|
||||||
return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any?
|
return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any?
|
||||||
|
|
||||||
if params[:champs] && !brouillon_submission?
|
if params[:champs] && !(brouillon_submission? || brouillon_then_dashboard_submission?)
|
||||||
errors =
|
errors =
|
||||||
ChampsService.build_error_messages(dossier.champs) +
|
ChampsService.build_error_messages(dossier.champs) +
|
||||||
PiecesJustificativesService.missing_pj_error_messages(dossier)
|
PiecesJustificativesService.missing_pj_error_messages(dossier)
|
||||||
|
@ -48,6 +48,8 @@ class Users::DescriptionController < UsersController
|
||||||
|
|
||||||
if brouillon_submission?
|
if brouillon_submission?
|
||||||
flash.notice = 'Votre brouillon a bien été sauvegardé.'
|
flash.notice = 'Votre brouillon a bien été sauvegardé.'
|
||||||
|
redirect_to users_dossier_description_path(dossier.id)
|
||||||
|
elsif brouillon_then_dashboard_submission?
|
||||||
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
|
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
|
||||||
else
|
else
|
||||||
if dossier.brouillon?
|
if dossier.brouillon?
|
||||||
|
@ -110,7 +112,11 @@ class Users::DescriptionController < UsersController
|
||||||
end
|
end
|
||||||
|
|
||||||
def brouillon_submission?
|
def brouillon_submission?
|
||||||
params[:submit] && params[:submit].keys.first == 'brouillon'
|
params[:submit] && params[:submit]['brouillon'].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def brouillon_then_dashboard_submission?
|
||||||
|
params[:submit] && params[:submit]['brouillon_then_dashboard'].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_autorisation_donnees
|
def check_autorisation_donnees
|
||||||
|
|
|
@ -44,3 +44,4 @@
|
||||||
- else
|
- else
|
||||||
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float: right;', disabled: @procedure.archivee?, data: { disable_with: 'Soumettre votre dossier', submit: true }
|
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float: right;', disabled: @procedure.archivee?, data: { disable_with: 'Soumettre votre dossier', submit: true }
|
||||||
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float: right; margin-right: 10px; margin-top: 6px;', disabled: @procedure.archivee?, data: { disable_with: 'Enregistrer un brouillon', submit: true }
|
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float: right; margin-right: 10px; margin-top: 6px;', disabled: @procedure.archivee?, data: { disable_with: 'Enregistrer un brouillon', submit: true }
|
||||||
|
= submit_tag "Enregistrer et voir mes dossiers", id: 'brouillon_then_dashboard', name: 'submit[brouillon_then_dashboard]', class: 'btn btn-xs btn-default', style: 'float: right; margin-right: 10px; margin-top: 6px;', disabled: @procedure.archivee?, data: { disable_with: 'Voir mes brouillons et dossiers', submit: true }
|
||||||
|
|
|
@ -110,8 +110,6 @@ shared_examples 'description_controller_spec' do
|
||||||
|
|
||||||
context 'Tous les attributs sont bons' do
|
context 'Tous les attributs sont bons' do
|
||||||
describe 'Premier enregistrement des données' do
|
describe 'Premier enregistrement des données' do
|
||||||
let(:submit) { {nouveaux: 'nouveaux'} }
|
|
||||||
|
|
||||||
subject { post :update, params: {dossier_id: dossier_id, submit: submit} }
|
subject { post :update, params: {dossier_id: dossier_id, submit: submit} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -120,22 +118,38 @@ shared_examples 'description_controller_spec' do
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirection vers la page recapitulative" do
|
context "when the user submits the dossier" do
|
||||||
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
let(:submit) { {nouveaux: 'nouveaux'} }
|
||||||
end
|
|
||||||
|
|
||||||
it 'etat du dossier est soumis' do
|
|
||||||
expect(dossier.state).to eq('en_construction')
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when user whould like save just a brouillon' do
|
|
||||||
let(:submit) { {brouillon: 'brouillon'} }
|
|
||||||
|
|
||||||
it "redirection vers la page recapitulative" do
|
it "redirection vers la page recapitulative" do
|
||||||
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'etat du dossier est en construction' do
|
||||||
|
expect(dossier.state).to eq('en_construction')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user saves a brouillon' do
|
||||||
|
let(:submit) { {brouillon: 'brouillon'} }
|
||||||
|
|
||||||
|
it "reste sur la page du dossier" do
|
||||||
|
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'etat du dossier est brouillon' do
|
||||||
|
expect(dossier.state).to eq('brouillon')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user saves a brouillon and goes to dashboard' do
|
||||||
|
let(:submit) { {brouillon_then_dashboard: 'brouillon_then_dashboard'} }
|
||||||
|
|
||||||
|
it "goes to dashboard" do
|
||||||
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
|
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'etat du dossier est soumis' do
|
it 'etat du dossier est brouillon' do
|
||||||
expect(dossier.state).to eq('brouillon')
|
expect(dossier.state).to eq('brouillon')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue