mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en el edit
This commit is contained in:
@ -0,0 +1,78 @@
|
||||
import Ajax from '../../../components/ajax.js';
|
||||
|
||||
|
||||
class editServiciosAcabado {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.selectElement = $('#tarifas');
|
||||
this.acabado_cubierta = $('#acabado_cubierta');
|
||||
this.acabado_sobrecubierta = $('#acabado_sobrecubierta');
|
||||
this.tarifasSeleccionadas = JSON.parse(this.selectElement.attr('data-selected') || '[]');
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
this.selectElement.select2({
|
||||
placeholder: "Selecciona tarifas...",
|
||||
allowClear: true,
|
||||
ajax: {
|
||||
url: "/serviciosacabado/gettarifas",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
id: window.location.pathname.split('/').pop(),
|
||||
search: params.term ,
|
||||
acabado_cubierta: self.acabado_cubierta.prop('checked')?1:0,
|
||||
acabado_sobrecubierta: self.acabado_sobrecubierta.prop('checked')?1:0
|
||||
};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {
|
||||
results: data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.nombre
|
||||
}))
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
});
|
||||
|
||||
// Si hay tarifas preseleccionadas, cargarlas manualmente
|
||||
if (this.tarifasSeleccionadas.length > 0) {
|
||||
$.ajax({
|
||||
url: "/serviciosacabado/getselectedtarifas",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
data: { ids: self.tarifasSeleccionadas },
|
||||
success: (data) => {
|
||||
let tarifasPreseleccionadas = data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.nombre
|
||||
}));
|
||||
|
||||
self.selectElement.append(
|
||||
tarifasPreseleccionadas.map(item =>
|
||||
new Option(item.text, item.id, true, true)
|
||||
)
|
||||
).trigger("change");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(function () {
|
||||
new editServiciosAcabado().init();
|
||||
})
|
||||
|
||||
export default editServiciosAcabado;
|
||||
@ -1,25 +1,58 @@
|
||||
class listServiciosAcabado{
|
||||
import Ajax from '../../../components/ajax.js';
|
||||
import ConfirmDeleteModal from '../../../components/ConfirmDeleteModal.js';
|
||||
|
||||
constructor(){}
|
||||
class listServiciosAcabado {
|
||||
|
||||
init(){
|
||||
constructor() {
|
||||
|
||||
this.deleteModal = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
const self = this;
|
||||
|
||||
this.table = $('#tableOfServiciosAcabado');
|
||||
|
||||
this.datatableColumns = [
|
||||
{ data: 'id', searchable: true, sortable: true, width: "10%" },
|
||||
{ data: 'nombre', searchable: true, sortable: true, width: "40%" },
|
||||
{ data: 'acabado_cubierta', sortable: true, width: "10%", render: this.#renderBoolCell.bind(this) },
|
||||
{ data: 'acabado_cubierta', sortable: true, width: "10%", render: this.#renderBoolCell.bind(this) },
|
||||
{ data: 'acabado_sobrecubierta', sortable: false, width: "10%", render: this.#renderBoolCell.bind(this) },
|
||||
{ data: 'mostrar_en_presupuesto_cliente', searchable: false, sortable: true, width: "1exit0%", render: this.#renderBoolCell.bind(this) },
|
||||
{ data: 'mostrar_en_presupuesto_cliente', searchable: false, sortable: true, width: "1exit0%", render: this.#renderBoolCell.bind(this) },
|
||||
{ data: 'user_updated', searchable: true, sortable: true },
|
||||
{ data: 'updated_at', searchable: false, sortable: true },
|
||||
{
|
||||
data: 'action', searchable: false, sortable: false, width: "10%", render: this.#renderActionCell.bind(this)
|
||||
data: 'action', searchable: false, sortable: false, width: "10%"
|
||||
},
|
||||
]
|
||||
|
||||
this.initDatatableTareas();
|
||||
|
||||
this.deleteModal = new ConfirmDeleteModal('tarifascliente');
|
||||
this.deleteModal.init();
|
||||
|
||||
this.table.on('click', '.btn-delete', function (e) {
|
||||
|
||||
self.deleteModal.setData($(this).attr('data-id'));
|
||||
self.deleteModal.show(() => {
|
||||
if ($.isNumeric(self.deleteModal.getData())) {
|
||||
new Ajax(
|
||||
'/serviciosacabado/delete/' + self.deleteModal.getData(),
|
||||
{},
|
||||
{},
|
||||
(response) => {
|
||||
if (response.id) {
|
||||
self.datatableTareas.ajax.reload();
|
||||
popSuccessAlert(response.msg);
|
||||
}
|
||||
}
|
||||
).get();
|
||||
}
|
||||
});
|
||||
});
|
||||
this.table.on('click', '.btn-edit', function (e) {
|
||||
window.location.href = '/serviciosacabado/edit/' + $(this).attr('data-id');
|
||||
});
|
||||
}
|
||||
|
||||
initDatatableTareas() {
|
||||
@ -34,7 +67,7 @@ class listServiciosAcabado{
|
||||
bottomEnd: 'paging'
|
||||
},
|
||||
serverSide: true,
|
||||
responsive : true,
|
||||
responsive: true,
|
||||
pageLength: 25,
|
||||
language: {
|
||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
@ -44,14 +77,6 @@ class listServiciosAcabado{
|
||||
});
|
||||
}
|
||||
|
||||
#renderActionCell(d, t) {
|
||||
|
||||
let cell = `<div class="d-flex justify-content-start align-items-center gap-1">
|
||||
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${d.id}"></i></a></span>
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete} mx-2" data-id="${d.id}"></i></a>
|
||||
</div>`
|
||||
return cell;
|
||||
}
|
||||
|
||||
#renderBoolCell(d, t) {
|
||||
|
||||
@ -62,7 +87,7 @@ class listServiciosAcabado{
|
||||
|
||||
|
||||
|
||||
$(function() {
|
||||
$(function () {
|
||||
new listServiciosAcabado().init();
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user