mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
add client to chat
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import Ajax from '../components/ajax.js'
|
||||
import Modal from './modal.js'
|
||||
import ClassSelect from './select2.js'
|
||||
import {alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess} from "./alerts/sweetAlert.js"
|
||||
import { alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess } from "./alerts/sweetAlert.js"
|
||||
|
||||
|
||||
class Chat {
|
||||
@ -14,7 +14,7 @@ class Chat {
|
||||
this.sendBtnMessageDepartment = this.domItem.find("#send-msg-btn-deparment")
|
||||
this.sendBtnMessageInternal = this.domItem.find("#send-msg-btn-internal")
|
||||
this.chatSidebarLeftUserAbout = this.domItem.find('.chat-sidebar-left-user-about'),
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.sideBar = this.domItem.find(".sidebar-body")
|
||||
this.selectItem = this.domItem.find(".chat-search-client")
|
||||
this.btnExitChat = this.domItem.find(".exit-chat")
|
||||
@ -55,8 +55,8 @@ class Chat {
|
||||
}
|
||||
|
||||
this.sendBtnMessageDepartment.addClass("d-none")
|
||||
this.btnExitChat.on('click',this._handleExitChatDepartment.bind(this))
|
||||
this.btnSubscribeChat.on('click',this._handleSubscribeChatDepartment.bind(this))
|
||||
this.btnExitChat.on('click', this._handleExitChatDepartment.bind(this))
|
||||
this.btnSubscribeChat.on('click', this._handleSubscribeChatDepartment.bind(this))
|
||||
|
||||
this.sendBtnMessageInternal.addClass("d-none")
|
||||
if (this.chatContactsBody[0]) {
|
||||
@ -98,7 +98,7 @@ class Chat {
|
||||
this.selectParticipants.init()
|
||||
this.modalNewParticipant.toggle()
|
||||
})
|
||||
|
||||
|
||||
this.selectParticipants.item.on("change", () => {
|
||||
if (this.selectParticipants.getVal().length > 0) {
|
||||
this.btnAddParticipantSubmit.removeClass("d-none")
|
||||
@ -106,19 +106,18 @@ class Chat {
|
||||
this.btnAddParticipantSubmit.addClass("d-none")
|
||||
}
|
||||
})
|
||||
this.btnUpdateMessagesUnviewed.on("click",this._handleUpdateChatMessagesUnread.bind(this))
|
||||
this.btnUpdateMessagesUnviewed.on("click", this._handleUpdateChatMessagesUnread.bind(this))
|
||||
this._handleGetChatDirect()
|
||||
setInterval(this._handleReloadChatDirectMessages.bind(this),10000)
|
||||
setInterval(this._handleReloadChatDirectMessages.bind(this), 10000)
|
||||
}
|
||||
initSelectClient()
|
||||
{
|
||||
this.selectClientUser = new ClassSelect(this.selectItem,`/chat/direct/client/users/select/${this.chatType}/${this.modelId}`,"Seleccione contacto",true)
|
||||
initSelectClient() {
|
||||
this.selectClientUser = new ClassSelect(this.selectItem, `/chat/direct/client/users/select/${this.chatType}/${this.modelId}`, "Seleccione contacto", true)
|
||||
this.selectClientUser.init()
|
||||
this.selectItem.on('change',() => {
|
||||
if(this.selectClientUser.getVal()){
|
||||
this.sendBtnMessageDepartment.attr('disabled',null)
|
||||
}else{
|
||||
this.sendBtnMessageDepartment.attr('disabled','disabled')
|
||||
this.selectItem.on('change', () => {
|
||||
if (this.selectClientUser.getVal()) {
|
||||
this.sendBtnMessageDepartment.attr('disabled', null)
|
||||
} else {
|
||||
this.sendBtnMessageDepartment.attr('disabled', 'disabled')
|
||||
}
|
||||
})
|
||||
|
||||
@ -228,7 +227,7 @@ class Chat {
|
||||
this.domItem.find("#chat-header-users").empty()
|
||||
this.domItem.find("#chat-header-dropdown-users").removeClass("d-none")
|
||||
let ajax = new Ajax(
|
||||
`/chat/department/${this.chatDeparmentId}/users`,
|
||||
`/chat/department/users/${this.chatType}/${this.chatDeparmentId}/${this.modelId}`,
|
||||
null,
|
||||
null,
|
||||
this._getChatDeparmentUsersSuccess.bind(this),
|
||||
@ -238,31 +237,34 @@ class Chat {
|
||||
ajax.get()
|
||||
}
|
||||
_getChatDeparmentUsersSuccess(deparmentUsers) {
|
||||
deparmentUsers.map((user) => {
|
||||
this.domItem.find("#chat-header-users").append(
|
||||
`
|
||||
<li class="chat-contact-list-item p-1">
|
||||
<a class="d-flex align-items-center py-1"
|
||||
id="chat-contact-list-item-${user.id}">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">
|
||||
${user?.first_name?.charAt(0) ?? "?"
|
||||
+ user?.last_name?.charAt(0) ?? "?"}</span>
|
||||
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
|
||||
user?.last_name ?? ""}</h6>
|
||||
<p class="chat-contact-status text-muted text-truncate mb-0">
|
||||
${user.username}
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
deparmentUsers.admin_users.map(user => this.appendChatDepartmentUser(user))
|
||||
deparmentUsers.external_users.map(user => this.appendChatDepartmentUser(user, 'warning', 'user'))
|
||||
|
||||
}
|
||||
appendChatDepartmentUser(user, color = "primary", icon = "user") {
|
||||
this.domItem.find("#chat-header-users").append(
|
||||
`
|
||||
)
|
||||
})
|
||||
<li class="chat-contact-list-item p-1">
|
||||
<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>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
|
||||
user?.last_name ?? ""}</h6>
|
||||
<p class="chat-contact-status text-muted text-truncate mb-0">
|
||||
${user.username}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
`
|
||||
)
|
||||
}
|
||||
_getChatDeparmentUsersError(err) { }
|
||||
|
||||
@ -424,7 +426,7 @@ class Chat {
|
||||
message: messageText,
|
||||
chat_department_id: this.chatDeparmentId,
|
||||
user: this.userId,
|
||||
client : this.selectClientUser.getVal(),
|
||||
client: this.selectClientUser.getVal(),
|
||||
model_id: this.modelId
|
||||
}
|
||||
if (messageText) {
|
||||
@ -442,6 +444,7 @@ class Chat {
|
||||
_sendMessageSuccess(data) {
|
||||
this.messageInput.val("")
|
||||
this._getChatMessage(this.chatDeparmentId)
|
||||
this._getChatDeparmentUsers()
|
||||
}
|
||||
_sendMessageError(err) {
|
||||
console.error(err)
|
||||
@ -674,7 +677,7 @@ class Chat {
|
||||
}
|
||||
_handleReloadChatDirectMessagesError(error) { }
|
||||
_handleStoreChatDirectUsers() {
|
||||
const data = { "users": this.selectParticipants.getVal() ,"notification" : this.checkboxNotificationMessage.prop("checked")}
|
||||
const data = { "users": this.selectParticipants.getVal(), "notification": this.checkboxNotificationMessage.prop("checked") }
|
||||
this.domItem.find(".chat-loader").removeClass("d-none")
|
||||
|
||||
const ajax = new Ajax(
|
||||
@ -716,7 +719,7 @@ class Chat {
|
||||
this._addChatDirectMessages(message)
|
||||
this.messageInput.val("")
|
||||
} catch (error) {
|
||||
|
||||
|
||||
} finally {
|
||||
this.scrollbarChatHistory.update()
|
||||
this.chatHistoryBody[0].scrollTop = this.scrollbarChatHistory.containerHeight
|
||||
@ -735,20 +738,22 @@ class Chat {
|
||||
)
|
||||
ajax.post()
|
||||
}
|
||||
_handleUpdateChatMessagesUnreadSuccess(){
|
||||
_handleUpdateChatMessagesUnreadSuccess() {
|
||||
this._handleReloadChatDirectMessages();
|
||||
}
|
||||
_handleUpdateChatMessagesUnreadError(){}
|
||||
_handleRequestExitChatDeparment()
|
||||
{
|
||||
const ajax = new Ajax('/chat/department/user/'+this.chatDeparmentId,
|
||||
null,
|
||||
_handleUpdateChatMessagesUnreadError() { }
|
||||
_handleRequestExitChatDeparment() {
|
||||
const ajax = new Ajax('/chat/department/user/' + this.chatDeparmentId,
|
||||
{
|
||||
model_fk: this.chatType,
|
||||
model_id_fk: this.modelId
|
||||
},
|
||||
null,
|
||||
(response) => {
|
||||
if(response.status){
|
||||
if (response.status) {
|
||||
alertSuccess(response.message).fire()
|
||||
this._getChatDeparmentUsers()
|
||||
}else{
|
||||
} else {
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
},
|
||||
@ -759,18 +764,19 @@ class Chat {
|
||||
)
|
||||
ajax.delete();
|
||||
}
|
||||
_handleRequestSubscribeChatDeparment()
|
||||
{
|
||||
_handleRequestSubscribeChatDeparment() {
|
||||
const ajax = new Ajax('/chat/department/user',
|
||||
{
|
||||
chat_department_id : this.chatDeparmentId
|
||||
chat_department_id: this.chatDeparmentId,
|
||||
model_fk: this.chatType,
|
||||
model_id_fk: this.modelId
|
||||
},
|
||||
null,
|
||||
(response) => {
|
||||
if(response.status){
|
||||
if (response.status) {
|
||||
alertSuccess(response.message).fire()
|
||||
this._getChatDeparmentUsers()
|
||||
}else{
|
||||
} else {
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
},
|
||||
@ -781,27 +787,23 @@ class Chat {
|
||||
)
|
||||
ajax.post();
|
||||
}
|
||||
_handleExitChatDepartment()
|
||||
{
|
||||
if(this.chatDeparmentId)
|
||||
{
|
||||
alertConfirmationDelete('¿Estás seguro de salir de la conversación?').then((result) => {
|
||||
if(result.isConfirmed){
|
||||
this._handleRequestExitChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
_handleExitChatDepartment() {
|
||||
if (this.chatDeparmentId) {
|
||||
alertConfirmationDelete('¿Estás seguro de salir de la conversación?').then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this._handleRequestExitChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
_handleSubscribeChatDepartment()
|
||||
{
|
||||
if(this.chatDeparmentId)
|
||||
{
|
||||
alertConfirmAction('¿Estás seguro de subscribirte al chat?').then((result) => {
|
||||
if(result.isConfirmed){
|
||||
this._handleRequestSubscribeChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
_handleSubscribeChatDepartment() {
|
||||
if (this.chatDeparmentId) {
|
||||
alertConfirmAction('¿Estás seguro de subscribirte al chat?').then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this._handleRequestSubscribeChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user