fix datatable messages

This commit is contained in:
amazuecos
2025-02-26 08:11:12 +01:00
parent c5f1f0e55a
commit ae561d1e19
8 changed files with 184 additions and 43 deletions

View File

@ -14,7 +14,7 @@ class MessagesDatatable {
{ data: 'title', searchable: true, sortable: true },
{ data: 'creator', searchable: false, sortable: false },
{
data: 'viewed', searchable: false, sortable: false,
data: 'viewed', searchable: false, sortable: true,
render: (d, t) => {
const iconClass = d == true ? "ti ti-sm ti-check" : "ti ti-sm ti-x"
return `<span class="${iconClass}"</span>`
@ -24,8 +24,19 @@ class MessagesDatatable {
data: 'action', searchable: false, sortable: false,
render: (d, t) => {
return `<div class="btn-group btn-group-sm">
<a href="/chat/${d.type}/${d.modelId}" class="message-edit"><i class="ti ti-eye ti-sm mx-2"></i></a>
</div>`
<a href="/chat/${d.type}/${d.modelId}" class="message-edit" title="${d.lang.view_chat}"><i class="ti ti-eye ti-sm mx-2"></i></a>
${d.isAdmin ?
`<div class="btn-group dropstart btn-group-sm">
<button data-id="${d.modelId}" type="button" title="${d.lang.view_by_alt_message}" class="btn btn-icon rounded-pill dropdown-toggle hide-arrow text-primary btn-notification-viewed" data-bs-toggle="dropdown">
<i class="icon-base ti ti-messages"></i>
</button>
<ul class="dropdown-menu" id="dropdown-viewed-${d.modelId}">
</ul>
</div>` : ""
}
</div>
`
}
}
]
@ -34,8 +45,14 @@ class MessagesDatatable {
}
init() {
this.item.on('click', '.btn-notification-viewed', (event) => {
const chatId = $(event.currentTarget).data('id')
$(`#dropdown-viewed-${chatId}`).empty()
this.handleDropUp(chatId)
})
this.datatable = this.datatableItem.DataTable({
processing: true,
order: [[1, 'desc']],
layout: {
topStart: 'pageLength',
topEnd: 'search',
@ -53,6 +70,7 @@ class MessagesDatatable {
this.datatablePresupuestoMessage = this.datatablePresupuestoMessageItem.DataTable({
processing: true,
order: [[1, 'desc']],
layout: {
topStart: 'pageLength',
topEnd: 'search',
@ -69,6 +87,7 @@ class MessagesDatatable {
});
this.datatablePedidoMessage = this.datatablePedidoMessageItem.DataTable({
processing: true,
order: [[1, 'desc']],
layout: {
topStart: 'pageLength',
topEnd: 'search',
@ -85,6 +104,7 @@ class MessagesDatatable {
});
this.datatableFacturaMessage = this.datatableFacturaMessageItem.DataTable({
processing: true,
order: [[1, 'desc']],
layout: {
topStart: 'pageLength',
topEnd: 'search',
@ -102,6 +122,46 @@ class MessagesDatatable {
}
handleDropUp(chatId) {
let ajax = new Ajax('/chat/users/notifications-unviewed/' + chatId,
null,
null,
this.handleDropUpSuccess.bind(this),
this.handleDropUpError.bind(this)
)
ajax.get();
}
handleDropUpSuccess(response) {
const chatId = response.chat_id
const users = response.data
if (users.length > 0) {
users.forEach(user => {
const viewed = (user.notification_count - user.viewed_count) == 0
if (user.userFullName || user.userName) {
$(`#dropdown-viewed-${chatId}`)
.append(`
<li >
<a class="d-flex flex-row justify-content-start align-items-center dropdown-item px-2 gap-2" href="javascript:void(0);" >
<span> ${user.userFullName ?? user.userName} </span>
<span class="badge badge-center rounded-pill text-bg-secondary">
<i class="ti ti-xs ti-${viewed ? "eye-check" : "eye-off"} "></i>
</span>
</a>
</li>
`)
}
});
} else {
$(`#dropdown-viewed-${chatId}`).append(`<li><a class="dropdown-item" href="javascript:void(0);" >Visto</a></li>`)
}
}
handleDropUpError() { }
}
export default MessagesDatatable;