-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendu dynamique du formulaire de message #615
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
|
||
(function () { | ||
// This JS code won't be executed on IE11, so we can write ES6 code | ||
class MessageForm extends Stimulus.Controller { | ||
initialize() { | ||
this.onGoingRequestValue = false; | ||
} | ||
|
||
async onSubmit(evt) { | ||
if (this.onGoingRequestValue) { | ||
return; | ||
} | ||
|
||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
|
||
if (!this.formTarget.checkValidity()) { | ||
return; | ||
} | ||
|
||
let dest = new URL(this.formTarget.action, location.origin); | ||
dest.searchParams.append("http-api", "true"); | ||
|
||
this.onGoingRequestValue = true; | ||
christophehenry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let response = await fetch(dest.toString(), { | ||
method: this.formTarget.method.toUpperCase(), | ||
body: new FormData(this.formTarget), | ||
}).finally(() => {this.onGoingRequestValue = false}); | ||
|
||
if (response.ok) { | ||
let html = await response.text(); | ||
if (this.hasEmptyElementTarget) { | ||
this.emptyElementTarget.remove(); | ||
} | ||
|
||
this.messagesListTarget.insertAdjacentHTML("beforeend", html); | ||
this.formTarget.reset(); | ||
} | ||
} | ||
|
||
onGoingRequestValueChanged(value, _) { | ||
if (value) { | ||
this.submitBtnTarget.setAttribute("disabled", "disabled"); | ||
this.textareaTarget.setAttribute("disabled", "disabled"); | ||
} else { | ||
this.submitBtnTarget.removeAttribute("disabled"); | ||
this.textareaTarget.removeAttribute("disabled"); | ||
} | ||
} | ||
|
||
static targets = ["form", "emptyElement", "messagesList", "submitBtn", "textarea"] | ||
static values = {"onGoingRequest": Boolean} | ||
} | ||
|
||
if (window.fetch) { | ||
window.addEventListener("load", () => | ||
Stimulus.Application.start().register("message-form", MessageForm) | ||
); | ||
} | ||
})(); |
23 changes: 23 additions & 0 deletions
23
aidants_connect_habilitation/templates/request_messages/_message_item.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% comment %} | ||
Context: | ||
{ | ||
"message": RequestMessage, | ||
"issuer": Issuer, | ||
} | ||
{% endcomment %} | ||
<li> | ||
<div class="fr-grid-row fr-grid-row--gutters"> | ||
{% if message.sender == "AC" %} | ||
<div class="fr-col-4 text-blue"> | ||
<strong>"Aidant Connect</strong> | ||
<p class="more-info-messages">{{ message.created_at }}</p> | ||
</div> | ||
{% else %} | ||
<div class="fr-col-4 text-red"> | ||
<strong>{{ issuer.first_name }} {{ issuer.last_name }}</strong> | ||
<p class="more-info-messages">{{ message.created_at }}</p> | ||
</div> | ||
{% endif %} | ||
<div class="fr-col-8">{{ message.content|linebreaksbr }}</div> | ||
</div> | ||
</li> |
60 changes: 60 additions & 0 deletions
60
aidants_connect_habilitation/templates/request_messages/_messages.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{% comment %} | ||
Context: | ||
{ | ||
"messages": List[RequestMessage], | ||
"issuer": Issuer, | ||
"form": RequestMessageForm, | ||
} | ||
{% endcomment %} | ||
<h2>Vos échanges avec Aidants Connect</h2> | ||
<div | ||
class="fr-grid-row fr-grid-row--gutters" | ||
data-controller="message-form" | ||
> | ||
<div class="fr-col-12 fr-col-md-8"> | ||
<div class="shadowed"> | ||
<div class="messages-list-container"> | ||
<ol class="messages-list" data-message-form-target="messagesList"> | ||
{% for message in messages.all %} | ||
{% include "request_messages/_message_item.html" with issuer=issuer message=message %} | ||
{% empty %} | ||
<li data-message-form-target="emptyElement"> | ||
<div class="fr-grid-row fr-grid-row--gutters"> | ||
<div class="fr-col-4 text-blue"><strong>Aidants Connect</strong></div> | ||
<div class="fr-col-8"> | ||
<p class="more-info-messages"><strong>Notre conversation démarre ici.</strong></p> | ||
<p class="more-info-messages"> | ||
Vous retrouverez ici vos échanges par écrit avec l’équipe d’Aidants Connect. Vous pouvez utiliser | ||
l’interface ci-dessous pour envoyer un message, | ||
une remarque ou une demande complémentaire.</p> | ||
<p class="more-info-messages">Nous vous répondrons dans les meilleurs délais.</p> | ||
</div> | ||
</div> | ||
</li> | ||
{% endfor %} | ||
</ol> | ||
</div> | ||
<div class="message-form-container"> | ||
<form method="post" data-message-form-target="form"> | ||
{% csrf_token %} | ||
<div class="fr-grid-row fr-grid-row--gutters"> | ||
<label class="fr-col-4" for="{{ form.content.id_for_label }}">Votre message</label> | ||
<div class="fr-col-6"> | ||
{{ form.content }} | ||
</div> | ||
<div class="fr-col-2"> | ||
<button | ||
type="submit" | ||
class="button primary" | ||
data-action="message-form#onSubmit" | ||
data-message-form-target="submitBtn" | ||
> | ||
Envoyer | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est sympa, quand-même, ES6+. Ça me gonfle vraiment qu'on s'oblige à supporter un navigateur que même son éditeur ne supporte plus.