invite: support remote forms

This allows to keep the draft content when inviting a new user.
This commit is contained in:
Pierre de La Morinerie 2018-07-31 15:26:08 +00:00 committed by gregoirenovel
parent 1cac0b80af
commit 1ca2ca9121
5 changed files with 27 additions and 13 deletions

View file

@ -24,7 +24,10 @@ class InvitesController < ApplicationController
flash.alert = invite.errors.full_messages
end
redirect_back(fallback_location: helpers.url_for_dossier(dossier))
respond_to do |format|
format.html { redirect_back(fallback_location: helpers.url_for_dossier(dossier)) }
format.js { @dossier = dossier }
end
end
private

View file

@ -12,6 +12,6 @@
%p Vous pouvez inviter quelquun à remplir ce dossier avec vous.
%p Cette personne aura le droit de modifier votre dossier.
= form_tag invites_dossier_path(dossier_id: dossier.id), method: :post, class: 'form' do
= form_tag invites_dossier_path(dossier_id: dossier.id), remote: true, method: :post, class: 'form' do
= email_field_tag :invite_email, '', class: 'small', placeholder: 'adresse email', required: true
= submit_tag 'Envoyer une invitation', class: 'button accepted'

View file

@ -0,0 +1,6 @@
var formView = "<%= escape_javascript(render partial: 'invites/form', locals: { dossier: @dossier }) %>";
document.querySelector("#invites-form").outerHTML = formView;
var flashMessagesView = "<%= escape_javascript(render partial: 'layouts/flash_messages') %>";
document.querySelector("#flash_messages").outerHTML = flashMessagesView;
<% flash.clear %>

View file

@ -1,11 +1,12 @@
- if flash.any?
#flash_message.center
- flash.each do |key, value|
- if value.class == Array
.alert{ class: flash_class(key) }
- value.each do |message|
= sanitize(message)
%br
- else
.alert{ class: flash_class(key) }
= sanitize(value)
#flash_messages
- if flash.any?
#flash_message.center
- flash.each do |key, value|
- if value.class == Array
.alert{ class: flash_class(key) }
- value.each do |message|
= sanitize(message)
%br
- else
.alert{ class: flash_class(key) }
= sanitize(value)

View file

@ -13,11 +13,15 @@ feature 'Invitations' do
log_in(user)
navigate_to_brouillon(dossier)
fill_in 'Libelle du champ', with: 'Some edited value'
send_invite_to "user_invite@exemple.fr"
expect(page).to have_current_path(modifier_dossier_path(dossier))
expect(page).to have_text("Une invitation a été envoyée à user_invite@exemple.fr.")
expect(page).to have_text("user_invite@exemple.fr")
# Ensure unsaved edits to the form are not lost
expect(page).to have_field('Libelle du champ', with: 'Some edited value')
end
scenario 'an invited user can see and edit the draft', js: true do