terminado

This commit is contained in:
2025-02-19 21:35:55 +01:00
parent fea409b5ad
commit b6decf8657
6 changed files with 195 additions and 121 deletions

View File

@ -48,7 +48,7 @@ class Email extends BaseConfig
/** /**
* SMTP Timeout (in seconds) * SMTP Timeout (in seconds)
*/ */
public int $SMTPTimeout = 5; public int $SMTPTimeout = 15;
/** /**
* Enable persistent SMTP connections * Enable persistent SMTP connections

View File

@ -58,14 +58,14 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
return view(static::$viewPath . 'viewTicketList', $viewData); return view(static::$viewPath . 'viewTicketList', $viewData);
} }
private function sendMail($subject,$body,$recipient) private function sendMail($subject, $body, $recipient)
{ {
$settings_model = new SettingsModel(); $settings_model = new SettingsModel();
$config = $settings_model->first()->toArray(); $config = $settings_model->first()->toArray();
$gateway = $config['email_gateway']; $gateway = $config['email_gateway'];
$body = html_entity_decode($body); $body = html_entity_decode($body);
if($gateway == 'smtp'){ if ($gateway == 'smtp') {
try { try {
//https://codeigniter.com/user_guide/libraries/email.html //https://codeigniter.com/user_guide/libraries/email.html
$email = \Config\Services::email(); $email = \Config\Services::email();
@ -74,23 +74,22 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$config['SMTPUser'] = $config['email_address']; $config['SMTPUser'] = $config['email_address'];
$config['SMTPPass'] = $config['email_pass']; $config['SMTPPass'] = $config['email_pass'];
$config['SMTPPort'] = intval($config['email_port']); $config['SMTPPort'] = intval($config['email_port']);
$config['SMTPCrypto'] = $config['email_cert']=='none'?'':$config['email_cert']; $config['SMTPCrypto'] = $config['email_cert'] == 'none' ? '' : $config['email_cert'];
$config['SMTPTimeout'] = 15; $config['SMTPTimeout'] = 15;
$config['mailType'] = 'html'; $config['mailType'] = 'html';
$config['wordWrap'] = true; $config['wordWrap'] = true;
$email->initialize($config); $email->initialize($config);
$email->setFrom($config['email_address'], $config['email_name']); $email->setFrom($config['email_address'], $config['email_name']);
$email->setTo($recipient); $email->setTo($recipient);
$email->setSubject($subject); $email->setSubject($subject);
$email->setMessage($body); $email->setMessage($body);
if (!$email->send()) if (!$email->send()) {
{
return false; return false;
}else{ } else {
return true; return true;
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
@ -105,7 +104,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
//checkPermission('tickets.create', $this->indexRoute); //checkPermission('tickets.create', $this->indexRoute);
if ($this->request->getPost()) : if ($this->request->getPost()):
$nullIfEmpty = false; // !(phpversion() >= '8.1'); $nullIfEmpty = false; // !(phpversion() >= '8.1');
@ -118,10 +117,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()):
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -135,7 +134,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult):
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
@ -145,10 +144,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$userModel = new \App\Models\UserModel(); $userModel = new \App\Models\UserModel();
$this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email); $this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email);
if ($thenRedirect) : if ($thenRedirect):
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)):
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
else: else:
return $this->redirect2listView('successMessage', $message); return $this->redirect2listView('successMessage', $message);
@ -181,51 +180,63 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
{ {
$modelRespuesta = new \App\Models\Soporte\TicketRespuestaModel(); $modelRespuesta = new \App\Models\Soporte\TicketRespuestaModel();
if ($requestedId == null) : if ($requestedId == null):
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL); $id = filter_var($requestedId, FILTER_SANITIZE_URL);
$ticket = $this->model->find($id); $ticket = $this->model->find($id);
if ($ticket == false) : if ($ticket == false):
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tickets.ticket')), $id]); $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tickets.ticket')), $id]);
return $this->redirect2listView('errorMessage', $message); return $this->redirect2listView('errorMessage', $message);
endif; endif;
if(!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id){ if (!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id) {
return redirect()->to(route_to('TicketIndex'))->with('errorMessage', lang('Basic.global.noPermission')); return redirect()->to(route_to('TicketIndex'))->with('errorMessage', lang('Basic.global.noPermission'));
} }
if ($this->request->getPost()) : if ($this->request->getPost()):
$oldUserSupport = $ticket->user_soporte_id;
$oldState = $ticket->estado_id;
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, false); $sanitizedData = $this->sanitized($postData, false);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()):
try { try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
$this->saveImages($id, $this->request->getFiles()); $this->saveImages($id, $this->request->getFiles());
if(auth()->user()->can('Tickets.edit')){ if (auth()->user()->can('Tickets.edit')) {
$respuesta = $modelRespuesta->where('ticket_id', $id)->first(); $respuesta = $modelRespuesta->where('ticket_id', $id)->first();
if($respuesta == null){ if ($respuesta == null) {
$modelRespuesta->insert([ $modelRespuesta->insert([
'ticket_id' => $id, 'ticket_id' => $id,
'usuario_id' => auth()->user()->id, 'usuario_id' => auth()->user()->id,
'mensaje' => $sanitizedData['respuesta_mensaje'] 'mensaje' => $sanitizedData['respuesta_mensaje']
]); ]);
}else{ } else {
$modelRespuesta->update($respuesta->id, [ $modelRespuesta->update($respuesta->id, [
'mensaje' => $sanitizedData['respuesta_mensaje'], 'mensaje' => $sanitizedData['respuesta_mensaje'],
'usuario_id' => auth()->user()->id, 'usuario_id' => auth()->user()->id,
]); ]);
} }
// envio de correos
$userModel = new \App\Models\UserModel();
if ($oldUserSupport != $sanitizedData['supportUser']) {
$this->sendMail(lang('Tickets.asgignToChanged'), lang('Tickets.asgignToChangedBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email);
}
if ($oldState != $sanitizedData['estado_id']) {
$this->sendMail(lang('Tickets.stateChange'), lang('Tickets.stateChangeBody') . base_url(route_to('editTicket', $id)), $userModel->find($ticket->usuario_id)->email);
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {
@ -242,12 +253,12 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$thenRedirect = false; $thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult):
$id = $ticket->id ?? $id; $id = $ticket->id ?? $id;
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) : if ($thenRedirect):
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)):
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
else: else:
return $this->redirect2listView('successMessage', $message); return $this->redirect2listView('successMessage', $message);
@ -295,9 +306,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
$searchValues = get_filter_datatables_columns($reqData); $searchValues = get_filter_datatables_columns($reqData);
if(auth()->user()->can('tickets.edit')){ if (auth()->user()->can('tickets.edit')) {
$user_id = null; $user_id = null;
}else{ } else {
$user_id = auth()->user()->id; $user_id = auth()->user()->id;
} }
@ -359,9 +370,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
// Guardar en la base de datos // Guardar en la base de datos
$fileModel->insert([ $fileModel->insert([
'nombre' => $originalName, 'nombre' => $originalName,
'ticket_id' => $ticket_id, 'ticket_id' => $ticket_id,
'hash' => $fileHash, 'hash' => $fileHash,
'path' => 'uploads/tickets/' . $newFileName 'path' => 'uploads/tickets/' . $newFileName
]); ]);
} }
} }

View File

@ -49,5 +49,9 @@ return [
// Mail // Mail
'newTicket' => 'Nuevo Ticket en ERP Safekat', 'newTicket' => 'Nuevo Ticket en ERP Safekat',
'stateChange' => 'Cambio de estado en ticket en ERP Safekat',
'asgignToChanged' => 'Asignado ticket en ERP Safekat',
'newTicketBody' => '<p>Se ha creado un nuevo ticket en el sistema de soporte de Safekat ERP. <br><br>Puede verlo en el siguiente enlace:</p>', 'newTicketBody' => '<p>Se ha creado un nuevo ticket en el sistema de soporte de Safekat ERP. <br><br>Puede verlo en el siguiente enlace:</p>',
'stateChangeBody' => '<p>El estado de un ticket en el sistema de soporte de Safekat ERP ha cambiado. <br><br>Puede verlo en el siguiente enlace:</p>',
'asgignToChangedBody' => '<p>Se le ha asignado un ticket en el sistema de soporte de Safekat ERP. <br><br>Puede verlo en el siguiente enlace:</p>',
]; ];

View File

@ -8,7 +8,7 @@ class TicketModel extends \App\Models\BaseModel
protected $table = 'tickets'; protected $table = 'tickets';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $allowedFields = ['usuario_id', 'user_soporte_id', 'seccion_id' ,'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at']; protected $allowedFields = ['usuario_id', 'user_soporte_id', 'seccion_id', 'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at'];
protected $useTimestamps = true; protected $useTimestamps = true;
@ -29,8 +29,8 @@ class TicketModel extends \App\Models\BaseModel
public function getEstados() public function getEstados()
{ {
$values = $this->db->table('tickets_estados')->get()->getResultArray(); $values = $this->db->table('tickets_estados')->get()->getResultArray();
for($i = 0; $i < count($values); $i++){ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']); $values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
} }
@ -40,8 +40,8 @@ class TicketModel extends \App\Models\BaseModel
public function getCategorias() public function getCategorias()
{ {
$values = $this->db->table('tickets_categorias')->get()->getResultArray(); $values = $this->db->table('tickets_categorias')->get()->getResultArray();
for($i = 0; $i < count($values); $i++){ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']); $values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
} }
@ -52,7 +52,7 @@ class TicketModel extends \App\Models\BaseModel
{ {
$values = $this->db->table('tickets_secciones')->get()->getResultArray(); $values = $this->db->table('tickets_secciones')->get()->getResultArray();
for($i = 0; $i < count($values); $i++){ for ($i = 0; $i < count($values); $i++) {
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']); $values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
} }
@ -100,13 +100,44 @@ class TicketModel extends \App\Models\BaseModel
else { else {
$builder->groupStart(); $builder->groupStart();
foreach ($search as $col_search) { foreach ($search as $col_search) {
if ($col_search[0] > 0 && $col_search[0] < 4) if ($col_search[1] == "seccion_id") {
$builder->where(self::SORTABLE[$col_search[0]], $col_search[2]); $id = $this->getIdFromKeyword("tickets_secciones", $col_search[2]);
$builder->where("t1." . $col_search[1], $id);
} else if ($col_search[1] == "categoria_id") {
$id = $this->getIdFromKeyword("tickets_categorias", $col_search[2]);
$builder->where("t1." . $col_search[1], $id);
} else if ($col_search[1] == "estado_id") {
$id = $this->getIdFromKeyword("tickets_estados", $col_search[2]);
$builder->where("t1." . $col_search[1], $id);
} else if ($col_search[1] == "prioridad") {
$builder->where("t1." . $col_search[1], $col_search[2]);
} else if ($col_search[1] == "created_at") {
$dates = explode(" ", $col_search[2]);
$builder->where("t1." . $col_search[1] . ">=", $dates[0]);
$builder->where("t1." . $col_search[1] . "<=", $dates[1]);
} else if ($col_search[1] == "usuario_id") {
$builder->like("t2.first_name", $col_search[2]);
$builder->orLike("t2.last_name", $col_search[2]);
} else if ($col_search[1] == "user_soporte_id") {
$builder->like("t6.first_name", $col_search[2]);
$builder->orLike("t6.last_name", $col_search[2]);
}
else else
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]); $builder->like("t1." . $col_search[1], $col_search[2]);
} }
$builder->groupEnd(); $builder->groupEnd();
return $builder; return $builder;
} }
} }
private function getIdFromKeyword($table, $keyword)
{
$subquery = $this->db->table($table)
->select('id')
->where('keyword', $keyword)
->get()
->getRow();
return $subquery->id;
}
} }

View File

@ -21,12 +21,16 @@
<th><?= lang('Tickets.tipo') ?></th> <th><?= lang('Tickets.tipo') ?></th>
<th><?= lang('Tickets.seccion') ?></th> <th><?= lang('Tickets.seccion') ?></th>
<th><?= lang('Tickets.estado') ?></th> <th><?= lang('Tickets.estado') ?></th>
<th style="display: none;"><?= lang('Tickets.prioridad') ?></th> <?php if ($userType == 1) : ?>
<th><?= lang('Tickets.prioridad') ?></th>
<?php endif; ?>
<th><?= lang('Tickets.asunto') ?></th> <th><?= lang('Tickets.asunto') ?></th>
<th style="display: none;"><?= lang('Tickets.usuario') ?></th> <?php if ($userType == 1) : ?>
<th style="display: none;"><?= lang('Tickets.asignarTo') ?></th> <th><?= lang('Tickets.usuario') ?></th>
<th><?= lang('Tickets.asignarTo') ?></th>
<?php endif; ?>
<th><?= lang('Tickets.fechaCreacion') ?></th> <th><?= lang('Tickets.fechaCreacion') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th> <th class="text-nowrap noFilter"><?= lang('Basic.global.Action') ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -45,6 +49,7 @@
<?= $this->section('css') ?> <?= $this->section('css') ?>
<link rel="stylesheet" <link rel="stylesheet"
href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>"> href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css') ?>" />
<?= $this->endSection() ?> <?= $this->endSection() ?>
@ -65,6 +70,7 @@
crossorigin="anonymous" referrerpolicy="no-referrer"></script> crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script> <script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.colVis.min.js") ?>"></script> <script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.colVis.min.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/soporte/tickets.js') ?>"></script> <script type="module" src="<?= site_url('assets/js/safekat/pages/soporte/tickets.js') ?>"></script>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -38,55 +38,81 @@ class Ticket {
#initDatatable() { #initDatatable() {
this.#headerSearcher();
const self = this; const self = this;
self.#headerSearcher();
const actions = ['view']; const actions = ['view'];
const columns = [
{ 'data': 'id' }, let columns = [];
{ if (window.userType == 1) {
'data': 'categoria_id', columns = [
render: function (data, type, row) { { 'data': 'id' },
return window.language.Tickets[row.categoria]; {
} 'data': 'categoria_id',
}, render: function (data, type, row) {
{ return window.language.Tickets[row.categoria];
'data': 'seccion_id', }
render: function (data, type, row) {
return window.language.Tickets[row.seccion];
}
},
{
'data': 'estado_id',
render: function (data, type, row) {
return window.language.Tickets[row.estado];
}
},
{
'data': 'prioridad',
render: function (data, type, row) {
return window.language.Tickets[data];
}, },
visible: false, {
}, 'data': 'seccion_id',
{ 'data': 'titulo' }, render: function (data, type, row) {
{ return window.language.Tickets[row.seccion];
'data': 'usuario_id', }
render: function (data, type, row) {
return row.usuario;
}, },
visible: false, {
}, 'data': 'estado_id',
{ render: function (data, type, row) {
'data': 'user_soporte_id', return window.language.Tickets[row.estado];
render: function (data, type, row) { }
return row.user_soporte;
}, },
visible: false, {
}, 'data': 'prioridad',
{ 'data': 'created_at' }, render: function (data, type, row) {
]; return window.language.Tickets[data];
},
},
{ 'data': 'titulo' },
{
'data': 'usuario_id',
render: function (data, type, row) {
return row.usuario;
},
},
{
'data': 'user_soporte_id',
render: function (data, type, row) {
return row.user_soporte;
},
},
{ 'data': 'created_at' },
];
}
else {
columns = [
{ 'data': 'id' },
{
'data': 'categoria_id',
render: function (data, type, row) {
return window.language.Tickets[row.categoria];
}
},
{
'data': 'seccion_id',
render: function (data, type, row) {
return window.language.Tickets[row.seccion];
}
},
{
'data': 'estado_id',
render: function (data, type, row) {
return window.language.Tickets[row.estado];
}
},
{ 'data': 'titulo' },
{ 'data': 'created_at' },
];
}
this.table = new Table( this.table = new Table(
@ -103,17 +129,10 @@ class Ticket {
}); });
this.table.table.on('init.dt', function () { this.table.table.on('init.dt', function () {
self.table.table.page.len(50).draw();
if (window.userType == 1) {
self.table.table.column(4).visible(true); self.table.table.page.len(100).draw();
self.table.table.column(6).visible(true); self.table.table.draw();
self.table.table.column(7).visible(true);
self.table.table.column(4).header().style.display = 'table-cell';
self.table.table.column(6).header().style.display = 'table-cell';
self.table.table.column(7).header().style.display = 'table-cell';
}
}); });
this.table.setEditCallback(function (id) { this.table.setEditCallback(function (id) {
@ -124,11 +143,14 @@ class Ticket {
#headerSearcher() { #headerSearcher() {
const self = this; const self = this;
$('#tableOfTickets thead tr').clone(true).appendTo('#tableOfTickets thead'); $('#tableOfTickets thead tr.search-header').remove();
let searchRow = $('#tableOfTickets thead tr').first().clone(true);
searchRow.addClass('search-header').appendTo('#tableOfTickets thead');
$('#tableOfTickets thead tr:eq(1) th').each(function (i) { $('#tableOfTickets thead tr:eq(1) th').each(function (i) {
if (!$(this).hasClass("noFilter")) { if (!$(this).hasClass("noFilter")) {
var title = $(this).text(); var title = $(this).text();
if (i == 8) { if (title == window.language.Tickets.fechaCreacion) {
$(this).html('<input id="bs-rangepicker-range" type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />'); $(this).html('<input id="bs-rangepicker-range" type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
var bsRangePickerRange = $('#bs-rangepicker-range') var bsRangePickerRange = $('#bs-rangepicker-range')
@ -142,13 +164,13 @@ class Ticket {
[window.language.datePicker.ultimoMes]: [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] [window.language.datePicker.ultimoMes]: [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}, },
opens: 'right', opens: 'right',
language: '<?= config('Basics')->i18n ?>', language: $('html').attr('lang'),
"locale": { "locale": {
"customRangeLabel": "<?= lang('datePicker.personalizar') ?>", "customRangeLabel": window.language.datePicker.personalizar,
"format": "YYYY-MM-DD", "format": "YYYY-MM-DD",
"separator": " ", "separator": " ",
"applyLabel": "<?= lang('datePicker.aplicar') ?>", "applyLabel": window.language.datePicker.aplicar,
"cancelLabel": "<?= lang('datePicker.limpiar') ?>", "cancelLabel": window.language.datePicker.limpiar,
}, },
"alwaysShowCalendars": true, "alwaysShowCalendars": true,
@ -158,7 +180,7 @@ class Ticket {
bsRangePickerRange.on('apply.daterangepicker', function (ev, picker) { bsRangePickerRange.on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD')); $(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD'));
self.table self.table.table
.column(i) .column(i)
.search(this.value) .search(this.value)
.draw(); .draw();
@ -166,14 +188,14 @@ class Ticket {
bsRangePickerRange.on('cancel.daterangepicker', function (ev, picker) { bsRangePickerRange.on('cancel.daterangepicker', function (ev, picker) {
$(this).val(''); $(this).val('');
self.table self.table.table
.column(i) .column(i)
.search(this.value) .search(this.value)
.draw(); .draw();
}); });
} }
else if (i == 1) { else if (title == window.language.Tickets.tipo) {
// Agregar un selector en la tercera columna // Agregar un selector en la tercera columna
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>'); $(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -188,11 +210,11 @@ class Ticket {
var val = $.fn.dataTable.util.escapeRegex( var val = $.fn.dataTable.util.escapeRegex(
$(this).val() $(this).val()
); );
self.table.column(i).search(val).draw(); self.table.table.column(i).search(val).draw();
}); });
} }
else if (i == 2) { else if (title == window.language.Tickets.seccion) {
// Agregar un selector en la tercera columna // Agregar un selector en la tercera columna
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>'); $(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -210,10 +232,10 @@ class Ticket {
var val = $.fn.dataTable.util.escapeRegex( var val = $.fn.dataTable.util.escapeRegex(
$(this).val() $(this).val()
); );
self.table.column(i).search(val).draw(); self.table.table.column(i).search(val).draw();
}); });
} }
else if (i == 2) { else if (title == window.language.Tickets.estado) {
// Agregar un selector en la tercera columna // Agregar un selector en la tercera columna
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>'); $(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -223,15 +245,15 @@ class Ticket {
selectorEstado.append('<option value="abierto">' + window.language.Tickets.abierto + '</option>'); selectorEstado.append('<option value="abierto">' + window.language.Tickets.abierto + '</option>');
selectorEstado.append('<option value="en_proceso">' + window.language.Tickets.en_proceso + '</option>'); selectorEstado.append('<option value="en_proceso">' + window.language.Tickets.en_proceso + '</option>');
selectorEstado.append('<option value="resuelto">' + window.language.Tickets.resuelto + '</option>'); selectorEstado.append('<option value="resuelto">' + window.language.Tickets.resuelto + '</option>');
selectorEstado.on('change', function () { selectorEstado.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex( var val = $.fn.dataTable.util.escapeRegex(
$(this).val() $(this).val()
); );
self.table.column(i).search(val).draw(); self.table.table.column(i).search(val).draw();
}); });
} }
else if (i == 8) { else if (title == window.language.Tickets.prioridad) {
// Agregar un selector en la tercera columna // Agregar un selector en la tercera columna
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>'); $(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
@ -241,20 +263,20 @@ class Ticket {
selectorPrioridad.append('<option value="baja">' + window.language.Tickets.baja + '</option>'); selectorPrioridad.append('<option value="baja">' + window.language.Tickets.baja + '</option>');
selectorPrioridad.append('<option value="media">' + window.language.Tickets.media + '</option>'); selectorPrioridad.append('<option value="media">' + window.language.Tickets.media + '</option>');
selectorPrioridad.append('<option value="baja">' + window.language.Tickets.alta + '</option>'); selectorPrioridad.append('<option value="baja">' + window.language.Tickets.alta + '</option>');
selectorPrioridad.on('change', function () { selectorPrioridad.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex( var val = $.fn.dataTable.util.escapeRegex(
$(this).val() $(this).val()
); );
self.table.column(i).search(val).draw(); self.table.table.column(i).search(val).draw();
}); });
} }
else { else {
$(this).html('<input type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />'); $(this).html('<input type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
$('input', this).on('change clear', function () { $('input', this).on('change clear', function () {
if (self.table.column(i).search() !== this.value) { if (self.table.table.column(i).search() !== this.value) {
self.table self.table.table
.column(i) .column(i)
.search(this.value) .search(this.value)
.draw(); .draw();
@ -273,7 +295,7 @@ document.addEventListener('DOMContentLoaded', function () {
const locale = document.querySelector('meta[name="locale"]').getAttribute('content'); const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Tickets, datePicker'] }, {}, new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Tickets', 'datePicker'] }, {},
function (translations) { function (translations) {
window.language = JSON.parse(translations); window.language = JSON.parse(translations);
new Ticket(); new Ticket();