message client department

This commit is contained in:
amazuecos
2025-03-16 23:13:03 +01:00
parent ed7e697d2d
commit 55157d23aa
9 changed files with 318 additions and 82 deletions

View File

@ -34,18 +34,19 @@ export const alertConfirmAction = (title, type = "primary") => {
buttonsStyling: false
})
}
export const alertSuccessMessage = (title, type = "primary") => {
export const alertSuccessMessage = (title, type = "primary", options = {}) => {
return Swal.fire({
showCancelButton: false,
showConfirmButton: false,
title: title,
text: title,
icon: "success",
timer: 2000
timer: 2000,
...options,
})
}
export const alertWarningMessage = (title, message, type = "primary") => {
export const alertWarningMessage = (title, message, type = "primary",options = {}) => {
return Swal.fire({
title: title,
text: message,
@ -70,8 +71,8 @@ export const toastPresupuestoSummary = (value, target = 'body') => {
popup: 'bg-primary text-white',
},
target: target,
width : "200px",
padding : '1px',
width: "200px",
padding: '1px',
allowEscapeKey: false,
showConfirmButton: false,
timer: 0,
@ -79,7 +80,7 @@ export const toastPresupuestoSummary = (value, target = 'body') => {
stopKeydownPropagation: false,
})
}
export const alertSuccess = (value, target = 'body') => {
export const alertSuccess = (value, target = 'body',options = {}) => {
return Swal.mixin({
toast: true,
position: 'bottom-end',
@ -87,15 +88,16 @@ export const alertSuccess = (value, target = 'body') => {
customClass: {
popup: 'bg-success text-white',
},
icon : 'success',
icon: 'success',
iconColor: 'white',
target: target,
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
...options,
})
}
export const alertError = (value, target = 'body') => {
export const alertError = (value, target = 'body',options = {}) => {
return Swal.mixin({
toast: true,
position: 'bottom-end',
@ -103,15 +105,16 @@ export const alertError = (value, target = 'body') => {
customClass: {
popup: 'bg-danger text-white',
},
icon : 'error',
icon: 'error',
iconColor: 'white',
target: target,
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
...options
})
}
export const alertWarning = (value, target = 'body') => {
export const alertWarning = (value, target = 'body',options = {}) => {
return Swal.mixin({
toast: true,
position: 'bottom-end',
@ -119,11 +122,12 @@ export const alertWarning = (value, target = 'body') => {
customClass: {
popup: 'bg-warning text-white',
},
icon : 'warning',
icon: 'warning',
iconColor: 'white',
target: target,
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
...options
})
}

View File

@ -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"
class Chat {
@ -16,10 +16,13 @@ class Chat {
this.chatSidebarLeftUserAbout = this.domItem.find('.chat-sidebar-left-user-about'),
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")
this.btnSubscribeChat = this.domItem.find(".subscribe-chat")
this.chatDeparmentId = undefined
this.searchInput = this.domItem.find(".chat-search-input")
this.headers = {}
this.chatContactsBody = this.domItem.find('.app-chat-contacts .sidebar-body')
this.chatContactListItems = [].slice.call(
document.querySelectorAll('.chat-contact-list-item:not(.chat-contact-list-item-title)')
@ -52,6 +55,9 @@ class Chat {
}
this.sendBtnMessageDepartment.addClass("d-none")
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]) {
this.scrollbarContacts = new PerfectScrollbar(this.chatContactsBody[0], {
@ -69,6 +75,7 @@ class Chat {
}
}
initDirectMessage() {
this.chatType = "direct"
this.modalNewParticipant = new Modal(this.domItem.find("#modalAddNewChatParticipant"))
this.selectPlaceholder = {
@ -103,6 +110,19 @@ class Chat {
this._handleGetChatDirect()
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)
this.selectClientUser.init()
this.selectItem.on('change',() => {
if(this.selectClientUser.getVal()){
this.sendBtnMessageDepartment.attr('disabled',null)
}else{
this.sendBtnMessageDepartment.attr('disabled','disabled')
}
})
}
initGeneral() {
this.chatType = "general"
this._handleGetChatList()
@ -113,6 +133,8 @@ class Chat {
this._handleGetChatList()
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
this.initSelectClient()
}
@ -121,6 +143,8 @@ class Chat {
this._handleGetChatList()
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
this.initSelectClient()
}
initFactura() {
@ -128,6 +152,8 @@ class Chat {
this._handleGetChatList()
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
this.initSelectClient()
}
initContacts() {
@ -398,6 +424,7 @@ class Chat {
message: messageText,
chat_department_id: this.chatDeparmentId,
user: this.userId,
client : this.selectClientUser.getVal(),
model_id: this.modelId
}
if (messageText) {
@ -712,7 +739,70 @@ class Chat {
this._handleReloadChatDirectMessages();
}
_handleUpdateChatMessagesUnreadError(){}
_handleRequestExitChatDeparment()
{
const ajax = new Ajax('/chat/department/user/'+this.chatDeparmentId,
null,
null,
(response) => {
if(response.status){
alertSuccess(response.message).fire()
this._getChatDeparmentUsers()
}else{
alertError(response.message).fire()
}
},
(error) => {
alertError("Error")
}
)
ajax.delete();
}
_handleRequestSubscribeChatDeparment()
{
const ajax = new Ajax('/chat/department/user',
{
chat_department_id : this.chatDeparmentId
},
null,
(response) => {
if(response.status){
alertSuccess(response.message).fire()
this._getChatDeparmentUsers()
}else{
alertError(response.message).fire()
}
},
(error) => {
alertError("Error")
}
)
ajax.post();
}
_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()
}
})
}
}