Merge pull request #1446 from tchak/fix-multi-submit
Fix multi submit bug with direct upload
This commit is contained in:
commit
5b6a54399c
5 changed files with 45 additions and 10 deletions
|
@ -42,4 +42,16 @@ addEventListener("direct-upload:end", function (event) {
|
|||
element = document.getElementById("direct-upload-" + id);
|
||||
|
||||
element.classList.add("direct-upload--complete");
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue