invite: support remote forms
This allows to keep the draft content when inviting a new user.
This commit is contained in:
parent
1cac0b80af
commit
1ca2ca9121
5 changed files with 27 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
%p Vous pouvez inviter quelqu’un à 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'
|
||||
|
|
6
app/views/invites/create.js.erb
Normal file
6
app/views/invites/create.js.erb
Normal 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 %>
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue