mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message client department
This commit is contained in:
@ -898,6 +898,9 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
|
||||
$routes->get('department/pedido/(:num)/(:num)', 'ChatController::get_chat_pedido/$1/$2', ['as' => 'getChatPedido']);
|
||||
$routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']);
|
||||
$routes->get('department/(:num)/users', 'ChatController::get_chat_department_users/$1', ['as' => 'getChatDepartmentUsers']);
|
||||
$routes->post('department/user', 'ChatController::subscribe_to_chat_deparment/$1', ['as' => 'subscribeToChatDepartment']);
|
||||
$routes->delete('department/user/(:num)', 'ChatController::delete_user_from_department/$1', ['as' => 'deleteUserFromDepartment']);
|
||||
|
||||
|
||||
$routes->get('(:num)', 'ChatController::get_chat/$1', ['as' => 'getChat']);
|
||||
$routes->post('message/error/presupuesto', 'ChatController::store_chat_error_message', ['as' => 'storeChatErrorMessage']);
|
||||
|
||||
@ -207,6 +207,17 @@ class ChatController extends BaseController
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
|
||||
if($cliente_in_department_count == 0){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
|
||||
}
|
||||
if($auth_user_in_department_count){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
|
||||
|
||||
}
|
||||
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
@ -228,6 +239,16 @@ class ChatController extends BaseController
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
|
||||
if($cliente_in_department_count == 0){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
|
||||
}
|
||||
if($auth_user_in_department_count){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
|
||||
|
||||
}
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
@ -249,6 +270,16 @@ class ChatController extends BaseController
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
|
||||
if($cliente_in_department_count == 0){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
|
||||
}
|
||||
if($auth_user_in_department_count){
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
|
||||
|
||||
}
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
@ -319,26 +350,30 @@ class ChatController extends BaseController
|
||||
$response = [];
|
||||
if ($cliente_id) {
|
||||
$data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
|
||||
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
|
||||
$response["totalMessages"] = 0;
|
||||
$response["chatFacturas"] = $this->chatModel->getClienteChatFacturas($data["facturas"]);
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
|
||||
foreach ($response["chatFacturas"] as $key => $value) {
|
||||
// $response["chatFacturas"] = $this->chatModel->getClienteChatFacturas($data["facturas"]);
|
||||
// foreach ($response["chatFacturas"] as $key => $value) {
|
||||
// $response["totalMessages"] += $value->unreadMessages;
|
||||
// }
|
||||
// $response["chatPresupuestos"] = $this->chatModel->getClienteChatPresupuestos($data["presupuestos"]);
|
||||
// foreach ($response["chatPresupuestos"] as $key => $value) {
|
||||
// $response["totalMessages"] += $value->unreadMessages;
|
||||
// }
|
||||
// foreach ($mensajes_directos as $value) {
|
||||
// $response["internals"][] = $value;
|
||||
// $response["totalMessages"] += $value->unreadMessages;
|
||||
// }
|
||||
// $response["chatPedidos"] = $this->chatModel->getClienteChatPedidos($data["pedidos"]);
|
||||
// foreach ($response["chatPedidos"] as $key => $value) {
|
||||
// $response["totalMessages"] += $value->unreadMessages;
|
||||
// }
|
||||
// $response["data"] = $data;
|
||||
$response["totalMessages"] = 0;
|
||||
foreach ($response["internals"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["chatPresupuestos"] = $this->chatModel->getClienteChatPresupuestos($data["presupuestos"]);
|
||||
foreach ($response["chatPresupuestos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
foreach ($mensajes_directos as $value) {
|
||||
$response["internals"][] = $value;
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["chatPedidos"] = $this->chatModel->getClienteChatPedidos($data["pedidos"]);
|
||||
foreach ($response["chatPedidos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["data"] = $data;
|
||||
} else {
|
||||
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
|
||||
$internal_notifications = $this->chatModel->getChatInternalNotifications();
|
||||
@ -800,4 +835,29 @@ class ChatController extends BaseController
|
||||
$r = $messageService->createErrorMessagePresupuesto("Error", $bodyData['presupuesto_id']);
|
||||
return $this->response->setJSON(["message" => "ok", "data" => $r]);
|
||||
}
|
||||
public function delete_user_from_department($chat_department_id)
|
||||
{
|
||||
$user_id = auth()->user()->id;
|
||||
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id);
|
||||
if($chatDepartmentUserEntity->countAllResults() > 0)
|
||||
{
|
||||
$deleted = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id)->delete();
|
||||
return $this->response->setJSON(["message" => lang('Chat.exit_chat_ok'), "status" => true]);
|
||||
}else{
|
||||
return $this->response->setJSON(["message" => lang('Chat.exit_chat_wrong'),"status" => false]);
|
||||
}
|
||||
}
|
||||
public function subscribe_to_chat_deparment()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$user_id = auth()->user()->id;
|
||||
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])->where('user_id',$user_id);
|
||||
if($chatDepartmentUserEntity->countAllResults() > 0)
|
||||
{
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'),"status" => false]);
|
||||
}else{
|
||||
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"],"user_id" => $user_id]);
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_ok'), "status" => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
ci4/app/Language/en/Chat.php
Normal file
45
ci4/app/Language/en/Chat.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"chat" => "Messages",
|
||||
"messages" => "Messages",
|
||||
"message" => "Message",
|
||||
"messages_internal" => "Internal messages",
|
||||
"message_internal" => "Internal message",
|
||||
"messages_client" => "Client messages",
|
||||
"message_client" => "Client message",
|
||||
"modal" => [
|
||||
"new_hebra" => "New thread",
|
||||
"title" => "Title",
|
||||
"new_message" => "New message",
|
||||
"new_receivers" => "New participants",
|
||||
"btn_send" => "Send",
|
||||
"btn_send_update" => "Send"
|
||||
],
|
||||
"datatable_messages" => [
|
||||
"created_at" => "Created at",
|
||||
"updated_at" => "Updated at",
|
||||
"title" => "Title",
|
||||
"creator" => "Created by",
|
||||
"viewed" => "Viewed",
|
||||
|
||||
],
|
||||
"new_message_ok" => "Message sent successfully",
|
||||
"participants" => "Participants",
|
||||
"choose_department" => "Choose a deparment",
|
||||
"new_participant" => "Add new participants",
|
||||
"write_message_placeholder" => "Type your message here ...",
|
||||
"add_notification" => "Notification",
|
||||
"check_as_unviewed" => "Check as not viewed",
|
||||
"add_notification_message" => "Add users present in this chat a notification",
|
||||
"chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]',
|
||||
"no_messages_notification" => 'There is no messages',
|
||||
"view_chat" => 'See chat',
|
||||
"view_by_alt_message" => 'Show users that has or not viewed the messages',
|
||||
"exit_chat" => 'Exit chat',
|
||||
"subscribe_chat" => 'Subscribe to chat',
|
||||
"exit_chat_ok" => "You have exit chat successfully. Notifications on this chat will no longer be received",
|
||||
"exit_chat_wrong" => "You can't exit the chat because you don't belong to it.",
|
||||
"subscribe_chat_ok" => "You've subscribed to chat successfully. Now on you'll receive notifications.",
|
||||
"subscribe_chat_wrong" => "You already belong to this chat.",
|
||||
];
|
||||
@ -35,5 +35,14 @@ return [
|
||||
"chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]',
|
||||
"no_messages_notification" => 'No hay mensajes que revisar por el momento',
|
||||
"view_chat" => 'Ver chat',
|
||||
"view_by_alt_message" => 'Muestra los usuarios que han leído o no los mensajes'
|
||||
"view_by_alt_message" => 'Muestra los usuarios que han leído o no los mensajes',
|
||||
"exit_chat" => 'Salir conversación',
|
||||
"subscribe_chat" => 'Subscribirse al chat',
|
||||
"exit_chat_ok" => "Ha salido de la conversación correctamente. No recibirá más notificaciones a no ser que sea añadido de nuevo.",
|
||||
"exit_chat_wrong" => "No puede salir de la conversación porque no pertenece a ella.",
|
||||
"subscribe_chat_ok" => "Te has subscrito al chat correctamente. Ahora recibirás notificaciones cuando lleguen mensajes.",
|
||||
"subscribe_chat_wrong" => "Ya perteneces a este chat.",
|
||||
|
||||
|
||||
|
||||
];
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-factura" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden">
|
||||
<div class="row g-0">
|
||||
|
||||
@ -30,12 +26,17 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<div class="chat-contact-list-item-title">
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
<!-- Chats -->
|
||||
<ul class="list-unstyled chat-contact-list" id="chat-list">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
|
||||
</div>
|
||||
|
||||
@ -67,11 +68,23 @@
|
||||
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
@ -82,7 +95,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-history-body bg-body ">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="sk-wave sk-primary ">
|
||||
<div class="sk-wave-rect"></div>
|
||||
<div class="sk-wave-rect"></div>
|
||||
@ -101,19 +114,15 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-pedido" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden">
|
||||
<div class="row g-0">
|
||||
|
||||
@ -30,13 +26,18 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<div class="chat-contact-list-item-title">
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
<!-- Chats -->
|
||||
<ul class="list-unstyled chat-contact-list" id="chat-list">
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- CHAT LIST -->
|
||||
|
||||
</ul>
|
||||
@ -64,11 +65,23 @@
|
||||
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
@ -79,7 +92,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-history-body bg-body ">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="sk-wave sk-primary ">
|
||||
<div class="sk-wave-rect"></div>
|
||||
<div class="sk-wave-rect"></div>
|
||||
@ -98,19 +111,14 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-presupuesto" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden border">
|
||||
<div class="row g-0">
|
||||
<!-- Chat & Contacts -->
|
||||
@ -29,6 +25,12 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<div class="chat-contact-list-item-title">
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
@ -63,15 +65,26 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -97,19 +110,14 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -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
|
||||
})
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user