mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta boton add direcciones
This commit is contained in:
@ -0,0 +1,76 @@
|
||||
class tarjetaDireccion {
|
||||
|
||||
constructor(container, id, direccion) {
|
||||
|
||||
this.container = container;
|
||||
this.card = this.#generateHTML(id, direccion);
|
||||
this.deleteBtn = this.card.find('.direccion-eliminar');
|
||||
this.editBtn = this.card.find('.direccion-editar');
|
||||
}
|
||||
|
||||
|
||||
#generateHTML(id, direccion) {
|
||||
|
||||
// Crear los elementos usando jQuery
|
||||
var $parent = $('<div>', {
|
||||
class: 'direccion-cliente col-sm-5 form-check custom-option custom-option-basic checked justify-content-center mb-4',
|
||||
id: id
|
||||
});
|
||||
|
||||
var $label = $('<label>', { class: 'form-check-label custom-option-content' });
|
||||
|
||||
var $header = $('<span>', { class: 'custom-option-header mb-2' });
|
||||
var $name = $('<h6>', { class: 'fw-semibold mb-0', text: direccion.nombre });
|
||||
var $unidades = $('<span>', { class: 'badge bg-label-primary unidades', text: direccion.unidades + ' unidades' });
|
||||
|
||||
var $body = $('<span>', { class: 'custom-option-body' });
|
||||
var $direccion = $('<small>', { class: 'address-direccion', text: direccion.direccion });
|
||||
var $cp = $('<small>', { class: 'address-cp', text: direccion.cp });
|
||||
var $municipioPais = $('<small>', { class: 'address-municipio-pais', text: direccion.municipioPais });
|
||||
var $telefono = $('<small>', { class: 'address-telefono', text: direccion.telefono });
|
||||
var $email = $('<small>', { class: 'address-email', text: direccion.email });
|
||||
|
||||
var $palets = $('<small>', {class: 'address-palets', html: '<i>Envío en palets</i>'});
|
||||
if (!direccion.palets) $palets.addClass('d-none');
|
||||
|
||||
var $hr = $('<hr>', { class: 'my-2' });
|
||||
var $eliminar = $('<a>', { class: 'ms-auto direccion-eliminar', href: 'javascript:void(0)', text: 'Eliminar' });
|
||||
var $editar = $('<a>', { class: 'me-auto direccion-editar', href: 'javascript:void(0)', text: 'Editar' });
|
||||
var $eliminarContainer = $('<span>', { class: 'd-flex w-100 position-relative' }).append($editar, $eliminar);
|
||||
|
||||
// Construir la estructura del HTML
|
||||
$header.append($name, $unidades);
|
||||
$body.append($direccion, '<br>', $cp, '<br>', $municipioPais, '<br>', $telefono, '<br>', $email, '<br>', $palets, '<br>', $hr, $eliminarContainer);
|
||||
$label.append($header, $body);
|
||||
$parent.append($label);
|
||||
|
||||
return $parent;
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
|
||||
this.container.append(this.card);
|
||||
}
|
||||
|
||||
|
||||
setDireccion(direccion) {
|
||||
this.card.find('.address-direccion').text(direccion.direccion);
|
||||
this.card.find('.address-cp').text(direccion.cp);
|
||||
this.card.find('.address-municipio-pais').text(direccion.municipioPais);
|
||||
this.card.find('.address-telefono').text(direccion.telefono);
|
||||
this.card.find('.address-email').text(direccion.email);
|
||||
this.card.find('.address-palets').toggleClass('d-none', !direccion.palets);
|
||||
}
|
||||
|
||||
|
||||
getUnidades() {
|
||||
return this.card.find('.unidades').text().split(' ')[0];
|
||||
}
|
||||
|
||||
getCp() {
|
||||
return this.card.find('.address-cp').text();
|
||||
}
|
||||
}
|
||||
|
||||
export default tarjetaDireccion;
|
||||
@ -1,4 +1,5 @@
|
||||
import ClassSelect from '../../components/select2.js';
|
||||
import tarjetaDireccion from '../../components/tarjetaDireccionPresupuesto.js';
|
||||
|
||||
class Direcciones {
|
||||
|
||||
@ -8,7 +9,11 @@ class Direcciones {
|
||||
this.wizardStep = wizardForm.querySelector('#direcciones-libro');
|
||||
this.validatorStepper = validatorStepper;
|
||||
|
||||
this.direcciones = new ClassSelect($("#direcciones"), '/clientedirecciones/menuitems');
|
||||
this.direccionesCliente = new ClassSelect($("#direcciones"), '/clientedirecciones/menuitems');
|
||||
|
||||
this.divDirecciones = $(this.domItem.find('#divDirecciones'));
|
||||
|
||||
this.direcciones = [];
|
||||
|
||||
this.initValidation();
|
||||
|
||||
@ -19,8 +24,16 @@ class Direcciones {
|
||||
|
||||
$("#clienteId").on('change', this.#handleChangeCliente.bind(this));
|
||||
|
||||
this.domItem.load('../../components/direcciones.html');
|
||||
this.direcciones.init();
|
||||
let direccion = {
|
||||
nombre: 'Casa',
|
||||
unidades: '100',
|
||||
direccion: 'Calle de la Prueba, 12',
|
||||
cp: '28000',
|
||||
municipioPais: 'Madrid, España',
|
||||
telefono: '912345678',
|
||||
email: 'aaa@aa.com',
|
||||
palets: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,11 +70,61 @@ class Direcciones {
|
||||
});
|
||||
}
|
||||
|
||||
#insertDireccion(direccion_id) {
|
||||
|
||||
let tarjeta = new tarjetaDireccion();
|
||||
tarjeta.setDireccion(direccion);
|
||||
|
||||
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(this));
|
||||
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(this));
|
||||
|
||||
this.divDirecciones.append(tarjeta.card);
|
||||
this.direcciones.push(direccion);
|
||||
}
|
||||
|
||||
|
||||
#handleChangeCliente() {
|
||||
this.direcciones.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
|
||||
this.direcciones.clear();
|
||||
// falta quitar las direcciones que haya!!!!
|
||||
|
||||
this.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
|
||||
this.direccionesCliente.clear();
|
||||
|
||||
this.domItem.find('.direccion-cliente').remove();
|
||||
this.direcciones = [];
|
||||
}
|
||||
|
||||
#editUnits(event) {
|
||||
|
||||
let tarjeta = $(event.currentTarget.closest('.direccion-cliente'));
|
||||
let unidades = tarjeta.find('.unidades').text().split(' ')[0];
|
||||
|
||||
let modal = $('#modalInput');
|
||||
modal.find('.modal-title').text('Editar unidades');
|
||||
modal.find('.inputData').val(unidades);
|
||||
modal.modal('show');
|
||||
|
||||
modal.find('.btn-primary').off('click');
|
||||
modal.find('.btn-primary').on('click', function () {
|
||||
try {
|
||||
|
||||
let nuevo_valor = parseInt(modal.find('.modal-body input').val());
|
||||
if (nuevo_valor > 0) {
|
||||
tarjeta.find('.unidades').text(nuevo_valor + ' unidades');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Units must be a number');
|
||||
}
|
||||
modal.modal('hide');
|
||||
});
|
||||
}
|
||||
|
||||
#deleteDireccion(event) {
|
||||
|
||||
let tarjeta = event.currentTarget.closest('.direccion-cliente');
|
||||
let id = tarjeta.id;
|
||||
|
||||
tarjeta.remove();
|
||||
|
||||
this.direcciones = this.direcciones.filter(direccion => direccion.id != id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +76,8 @@ class PresupuestoCliente {
|
||||
|
||||
setTimeout(function() {
|
||||
$("#tapaDura").trigger("click");
|
||||
}, 0);
|
||||
}, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user