1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-24 03:02:23 +00:00

Improve context menus

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-28 20:25:00 +02:00
parent f26f102650
commit 8f3929875f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -199,7 +199,7 @@ function redrawMessages() {
messageContentSpan.innerText = message['content']
messageContentDiv.appendChild(messageContentSpan)
registerMessageContextMenu(message, messageContentSpan)
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
continue
}
}
@ -216,7 +216,7 @@ function redrawMessages() {
authorSpan.innerText = message['author']
authorDiv.appendChild(authorSpan)
registerSendPrivateMessageContextMenu(message, authorSpan)
registerSendPrivateMessageContextMenu(message, authorDiv, authorSpan)
let dateSpan = document.createElement('span')
dateSpan.classList.add('text-muted', 'float-end')
@ -232,7 +232,7 @@ function redrawMessages() {
messageContentSpan.innerText = message['content']
messageContentDiv.appendChild(messageContentSpan)
registerMessageContextMenu(message, messageContentSpan)
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
lastMessage = message
lastContentDiv = contentDiv
@ -253,11 +253,11 @@ function removeAllPopovers() {
}
}
function registerSendPrivateMessageContextMenu(message, element) {
element.addEventListener('contextmenu', (menu_event) => {
function registerSendPrivateMessageContextMenu(message, div, span) {
div.addEventListener('contextmenu', (menu_event) => {
menu_event.preventDefault()
removeAllPopovers()
const popover = bootstrap.Popover.getOrCreateInstance(element, {
const popover = bootstrap.Popover.getOrCreateInstance(span, {
'title': message['author'],
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
'html': true,
@ -275,8 +275,8 @@ function registerSendPrivateMessageContextMenu(message, element) {
})
}
function registerMessageContextMenu(message, element) {
element.addEventListener('contextmenu', (menu_event) => {
function registerMessageContextMenu(message, div, span) {
div.addEventListener('contextmenu', (menu_event) => {
menu_event.preventDefault()
removeAllPopovers()
let content = `<a id="send-private-message-link-msg-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`
@ -288,7 +288,7 @@ function registerMessageContextMenu(message, element) {
content += `<a id="delete-message-${message['id']}" class="nav-link" href="#" tabindex="0">Supprimer</a>`
}
const popover = bootstrap.Popover.getOrCreateInstance(element, {
const popover = bootstrap.Popover.getOrCreateInstance(span, {
'content': content,
'html': true,
'placement': 'bottom',
@ -321,7 +321,7 @@ function registerMessageContextMenu(message, element) {
document.getElementById('delete-message-' + message['id']).addEventListener('click', event => {
event.preventDefault()
popover.dispose()
if (confirm("Supprimer le message ?")) {
if (confirm(`Supprimer le message ?\n${message['content']}`)) {
socket.send(JSON.stringify({
'type': 'delete_message',
'message_id': message['id'],