From 90371bbb826c533dba2b8a382b06facab4df2228 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Wed, 11 Aug 2021 19:02:12 +0200 Subject: [PATCH] save instructeur commentaire local storage --- .../shared/dossiers/_messagerie.html.haml | 2 +- .../shared/dossiers/messages/_form.html.haml | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/views/shared/dossiers/_messagerie.html.haml b/app/views/shared/dossiers/_messagerie.html.haml index a37612b50..039f01043 100644 --- a/app/views/shared/dossiers/_messagerie.html.haml +++ b/app/views/shared/dossiers/_messagerie.html.haml @@ -5,6 +5,6 @@ = render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, connected_user: connected_user, messagerie_seen_at: messagerie_seen_at, show_reply_button: show_reply_button(commentaire, connected_user) } - if dossier.messagerie_available? - = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } + = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url, dossier: dossier } - else = render partial: "shared/dossiers/messages/messagerie_disabled", locals: { service: dossier.procedure.service, dossier: dossier } diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index c9a4837de..c1b555b7a 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -1,8 +1,9 @@ -= form_for(commentaire, url: form_url, html: { class: 'form' }) do |f| += form_for(commentaire, url: form_url, html: { class: 'form', id: "commentaire-form-#{@dossier.id}" }) do |f| + - dossier = commentaire.dossier - placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder') - if instructeur_signed_in? || administrateur_signed_in? - placeholder = t('views.shared.dossiers.messages.form.write_message_placeholder') - = f.text_area :body, rows: 5, placeholder: placeholder, required: true, class: 'message-textarea' + = f.text_area :body, rows: 5, placeholder: placeholder, required: true, class: 'message-textarea', id: "messagerie-#{@dossier.id}" .flex.justify-between.wrap %div = f.label :piece_jointe, for: :piece_jointe do @@ -12,3 +13,17 @@ %div = f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'button primary send', data: { disable: true } + +:javascript + const commentaireInput = document.getElementById('messagerie-#{@dossier.id}') + const commentaireForm = document.getElementById('commentaire-form-#{@dossier.id}') + commentaireInput.value = localStorage.getItem(`message-#{@dossier.id}`) + + commentaireInput.addEventListener('change', (event) => { + localStorage.setItem(`message-#{@dossier.id}`, event.target.value); + }); + + commentaireForm.addEventListener('submit', () => { + localStorage.removeItem(`message-#{@dossier.id}`); + }) +