mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-05-16 11:32:46 +00:00
Compare commits
2 Commits
531eecf4b8
...
0129e32643
Author | SHA1 | Date | |
---|---|---|---|
|
0129e32643 | ||
|
64a2ea007e |
@ -157,7 +157,6 @@ function fetchPreviousMessages() {
|
||||
}
|
||||
|
||||
function receiveFetchedMessages(data) {
|
||||
console.log(data)
|
||||
let channel_id = data['channel_id']
|
||||
let new_messages = data['messages']
|
||||
|
||||
@ -237,7 +236,7 @@ function redrawMessages() {
|
||||
messageContentDiv.setAttribute('data-message-id', message['id'])
|
||||
lastContentDiv.appendChild(messageContentDiv)
|
||||
let messageContentSpan = document.createElement('span')
|
||||
messageContentSpan.innerText = message['content']
|
||||
messageContentSpan.innerHTML = markdownToHTML(message['content'])
|
||||
messageContentDiv.appendChild(messageContentSpan)
|
||||
|
||||
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
|
||||
@ -272,7 +271,7 @@ function redrawMessages() {
|
||||
messageContentDiv.setAttribute('data-message-id', message['id'])
|
||||
contentDiv.appendChild(messageContentDiv)
|
||||
let messageContentSpan = document.createElement('span')
|
||||
messageContentSpan.innerText = message['content']
|
||||
messageContentSpan.innerHTML = markdownToHTML(message['content'])
|
||||
messageContentDiv.appendChild(messageContentSpan)
|
||||
|
||||
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
|
||||
@ -290,6 +289,26 @@ function redrawMessages() {
|
||||
messageList.dispatchEvent(new CustomEvent('updatemessages'))
|
||||
}
|
||||
|
||||
function markdownToHTML(text) {
|
||||
let safeText = text.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'")
|
||||
let lines = safeText.split('\n')
|
||||
let htmlLines = []
|
||||
for (let line of lines) {
|
||||
let htmlLine = line
|
||||
.replaceAll(/_(.*)_/gim, '<span class="text-decoration-underline">$1</span>') // Underline
|
||||
.replaceAll(/\*\*(.*)\*\*/gim, '<span class="fw-bold">$1</span>') // Bold
|
||||
.replaceAll(/\*(.*)\*/gim, '<span class="fst-italic">$1</span>') // Italic
|
||||
.replaceAll(/`(.*)`/gim, '<pre>$1</pre>') // Code
|
||||
.replaceAll(/(https?:\/\/\S+)/g, '<a href="$1" target="_blank">$1</a>') // Links
|
||||
htmlLines.push(htmlLine)
|
||||
}
|
||||
return htmlLines.join('<br>')
|
||||
}
|
||||
|
||||
function removeAllPopovers() {
|
||||
for (let popover of document.querySelectorAll('*[aria-describedby*="popover"]')) {
|
||||
let instance = bootstrap.Popover.getInstance(popover)
|
||||
|
@ -259,17 +259,20 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
||||
payment = Payment.objects.get(registrations=registration, final=False)
|
||||
else:
|
||||
payment = None
|
||||
mail_context = dict(domain=domain, registration=registration, team=self.object, payment=payment,
|
||||
message=form.cleaned_data["message"])
|
||||
mail_plain = render_to_string("participation/mails/team_validated.txt", mail_context)
|
||||
mail_html = render_to_string("participation/mails/team_validated.html", mail_context)
|
||||
mail_context_plain = dict(domain=domain, registration=registration, team=self.object, payment=payment,
|
||||
message=form.cleaned_data["message"])
|
||||
mail_context_html = dict(domain=domain, registration=registration, team=self.object, payment=payment,
|
||||
message=form.cleaned_data["message"].replace('\n', '<br>'))
|
||||
mail_plain = render_to_string("participation/mails/team_validated.txt", mail_context_plain)
|
||||
mail_html = render_to_string("participation/mails/team_validated.html", mail_context_html)
|
||||
registration.user.email_user("[TFJM²] Équipe validée", mail_plain, html_message=mail_html)
|
||||
elif "invalidate" in self.request.POST:
|
||||
self.object.participation.valid = None
|
||||
self.object.participation.save()
|
||||
mail_context = dict(team=self.object, message=form.cleaned_data["message"])
|
||||
mail_plain = render_to_string("participation/mails/team_not_validated.txt", mail_context)
|
||||
mail_html = render_to_string("participation/mails/team_not_validated.html", mail_context)
|
||||
mail_context_plain = dict(team=self.object, message=form.cleaned_data["message"])
|
||||
mail_context_html = dict(team=self.object, message=form.cleaned_data["message"].replace('\n', '<br>'))
|
||||
mail_plain = render_to_string("participation/mails/team_not_validated.txt", mail_context_plain)
|
||||
mail_html = render_to_string("participation/mails/team_not_validated.html", mail_context_html)
|
||||
send_mail("[TFJM²] Équipe non validée", mail_plain, None, [self.object.email],
|
||||
html_message=mail_html)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user