From f70f6a09293b77a2ae584dfef6a3eb2e3888e202 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Tue, 10 Dec 2024 07:35:38 +0100 Subject: [PATCH] servicio cliente tareas --- .../datatables/ServicioClienteDatatable.js | 44 ++++++ .../components/forms/servicioClienteForm.js | 125 ++++++++++++++++++ .../configuracion/servicio_cliente/edit.js | 6 + .../configuracion/servicio_cliente/index.js | 4 + 4 files changed, 179 insertions(+) create mode 100644 httpdocs/assets/js/safekat/components/datatables/ServicioClienteDatatable.js create mode 100644 httpdocs/assets/js/safekat/components/forms/servicioClienteForm.js create mode 100644 httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/edit.js create mode 100644 httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/index.js diff --git a/httpdocs/assets/js/safekat/components/datatables/ServicioClienteDatatable.js b/httpdocs/assets/js/safekat/components/datatables/ServicioClienteDatatable.js new file mode 100644 index 00000000..efb2e7af --- /dev/null +++ b/httpdocs/assets/js/safekat/components/datatables/ServicioClienteDatatable.js @@ -0,0 +1,44 @@ + +class ServicioClienteDatatable { + constructor(domItem) { + this.datatableItem = domItem + + this.datatableColumns = [ + { data: 'nombre', searchable: true, sortable: true }, + { data: 'code', searchable: true, sortable: true }, + { data: 'created_at', searchable: true, sortable: true }, + { + data: 'action', searchable: false, sortable: false, + render: (d, t) => { + return `
+ +
` + } + } + ] + + + + } + init() { + this.datatable = this.datatableItem.DataTable({ + processing: true, + layout: { + topStart: 'pageLength', + topEnd: 'search', + bottomStart: 'info', + bottomEnd: 'paging' + }, + serverSide: true, + pageLength: 25, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: this.datatableColumns, + ajax: '/configuracion/servicios/datatable' + }); + } + +} + +export default ServicioClienteDatatable; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/components/forms/servicioClienteForm.js b/httpdocs/assets/js/safekat/components/forms/servicioClienteForm.js new file mode 100644 index 00000000..00cf3c46 --- /dev/null +++ b/httpdocs/assets/js/safekat/components/forms/servicioClienteForm.js @@ -0,0 +1,125 @@ +import Ajax from '../ajax.js' +import ClassSelect from '../select2.js' + +class ServicioClienteForm { + /** + * + * @param {*} domItem jQuery item of the form html element + */ + constructor(domItem) { + this.item = domItem + this.btnNew = this.item.find("#btn-new-servicio-cliente") + this.btnUpdate = this.item.find("#btn-update-servicio-cliente") + this.selectItemTarifaAcabado = this.item.find("#servicio-cliente-tarifa-acabado") + this.selectItemTarifaManipulado = this.item.find("#servicio-cliente-tarifa-manipulado") + this.selectTarifaAcabado = new ClassSelect(this.selectItemTarifaAcabado, '/tarifas/acabados/select', "Seleccione una tarifa", true) + this.selectTarifaManipulado = new ClassSelect(this.selectItemTarifaManipulado, '/tarifasmanipulado/select', "Seleccione una tarifa", true) + this.checkTarifaAcabado = this.item.find("#check-tarifa-acabado") + this.checkTarifaManipulado = this.item.find("#check-tarifa-manipulado") + + + } + init() { + this.modelId = this.item.data('id') + this.uri = `/configuracion/servicios/${this.modelId}` + this.uriUpdate = `/configuracion/servicios/update/${this.modelId}` + this.uriPost = `/configuracion/servicios` + this.btnNew.on("click", this.handlePost.bind(this)) + this.btnUpdate.on("click", this.handlePut.bind(this)) + this.handleGet() + this.selectTarifaAcabado.init() + this.selectTarifaManipulado.init() + this.btnUpdate.removeClass("d-none") + this.checkTarifaAcabado.change(() => { + console.log("Acabado", this.checkTarifaAcabado.is(":checked")) + if (this.checkTarifaAcabado.is(":checked")) { + this.item.find("#container-tarifa-acabado-select").removeClass("d-none") + this.item.find("#container-tarifa-manipulado-select").addClass("d-none") + } else { + this.item.find("#container-tarifa-acabado-select").addClass("d-none") + this.item.find("#container-tarifa-manipulado-select").removeClass("d-none") + } + }) + this.checkTarifaManipulado.change(() => { + console.log("Manipulado", this.checkTarifaManipulado.is(":checked")) + if (this.checkTarifaManipulado.is(":checked")) { + this.item.find("#container-tarifa-acabado-select").addClass("d-none") + this.item.find("#container-tarifa-manipulado-select").removeClass("d-none") + } else { + this.item.find("#container-tarifa-acabado-select").removeClass("d-none") + this.item.find("#container-tarifa-manipulado-select").addClass("d-none") + } + }) + } + handleGet() { + const ajax = new Ajax( + this.uri, + null, + null, + this.handleGetSuccess.bind(this), + this.handleGetError.bind(this) + ) + ajax.get() + } + handleGetSuccess(data) { + this.item.find('[name="nombre"]').val(data.nombre) + this.item.find('[name="code"]').val(data.code) + if(data?.tarifas_acabado){ + this.selectTarifaAcabado.setOption(data.tarifas_acabado.id,data.tarifas_acabado.nombre) + this.checkTarifaAcabado.prop("checked",true) + this.checkTarifaAcabado.trigger("change") + this.selectTarifaManipulado.reset() + } + if(data?.tarifas_manipulado){ + this.checkTarifaManipulado.prop("checked",true) + this.selectTarifaManipulado.setOption(data.tarifas_manipulado.id,data.tarifas_manipulado.nombre) + this.checkTarifaManipulado.trigger("change") + this.selectTarifaAcabado.reset() + } + + } + handleGetError(e) { + console.error(e) + } + handlePost() { + let bodyData = this.getFormData() + const ajax = new Ajax( + this.uriPost, + bodyData, + null, + this.handlePostSuccess.bind(this), + this.handlePostError.bind(this) + ) + ajax.post() + } + handlePostSuccess() { + this.item.reset() + } + handlePostError() { } + handlePut() { + let bodyData = this.getFormData() + const ajax = new Ajax( + this.uriUpdate, + bodyData, + null, + this.handlePutSuccess.bind(this), + this.handlePutError.bind(this) + ) + ajax.post() + } + handlePutSuccess(data) { + // this.item.reset() + this.handleGet(data) + } + handlePutError() { } + + getFormData() { + let data = {} + this.item.serializeArray().forEach((e) => { + data[e.name] = e.value + } + ) + return data + } +} +export default ServicioClienteForm \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/edit.js b/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/edit.js new file mode 100644 index 00000000..5bc6d4b2 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/edit.js @@ -0,0 +1,6 @@ +import ServicioClienteForm from '../../../components/forms/servicioClienteForm.js' + +$(document).ready(() => { + const formServicioCliente = new ServicioClienteForm($("#formServicioCliente")) + formServicioCliente.init() +}) diff --git a/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/index.js b/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/index.js new file mode 100644 index 00000000..5ee98e58 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/servicio_cliente/index.js @@ -0,0 +1,4 @@ +import ServicioClienteDatatable from '../../../components/datatables/ServicioClienteDatatable.js' + +const servicioClienteDatatable = new ServicioClienteDatatable($("#tableServiciosCliente")) +servicioClienteDatatable.init()