diff --git a/ci4/app/Controllers/Clientes/ClientePrecios.php b/ci4/app/Controllers/Clientes/ClientePrecios.php index bc258921..105d085a 100755 --- a/ci4/app/Controllers/Clientes/ClientePrecios.php +++ b/ci4/app/Controllers/Clientes/ClientePrecios.php @@ -205,21 +205,19 @@ class ClientePrecios extends \App\Controllers\BaseResourceController } }) ->on('preCreate', function ($editor, &$values) { - $session = session(); $datetime = (new \CodeIgniter\I18n\Time("now")); $editor ->field('user_updated_id') - ->setValue($session->id_user); + ->setValue(auth()->user()->id); $editor ->field('updated_at') ->setValue($datetime->format('Y-m-d H:i:s')); }) ->on('preEdit', function ($editor, &$values) { - $session = session(); $datetime = (new \CodeIgniter\I18n\Time("now")); $editor ->field('user_updated_id') - ->setValue($session->id_user); + ->setValue(auth()->user()->id); $editor ->field('updated_at') ->setValue($datetime->format('Y-m-d H:i:s')); diff --git a/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js b/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js index a874abf7..161c593f 100644 --- a/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js +++ b/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js @@ -1,9 +1,16 @@ class ConfirmDeleteModal { + constructor(alias = "") { - this.modalId = 'confirm2delete'; + + this.modalId = alias !== "" ? `confirm2delete-${alias}`: 'confirm2delete'; const removeClass = alias !== "" ? `btn-remove-${alias}` : 'btn-remove'; + this.btnCancelId = alias !== "" ? `btnCancelDelete-${alias}` : 'btnCancelDelete'; + this.btnDeleteId = alias !== "" ? `btnConfirmDelete-${alias}` : 'btnConfirmDelete'; + + this.data = null; + this.modalHtml = ` @@ -25,19 +32,39 @@ class ConfirmDeleteModal { `; } - // Método para mostrar el modal - show(callback) { + init() { + // Insertar el modal en el body del documento si no existe if (!document.getElementById(this.modalId)) { document.body.insertAdjacentHTML('beforeend', this.modalHtml); } + document.getElementById(this.btnCancelId).addEventListener('click', () => { + const modal = new bootstrap.Modal(document.getElementById(this.modalId)); + modal.hide(); + }); + } + + getModalId() { + return '#' + this.modalId; + } + + setData(data) { + this.data = data; + } + + getData() { + return this.data; + } + + // Método para mostrar el modal + show(callback) { // Mostrar el modal usando Bootstrap const modal = new bootstrap.Modal(document.getElementById(this.modalId)); modal.show(); // Configurar el evento de confirmación de eliminación - document.getElementById('confirmDelete').addEventListener('click', () => { + document.getElementById(this.btnDeleteId).addEventListener('click', () => { callback(); // Llamar al callback que el usuario haya proporcionado modal.hide(); // Cerrar el modal }); @@ -49,3 +76,6 @@ class ConfirmDeleteModal { modal.hide(); } } + + +export default ConfirmDeleteModal; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/components/table.js b/httpdocs/assets/js/safekat/components/table.js index 2f3c8eb3..84f94c7b 100644 --- a/httpdocs/assets/js/safekat/components/table.js +++ b/httpdocs/assets/js/safekat/components/table.js @@ -23,15 +23,13 @@ let Table = function ( dom = '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', actions = ['view', 'edit', 'delete', 'cancel'], order = [[0, 'asc']], - deleteModal = null, buttonsExport = true, buttonNewWithEditor = false, editor = null, booleanColumns = [], } = {}) { - this.actions = actions; // Guardar actions como propiedad de la instancia - this.deleteModal = deleteModal; + this.actions = actions; const lastColNr = this.domItem.find("tr:first th").length - 1; @@ -124,6 +122,10 @@ let Table = function ( } }; + this.getAlias = function () { + return this.alias; + } + this.setData = function (data) { this.data = data; } @@ -165,7 +167,7 @@ let Table = function ( btns += ``; } if (this.actions.includes('delete')) { - btns += ``; + btns += ``; } return btns; diff --git a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js index be539820..0ed7c8ea 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js +++ b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js @@ -1,6 +1,6 @@ import Table from '../../components/table.js'; import TableEditor from '../../components/tableEditor.js'; -import Confirm2Delete from '../../components/confirm2delete.js'; +import ConfirmDeleteModal from '../../components/ConfirmDeleteModal.js'; import { getToken } from '../../common/common.js'; @@ -21,12 +21,16 @@ class tarifasClienteView { this.tableTarifas = null; this.editorTarifas = null; this.confirmDeleteModal = null; + this.deleteModal = null; } init() { const self = this; + this.deleteModal = new ConfirmDeleteModal('tarifascliente'); + this.deleteModal.init(); + this.#initEditor(); this.#initTable(); @@ -51,6 +55,21 @@ class tarifasClienteView { }); + this.tableTarifas.table.on('click', '.btn-delete-' + this.tableTarifas.getAlias(), function (e) { + const row = $(this).closest('tr')[0]._DT_RowIndex; + self.deleteModal.setData($(this).attr('data-id')); + self.deleteModal.show(() =>{ + if ($.isNumeric(self.deleteModal.getData())) { + self.editorTarifas.editor + .create( false ) + .edit( self.tableTarifas.table.rows(row), false) + .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) + .set( 'is_deleted', 1 ) + .submit(); + self.deleteModal.hide(); + } + }); + }); } @@ -246,7 +265,6 @@ class tarifasClienteView { buttonNewWithEditor: true, buttonsExport: true, editor: this.editorTarifas.editor, - deleteModal: '#confirm2delete' }); @@ -262,6 +280,8 @@ class tarifasClienteView { } + + headerSearcher() { const self = this;