mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 03:02:23 +00:00
Users can only edit & delete their own messages (except for admin users)
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
a771710094
commit
0cab21f344
@ -235,9 +235,18 @@ function redrawMessages() {
|
||||
fetchMoreButton.classList.remove('d-none')
|
||||
}
|
||||
|
||||
function removeAllPopovers() {
|
||||
for (let popover of document.querySelectorAll('*[aria-describedby*="popover"]')) {
|
||||
let instance = bootstrap.Popover.getInstance(popover)
|
||||
if (instance)
|
||||
instance.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function registerSendPrivateMessageContextMenu(message, element) {
|
||||
element.addEventListener('contextmenu', (menu_event) => {
|
||||
menu_event.preventDefault()
|
||||
removeAllPopovers()
|
||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
||||
'title': message['author'],
|
||||
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
|
||||
@ -247,7 +256,7 @@ function registerSendPrivateMessageContextMenu(message, element) {
|
||||
|
||||
document.getElementById('send-private-message-link-' + message['id']).addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
popover.hide()
|
||||
popover.dispose()
|
||||
socket.send(JSON.stringify({
|
||||
'type': 'start_private_chat',
|
||||
'user_id': message['author_id'],
|
||||
@ -259,10 +268,13 @@ function registerSendPrivateMessageContextMenu(message, element) {
|
||||
function registerMessageContextMenu(message, element) {
|
||||
element.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>`
|
||||
content += `<hr class="my-1">`
|
||||
content += `<a class="nav-link" href="#" tabindex="0">Modifier</a>`
|
||||
content += `<a class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
||||
if (message['author_id'] === USER_ID || IS_ADMIN) {
|
||||
content += `<hr class="my-1">`
|
||||
content += `<a class="nav-link" href="#" tabindex="0">Modifier</a>`
|
||||
content += `<a class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
||||
}
|
||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
||||
'content': content,
|
||||
'html': true,
|
||||
@ -272,7 +284,7 @@ function registerMessageContextMenu(message, element) {
|
||||
|
||||
document.getElementById('send-private-message-link-msg-' + message['id']).addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
popover.hide()
|
||||
popover.dispose()
|
||||
socket.send(JSON.stringify({
|
||||
'type': 'start_private_chat',
|
||||
'user_id': message['author_id'],
|
||||
@ -296,13 +308,7 @@ function toggleFullscreen() {
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('click', () => {
|
||||
for (let popover of document.querySelectorAll('span[aria-describedby*="popover"]')) {
|
||||
let instance = bootstrap.Popover.getInstance(popover)
|
||||
if (instance)
|
||||
instance.hide()
|
||||
}
|
||||
})
|
||||
document.addEventListener('click', removeAllPopovers)
|
||||
|
||||
/**
|
||||
* Process the received data from the server.
|
||||
|
@ -87,4 +87,9 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const USER_ID = {{ request.user.id }}
|
||||
const IS_ADMIN = {{ request.user.registration.is_admin|yesno:"true,false" }}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user