From 8e04b4f0c93e7c9ea841a55cb5fab07df6383cb6 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 6 May 2019 16:24:48 +0200 Subject: [PATCH] =?UTF-8?q?Clear=20the=20=E2=80=9Cadd=20admin=E2=80=9D=20f?= =?UTF-8?q?ield=20after=20submit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the add_admin form to its own partial and re-render it when an admin is successfully added. --- .../_add_admin_form.html.haml | 9 +++++++++ .../procedure_administrateurs/create.js.haml | 5 ++++- .../procedure_administrateurs/index.html.haml | 10 +--------- 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 app/views/new_administrateur/procedure_administrateurs/_add_admin_form.html.haml diff --git a/app/views/new_administrateur/procedure_administrateurs/_add_admin_form.html.haml b/app/views/new_administrateur/procedure_administrateurs/_add_admin_form.html.haml new file mode 100644 index 000000000..9f9cd565a --- /dev/null +++ b/app/views/new_administrateur/procedure_administrateurs/_add_admin_form.html.haml @@ -0,0 +1,9 @@ += form_for procedure.administrateurs.new, + url: { controller: 'procedure_administrateurs' }, + html: { class: 'form', id: "procedure-#{procedure.id}-new_administrateur" } , + remote: true do |f| + = f.label :email do + Ajouter un administrateur + %span.notice= "Renseignez l’email d’un administrateur déjà enregistré sur demarches-simplifiees.fr pour lui permettre de modifier « #{procedure.libelle} »." + = f.email_field :email, placeholder: 'marie.dupont@exemple.fr', required: true + = f.submit 'Ajouter comme administrateur', class: 'button primary send' diff --git a/app/views/new_administrateur/procedure_administrateurs/create.js.haml b/app/views/new_administrateur/procedure_administrateurs/create.js.haml index 9e4ff843c..610fbd95b 100644 --- a/app/views/new_administrateur/procedure_administrateurs/create.js.haml +++ b/app/views/new_administrateur/procedure_administrateurs/create.js.haml @@ -3,4 +3,7 @@ = append_to_element("#procedure-#{@procedure.id}-administrateurs", partial: 'administrateur', locals: { administrateur: @administrateur }) - document.getElementById('procedure-#{@procedure.id}-new_administrateur').reset() + = render_to_element("#procedure-#{@procedure.id}-new_administrateur", + partial: 'add_admin_form', + outer: true, + locals: { procedure: @procedure }) diff --git a/app/views/new_administrateur/procedure_administrateurs/index.html.haml b/app/views/new_administrateur/procedure_administrateurs/index.html.haml index ea54e04c5..d270dad37 100644 --- a/app/views/new_administrateur/procedure_administrateurs/index.html.haml +++ b/app/views/new_administrateur/procedure_administrateurs/index.html.haml @@ -15,12 +15,4 @@ %tfoot %tr %th{ colspan: 4 } - = form_for @procedure.administrateurs.new, - url: { controller: 'procedure_administrateurs' }, - html: { class: 'form', id: "procedure-#{@procedure.id}-new_administrateur" } , - remote: true do |f| - = f.label :email do - Ajouter un administrateur - %span.notice= "Renseignez l’email d’un administrateur déjà enregistré sur demarches-simplifiees.fr pour lui permettre de modifier « #{@procedure.libelle} »." - = f.email_field :email, placeholder: 'marie.dupont@exemple.fr', required: true - = f.submit 'Ajouter comme administrateur', class: 'button primary send' + = render 'add_admin_form', procedure: @procedure