mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message refactor
This commit is contained in:
@ -138,6 +138,7 @@ class Chat {
|
||||
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
this.initSelectClient()
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
|
||||
|
||||
|
||||
@ -149,6 +150,8 @@ class Chat {
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
this.initSelectClient()
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -159,8 +162,7 @@ class Chat {
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
this.initSelectClient()
|
||||
|
||||
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
}
|
||||
initContacts() {
|
||||
this.chatType = "internal"
|
||||
@ -198,7 +200,7 @@ class Chat {
|
||||
_handleGetChatList(event) {
|
||||
this.domItem.find(".chat-loader").removeClass("d-none")
|
||||
let ajax = new Ajax(
|
||||
"/chat/departments",
|
||||
`/chat/departments/${this.chatType}/${this.modelId}`,
|
||||
null,
|
||||
null,
|
||||
this._handleGetChatListSuccess.bind(this),
|
||||
@ -211,7 +213,6 @@ class Chat {
|
||||
Object.values(data).map(row => {
|
||||
this.chatList.append(this._getContact(row))
|
||||
this.chatDeparmentId = row.id
|
||||
this._getChatTotalMessages(row.name)
|
||||
this.chatList.find(`#chat_${row.name}`).on("click", (event) => {
|
||||
$(".chat-contact-list-item").removeClass("active")
|
||||
$(event.currentTarget).parent().addClass("active")
|
||||
@ -220,7 +221,6 @@ class Chat {
|
||||
this.domItem.find(".chat-history-header div.chat-contact-info h6").text(row.display)
|
||||
this.domItem.find(".chat-history-header div.chat-contact-info small.user-status").text(row.display)
|
||||
this._getChatMessage()
|
||||
this._getChatTotalMessages(row.name)
|
||||
this._getChatDeparmentUsers()
|
||||
|
||||
})
|
||||
@ -248,8 +248,8 @@ class Chat {
|
||||
ajax.get()
|
||||
}
|
||||
_getChatDeparmentUsersSuccess(deparmentUsers) {
|
||||
deparmentUsers.admin_users.map(user => this.appendChatDepartmentUser(user))
|
||||
deparmentUsers.external_users.map(user => this.appendChatDepartmentUser(user, 'warning', 'user'))
|
||||
deparmentUsers.adminUsers.map(user => this.appendChatDepartmentUser(user))
|
||||
deparmentUsers.externalUsers.map(user => this.appendChatDepartmentUser(user, 'warning', 'user'))
|
||||
|
||||
}
|
||||
appendChatDepartmentUser(user, color = "primary", icon = "user") {
|
||||
@ -259,10 +259,8 @@ class Chat {
|
||||
<div class="d-flex align-items-center py-1"
|
||||
id="chat-contact-list-item-${user.id}">
|
||||
|
||||
<div class="avatar-initial avatar-md px-2 py-2">
|
||||
<span class="badge badge-center rounded-pill text-bg-${color}">
|
||||
<i class="icon-base ti ti-xs ti-${icon}"></i>
|
||||
</span>
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
|
||||
@ -292,7 +290,7 @@ class Chat {
|
||||
${row.display}
|
||||
</p>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-secondary messages-unread-contact">${row.totalMessages ?? 0}</span>
|
||||
<span class="badge badge-center rounded-pill bg-secondary messages-unread-contact">${row.countMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
@ -304,7 +302,7 @@ class Chat {
|
||||
null,
|
||||
null,
|
||||
(data) => {
|
||||
this.chatList.find(`#chat_${row_name} .messages-unread-contact`).text(data.count)
|
||||
|
||||
},
|
||||
null
|
||||
|
||||
@ -346,6 +344,7 @@ class Chat {
|
||||
_getChatMessageSuccess(data) {
|
||||
this.domItem.find(".chat-loader").addClass("d-none")
|
||||
this._setBtnDeparment()
|
||||
this.chatList.find(`#chat_${data.department.name} .messages-unread-contact`).text(data.count ?? 0)
|
||||
if (data.messages) {
|
||||
data.messages.map((m) => {
|
||||
this._addChatMessage(m)
|
||||
@ -365,7 +364,7 @@ class Chat {
|
||||
<div class="chat-message-text">
|
||||
<p class="mb-0">${chatMessage?.message}</p>
|
||||
</div>
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<small>${chatMessage?.user?.first_name + " " + chatMessage?.user?.last_name}</small>
|
||||
</div>
|
||||
@ -375,8 +374,8 @@ class Chat {
|
||||
|
||||
</div>
|
||||
<div class="user-avatar flex-shrink-0 ms-3">
|
||||
<div class="avatar avatar-sm">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${chatMessage?.user?.first_name.charAt(0) + chatMessage?.user?.last_name.charAt(0)}</span>
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${chatMessage.user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -533,8 +532,6 @@ class Chat {
|
||||
}
|
||||
_handleGetSingleContactMessagesSuccess(data) {
|
||||
try {
|
||||
|
||||
|
||||
if (data) {
|
||||
data.map((m) => {
|
||||
this._addChatMessage(m)
|
||||
@ -824,106 +821,73 @@ class Chat {
|
||||
|
||||
}
|
||||
|
||||
const addInternalNotification = (e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
$("#chat-notification-list").append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
}
|
||||
const addDepartmentNotification = (e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
$("#chat-notification-list").append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const showNotificationMessages = (dom) => {
|
||||
const addNotificationsToDom = (data) =>
|
||||
{
|
||||
$("#chat-notification-list").empty()
|
||||
if (data.totalMessages > 0) {
|
||||
$("#chat-message-notification-title").addClass("d-none")
|
||||
$("#chat-notification-number").removeClass("d-none")
|
||||
$("#chat-notification-number").text(data.totalMessages ?? 0)
|
||||
} else {
|
||||
$("#chat-message-notification-title").removeClass("d-none")
|
||||
$("#chat-notification-number").addClass("d-none")
|
||||
$("#chat-notification-number").text(0)
|
||||
}
|
||||
data.departmentNotifications?.map( e => {
|
||||
addDepartmentNotification(e)}
|
||||
)
|
||||
data.internalNotifications?.map(e => {
|
||||
addInternalNotification(e)}
|
||||
)
|
||||
|
||||
}
|
||||
export const showNotificationMessages = () => {
|
||||
let ajax = new Ajax(
|
||||
'/chat/notifications',
|
||||
null,
|
||||
null,
|
||||
(data) => {
|
||||
dom.empty()
|
||||
$("#chat-notification-number")
|
||||
if (data.totalMessages > 0) {
|
||||
$("#chat-message-notification-title").addClass("d-none")
|
||||
$("#chat-notification-number").removeClass("d-none")
|
||||
$("#chat-notification-number").text(data.totalMessages ?? 0)
|
||||
} else {
|
||||
$("#chat-message-notification-title").removeClass("d-none")
|
||||
$("#chat-notification-number").addClass("d-none")
|
||||
$("#chat-notification-number").text(0)
|
||||
}
|
||||
data?.internals?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatPresupuestos?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.presupuestoId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatFacturas?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.facturaId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatPedidos?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.pedidoId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
addNotificationsToDom,
|
||||
(err) => { }
|
||||
)
|
||||
ajax.get()
|
||||
@ -931,104 +895,3 @@ export const showNotificationMessages = (dom) => {
|
||||
export default Chat
|
||||
|
||||
|
||||
// // Seleccionar elementos del DOM
|
||||
// const chatContactsBody = document.querySelector('.app-chat-contacts .sidebar-body'),
|
||||
// chatContactListItems = [].slice.call(
|
||||
// document.querySelectorAll('.chat-contact-list-item:not(.chat-contact-list-item-title)')
|
||||
// ),
|
||||
// chatHistoryBody = document.querySelector('.chat-history-body'),
|
||||
// chatSidebarLeftUserAbout = document.querySelector('.chat-sidebar-left-user-about'),
|
||||
// messageInput = document.querySelector('.message-input'),
|
||||
// searchInput = document.querySelector('.chat-search-input'),
|
||||
// sendMsgBtn = document.querySelector('.send-msg-btn'); // Seleccionar el botón de envío de mensaje
|
||||
|
||||
// // Inicializar PerfectScrollbar
|
||||
// if (chatContactsBody) {
|
||||
// new PerfectScrollbar(chatContactsBody, {
|
||||
// wheelPropagation: false,
|
||||
// suppressScrollX: true
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (chatHistoryBody) {
|
||||
// new PerfectScrollbar(chatHistoryBody, {
|
||||
// wheelPropagation: false,
|
||||
// suppressScrollX: true
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Función para desplazar el scroll al final
|
||||
// function scrollToBottom() {
|
||||
// if (chatHistoryBody) {
|
||||
// chatHistoryBody.scrollTo(0, chatHistoryBody.scrollHeight);
|
||||
// }
|
||||
// }
|
||||
// scrollToBottom();
|
||||
|
||||
// // Seleccionar chat o contacto
|
||||
|
||||
|
||||
// // Filtrar chats
|
||||
// if (searchInput) {
|
||||
// searchInput.addEventListener('keyup', e => {
|
||||
// const searchValue = e.currentTarget.value.toLowerCase(),
|
||||
// chatListItem0 = document.querySelector('.chat-list-item-0'),
|
||||
// contactListItem0 = document.querySelector('.contact-list-item-0'),
|
||||
// searchChatListItems = [].slice.call(
|
||||
// document.querySelectorAll('#chat-list li:not(.chat-contact-list-item-title)')
|
||||
// ),
|
||||
// searchContactListItems = [].slice.call(
|
||||
// document.querySelectorAll('#contact-list li:not(.chat-contact-list-item-title)')
|
||||
// );
|
||||
|
||||
// // Buscar en chats
|
||||
// const chatListItemsCount = searchChatContacts(searchChatListItems, searchValue);
|
||||
// // Mostrar u ocultar mensaje de "No se encontraron resultados" en chats
|
||||
// if (chatListItem0) {
|
||||
// chatListItem0.classList.toggle('d-none', chatListItemsCount !== 0);
|
||||
// }
|
||||
|
||||
// // Buscar en contactos
|
||||
// const contactListItemsCount = searchChatContacts(searchContactListItems, searchValue);
|
||||
// // Mostrar u ocultar mensaje de "No se encontraron resultados" en contactos
|
||||
// if (contactListItem0) {
|
||||
// contactListItem0.classList.toggle('d-none', contactListItemsCount !== 0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Función para buscar en chats y contactos
|
||||
// function searchChatContacts(searchListItems, searchValue) {
|
||||
// let searchListItemsCount = 0;
|
||||
// searchListItems.forEach(searchListItem => {
|
||||
// const searchListItemText = searchListItem.textContent.toLowerCase();
|
||||
// const matchesSearch = searchListItemText.indexOf(searchValue) !== -1;
|
||||
|
||||
// searchListItem.classList.toggle('d-flex', matchesSearch);
|
||||
// searchListItem.classList.toggle('d-none', !matchesSearch);
|
||||
|
||||
// if (matchesSearch) {
|
||||
// searchListItemsCount++;
|
||||
// }
|
||||
// });
|
||||
|
||||
// return searchListItemsCount;
|
||||
// }
|
||||
|
||||
// // // Enviar mensaje
|
||||
// // if (sendMsgBtn) {
|
||||
// // sendMsgBtn.addEventListener('click', e => {
|
||||
// // e.preventDefault();
|
||||
// // if (messageInput.value) {
|
||||
// // const renderMsg = document.createElement('div');
|
||||
// // renderMsg.className = 'chat-message-text mt-2';
|
||||
// // renderMsg.innerHTML = `<p class="mb-0">${messageInput.value}</p>`;
|
||||
// // const lastChatMessageWrapper = document.querySelector('li:last-child .chat-message-wrapper');
|
||||
// // if (lastChatMessageWrapper) {
|
||||
// // lastChatMessageWrapper.appendChild(renderMsg);
|
||||
// // }
|
||||
// // messageInput.value = '';
|
||||
// // scrollToBottom();
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
|
||||
@ -7,11 +7,13 @@ class MessagesDatatable {
|
||||
this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages")
|
||||
this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages")
|
||||
this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages")
|
||||
|
||||
this.columnDefs = [
|
||||
]
|
||||
this.datatableColumns = [
|
||||
{ data: 'created_at', searchable: true, sortable: true },
|
||||
{ data: 'updated_at', searchable: true, sortable: true },
|
||||
{ data: 'title', searchable: true, sortable: true },
|
||||
{ data: 'title', name:"chats.title",searchable: true, sortable: true },
|
||||
{ data: 'message', searchable: false, sortable: true },
|
||||
{ data: 'creator', searchable: false, sortable: false },
|
||||
{
|
||||
data: 'viewed', searchable: false, sortable: true,
|
||||
@ -27,10 +29,10 @@ class MessagesDatatable {
|
||||
<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">
|
||||
<button data-id="${d.chatMessageId}" 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 class="dropdown-menu" id="dropdown-viewed-${d.chatMessageId}">
|
||||
</ul>
|
||||
</div>` : ""
|
||||
}
|
||||
@ -46,13 +48,16 @@ class MessagesDatatable {
|
||||
}
|
||||
init() {
|
||||
this.item.on('click', '.btn-notification-viewed', (event) => {
|
||||
const chatId = $(event.currentTarget).data('id')
|
||||
$(`#dropdown-viewed-${chatId}`).empty()
|
||||
this.handleDropUp(chatId)
|
||||
const chatMessageId = $(event.currentTarget).data('id')
|
||||
$(`#dropdown-viewed-${chatMessageId}`).empty()
|
||||
this.handleDropUp(chatMessageId)
|
||||
})
|
||||
|
||||
this.datatable = this.datatableItem.DataTable({
|
||||
processing: true,
|
||||
order: [[1, 'desc']],
|
||||
columnDefs : this.columnDefs,
|
||||
orderCellsTop : true,
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
@ -71,6 +76,8 @@ class MessagesDatatable {
|
||||
this.datatablePresupuestoMessage = this.datatablePresupuestoMessageItem.DataTable({
|
||||
processing: true,
|
||||
order: [[1, 'desc']],
|
||||
columnDefs : this.columnDefs,
|
||||
orderCellsTop : true,
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
@ -87,6 +94,8 @@ class MessagesDatatable {
|
||||
});
|
||||
this.datatablePedidoMessage = this.datatablePedidoMessageItem.DataTable({
|
||||
processing: true,
|
||||
orderCellsTop : true,
|
||||
columnDefs : this.columnDefs,
|
||||
order: [[1, 'desc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
@ -104,6 +113,8 @@ class MessagesDatatable {
|
||||
});
|
||||
this.datatableFacturaMessage = this.datatableFacturaMessageItem.DataTable({
|
||||
processing: true,
|
||||
orderCellsTop : true,
|
||||
columnDefs : this.columnDefs,
|
||||
order: [[1, 'desc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
@ -119,11 +130,23 @@ class MessagesDatatable {
|
||||
columns: this.datatableColumns,
|
||||
ajax: '/messages/datatable/factura'
|
||||
});
|
||||
this.datatablePresupuestoMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatablePresupuestoMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
this.datatablePedidoMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatablePedidoMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
this.datatableFacturaMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatableFacturaMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
handleDropUp(chatId) {
|
||||
let ajax = new Ajax('/chat/users/notifications-unviewed/' + chatId,
|
||||
handleDropUp(chatMessageId) {
|
||||
let ajax = new Ajax('/chat/users/message/notifications-unviewed/' + chatMessageId,
|
||||
null,
|
||||
null,
|
||||
this.handleDropUpSuccess.bind(this),
|
||||
@ -133,32 +156,31 @@ class MessagesDatatable {
|
||||
ajax.get();
|
||||
}
|
||||
handleDropUpSuccess(response) {
|
||||
const chatId = response.chat_id
|
||||
const unviewedNotifications = response.data.unviewedNotifications
|
||||
const viewedNotifications = response.data.viewedNotifications
|
||||
const chat_message_id = response.chat_message_id
|
||||
const notifications = response.data.notifications
|
||||
|
||||
if (unviewedNotifications.length > 0) {
|
||||
if (notifications.length > 0) {
|
||||
|
||||
unviewedNotifications.forEach(user => {
|
||||
notifications.forEach(user => {
|
||||
if (user.userFullName || user.userName) {
|
||||
|
||||
$(`#dropdown-viewed-${chatId}`)
|
||||
$(`#dropdown-viewed-${chat_message_id}`)
|
||||
.append(this.addDropUpItem(user))
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
if (viewedNotifications.length > 0) {
|
||||
// if (viewedNotifications.length > 0) {
|
||||
|
||||
viewedNotifications.forEach(user => {
|
||||
if (user.userFullName || user.userName) {
|
||||
// viewedNotifications.forEach(user => {
|
||||
// if (user.userFullName || user.userName) {
|
||||
|
||||
$(`#dropdown-viewed-${chatId}`)
|
||||
.append(this.addDropUpItem(user))
|
||||
}
|
||||
// $(`#dropdown-viewed-${chat_message_id}`)
|
||||
// .append(this.addDropUpItem(user))
|
||||
// }
|
||||
|
||||
});
|
||||
}
|
||||
// });
|
||||
// }
|
||||
}
|
||||
handleDropUpError() { }
|
||||
addDropUpItem(user)
|
||||
|
||||
@ -5,8 +5,8 @@ import ClassSelect from "./select2.js"
|
||||
const getInitials = (name) => name.split(" ").map(e => e.charAt(0)).join("")
|
||||
const hebraList = (message) => `
|
||||
<div class="list-group-item list-group-item-action d-flex align-items-center cursor-pointer">
|
||||
<div class="avatar avatar-sm me-2">
|
||||
<span class="avatar-initial rounded-circle bg-primary" title="${message.senderFullName}">${getInitials(message.senderFullName)}</span>
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${message.user?.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
<div class="w-100 px-4">
|
||||
<div class="d-flex flex-column">
|
||||
@ -18,7 +18,7 @@ const hebraList = (message) => `
|
||||
${message.created_at}
|
||||
</p>
|
||||
<h6>
|
||||
${message.senderFullName} (${message.senderUserName})
|
||||
${message.user.first_name} ${message.user.last_name} (${message.user.username})
|
||||
</h6>
|
||||
</div>
|
||||
<p class="text-start">${message.message}</p>
|
||||
@ -27,12 +27,10 @@ const hebraList = (message) => `
|
||||
</div>
|
||||
`
|
||||
const hebraUsersList = (user) => `
|
||||
<div class="avatar avatar-md px-2 py-2" title="${user.first_name + " " + user.last_name}">
|
||||
<img src="https://gravatar.com/avatar/${user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>`
|
||||
|
||||
<div class="avatar avatar-sm me-2">
|
||||
<span class="avatar-initial rounded-circle bg-secondary" title="${user.userFullName}">${getInitials(user.userFullName)}</span>
|
||||
</div>
|
||||
|
||||
`
|
||||
class InternalMessages {
|
||||
constructor(domItem) {
|
||||
this.item = domItem
|
||||
@ -53,14 +51,14 @@ class InternalMessages {
|
||||
this.type = this.item.data("type")
|
||||
this.chatId = null
|
||||
|
||||
this.selectMessageUsers = new ClassSelect(this.selectUsers, '/chat/users/internal', "Seleccione un usuario",true)
|
||||
this.selectMessageUsers = new ClassSelect(this.selectUsers, '/chat/users/internal', "Seleccione un usuario", true)
|
||||
}
|
||||
init() {
|
||||
this.selectMessageUsers.init()
|
||||
this.item.on("click", ".btn-new-hebra", this.handleBtnNewHebra.bind(this))
|
||||
this.item.on("click", ".btn-new-hebra-message", this.handleBtnUpdateHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click","#submit_new_hebra",this.handlePostNewHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click","#submit_update_hebra",this.handleUpdateHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click", "#submit_new_hebra", this.handlePostNewHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click", "#submit_update_hebra", this.handleUpdateHebra.bind(this))
|
||||
this.handleGetInternalMessages()
|
||||
|
||||
}
|
||||
@ -75,7 +73,7 @@ class InternalMessages {
|
||||
)
|
||||
ajax.get()
|
||||
}
|
||||
handlePostNewHebra(){
|
||||
handlePostNewHebra() {
|
||||
this._handleUpdateFormNewHebraValues()
|
||||
let ajax = new Ajax(
|
||||
`/chat/hebra/${this.type}`,
|
||||
@ -87,12 +85,12 @@ class InternalMessages {
|
||||
ajax.post()
|
||||
|
||||
}
|
||||
handlePostNewHebraSuccess(data){
|
||||
handlePostNewHebraSuccess(data) {
|
||||
this.modalNewMessage.toggle()
|
||||
this.handleGetInternalMessages()
|
||||
}
|
||||
handlePostNewHebraError(err){}
|
||||
handleUpdateHebra(){
|
||||
handlePostNewHebraError(err) { }
|
||||
handleUpdateHebra() {
|
||||
this._handleUpdateFormUpdateHebraValues()
|
||||
let ajax = new Ajax(
|
||||
`/chat/hebra/${this.chatId}`,
|
||||
@ -103,11 +101,11 @@ class InternalMessages {
|
||||
)
|
||||
ajax.post()
|
||||
}
|
||||
handleUpdateNewHebraSuccess(data){
|
||||
handleUpdateNewHebraSuccess(data) {
|
||||
this.modalNewMessage.toggle()
|
||||
this.handleGetInternalMessages()
|
||||
}
|
||||
handleUpdateNewHebraError(err){}
|
||||
handleUpdateNewHebraError(err) { }
|
||||
handleBtnNewHebra(e) {
|
||||
e.preventDefault()
|
||||
this.chatId = null
|
||||
@ -137,34 +135,34 @@ class InternalMessages {
|
||||
}
|
||||
_handleUpdateFormNewHebraValues() {
|
||||
this.formNewValues = {
|
||||
title : this.hebraTitle.val(),
|
||||
title: this.hebraTitle.val(),
|
||||
users: this.selectMessageUsers.getVal(),
|
||||
message: this.textAreaMessage.val(),
|
||||
modelId : this.modelId
|
||||
modelId: this.modelId
|
||||
}
|
||||
}
|
||||
_handleUpdateFormUpdateHebraValues() {
|
||||
this.formUpdateValues = {
|
||||
users: this.selectMessageUsers.getVal(),
|
||||
message: this.textAreaMessage.val(),
|
||||
modelId : this.modelId
|
||||
modelId: this.modelId
|
||||
}
|
||||
}
|
||||
_handleGetInternalMessagesSuccess(data){
|
||||
_handleGetInternalMessagesSuccess(data) {
|
||||
Object.values(data).map((k) => {
|
||||
this._addHebraDOM(k.chatId,k.chatTitle,k.messages,k.users)
|
||||
this._addHebraDOM(k.id, k.title, k.messages, k.internalUsers)
|
||||
})
|
||||
}
|
||||
_handleGetInternalMessagesError(err){}
|
||||
_handleGetInternalMessagesError(err) { }
|
||||
|
||||
_addHebraDOM(key,chatTitle,messages,users) {
|
||||
_addHebraDOM(key, chatTitle, messages, users) {
|
||||
const itemHebra = $(`<div id="hebra-item-${key}"></div>`).addClass("border border-container flex-grow-0 container-p-y mt-4 p-5")
|
||||
const headerHebra = $("<div></div>").addClass("d-flex justify-content-between align-items-center")
|
||||
const contentHeaderHebra = $("<h4></h4>").text(`${chatTitle}`)
|
||||
const btnNewHebra = $("<button></button>").attr("type", "button").addClass("btn btn-danger btn-sm btn-new-hebra")
|
||||
btnNewHebra.append('<span class="ti-xs ti ti-git-branch"></span>')
|
||||
btnNewHebra.append("Nuevo hilo")
|
||||
headerHebra.append(contentHeaderHebra,btnNewHebra)
|
||||
headerHebra.append(contentHeaderHebra, btnNewHebra)
|
||||
itemHebra.append(headerHebra)
|
||||
let itemMessagesHebraRow = $("<div></div>").addClass("row")
|
||||
let itemMessagesHebraCol = $("<div></div>").addClass("col")
|
||||
|
||||
@ -2,12 +2,12 @@ import { showNotificationMessages } from "../components/chat.js";
|
||||
|
||||
$(() => {
|
||||
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
const chatNotificationInterval = setInterval(() => {
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
}, 10000)
|
||||
$("#message-notification-dropdown").on("click", (e) => {
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
})
|
||||
$("#btn-log-out").on("click",() => {
|
||||
clearInterval(chatNotificationInterval)
|
||||
|
||||
Reference in New Issue
Block a user