diff --git a/app/assets/javascripts/old_design/direct_uploads.js b/app/assets/javascripts/old_design/direct_uploads.js index 1ac788eec..47b5aa23c 100644 --- a/app/assets/javascripts/old_design/direct_uploads.js +++ b/app/assets/javascripts/old_design/direct_uploads.js @@ -42,4 +42,16 @@ addEventListener("direct-upload:end", function (event) { element = document.getElementById("direct-upload-" + id); element.classList.add("direct-upload--complete"); -}); \ No newline at end of file +}); + +addEventListener('load', function() { + var submitButtons = document.querySelectorAll('form button[type=submit][data-action]'); + var hiddenInput = document.querySelector('form input[type=hidden][name=submit_action]'); + submitButtons = [].slice.call(submitButtons); + + submitButtons.forEach(function(button) { + button.addEventListener('click', function() { + hiddenInput.value = button.getAttribute('data-action'); + }); + }); +}); diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index f51305b31..ccf4b48fc 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -113,11 +113,11 @@ class Users::DescriptionController < UsersController end def brouillon_submission? - params[:submit] && params[:submit]['brouillon'].present? + params[:submit_action] == 'brouillon' end def brouillon_then_dashboard_submission? - params[:submit] && params[:submit]['brouillon_then_dashboard'].present? + params[:submit_action] == 'brouillon_then_dashboard' end def check_autorisation_donnees diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index cbb86df67..56234b031 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -40,6 +40,26 @@ - elsif !@dossier.brouillon? = render partial: '/layouts/modifications_terminees' - 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 '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 } + = hidden_field_tag 'submit_action', 'brouillon' + = submit_tag 'Bonjour Active Storage !', style: 'display: none;' + = button_tag 'Soumettre mon dossier', + id: 'suivant', + type: 'submit', + class: 'btn btn btn-success', + style: 'float: right;', + disabled: @procedure.archivee?, + data: { disable: true, action: 'nouveaux' } + = button_tag 'Enregistrer un brouillon', + id: 'brouillon', + type: 'submit', + class: 'btn btn-xs btn-default', + style: 'float: right; margin-right: 10px; margin-top: 6px;', + disabled: @procedure.archivee?, + data: { disable: true, action: 'brouillon' } + = button_tag "Enregistrer et voir mes dossiers", + id: 'brouillon_then_dashboard', + type: 'submit', + class: 'btn btn-xs btn-default', + style: 'float: right; margin-right: 10px; margin-top: 6px;', + disabled: @procedure.archivee?, + data: { disable: true, action: 'brouillon_then_dashboard' } diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index 24d0a7039..f3d024fc8 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -107,12 +107,12 @@ shared_examples 'description_controller_spec' do let(:state) { 'brouillon' } def submit_dossier - post :update, params: { dossier_id: dossier_id, submit: submit } + post :update, params: { dossier_id: dossier_id, submit_action: submit } dossier.reload end context "when the user submits the dossier" do - let(:submit) { { nouveaux: 'nouveaux' } } + let(:submit) { 'nouveaux' } it "redirection vers la page recapitulative" do submit_dossier @@ -142,7 +142,7 @@ shared_examples 'description_controller_spec' do end context 'when user saves a brouillon' do - let(:submit) { { brouillon: 'brouillon' } } + let(:submit) { 'brouillon' } it "reste sur la page du dossier" do submit_dossier @@ -156,7 +156,7 @@ shared_examples 'description_controller_spec' do end context 'when user saves a brouillon and goes to dashboard' do - let(:submit) { { brouillon_then_dashboard: 'brouillon_then_dashboard' } } + let(:submit) { 'brouillon_then_dashboard' } it "goes to dashboard" do submit_dossier diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index a1c7ab759..1ba1d94f4 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -27,6 +27,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1' + find(:css, '[name=submit_action]').set('nouveaux') page.find_by_id('suivant').click expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14") expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s)) @@ -38,6 +39,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1' + find(:css, '[name=submit_action]').set('nouveaux') page.find_by_id('suivant').click expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14") expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s)) @@ -52,6 +54,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click fill_in "champs_#{procedure_for_individual.dossiers.last.champs.first.id}", with: 'contenu du champ 1' + find(:css, '[name=submit_action]').set('nouveaux') page.find_by_id('suivant').click expect(user.dossiers.first.individual.birthdate).to eq(nil) expect(page).to have_current_path(users_dossier_recapitulatif_path(procedure_for_individual.dossiers.last.id.to_s))