reparados bugs

This commit is contained in:
jaimejimenezortega
2024-05-22 16:30:05 +02:00
parent e4f6295597
commit 667a2ab679
2 changed files with 2746 additions and 205 deletions

View File

@ -13,8 +13,7 @@
// -------------------------------------------------------------------- // --------------------------------------------------------------------
const clientePresupuestoWizard = document.querySelector('#wizard-presupuesto-cliente'); const clientePresupuestoWizard = document.querySelector('#wizard-presupuesto-cliente');
if (typeof clientePresupuestoWizard !== undefined && clientePresupuestoWizard !== null && if (typeof clientePresupuestoWizard !== undefined && clientePresupuestoWizard !== null ) {
clientePresupuestoWizard.querySelector('#presupuesto-cliente-form').querySelector('#tipo-libro') !== null ) {
// Wizard form // Wizard form
const clientePresupuestoWizardForm = clientePresupuestoWizard.querySelector('#presupuesto-cliente-form'); const clientePresupuestoWizardForm = clientePresupuestoWizard.querySelector('#presupuesto-cliente-form');
// Wizard steps // Wizard steps
@ -26,235 +25,241 @@
const clientePresupuestoWizardNext = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-next')); const clientePresupuestoWizardNext = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-next'));
const clientePresupuestoWizardPrev = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-prev')); const clientePresupuestoWizardPrev = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-prev'));
let FormValidation2;
let FormValidation3;
let FormValidation4;
let FormValidation5;
let validationStepper = new Stepper(clientePresupuestoWizard, { let validationStepper = new Stepper(clientePresupuestoWizard, {
linear: true linear: true
}); });
// select2 (clienteId) if(clientePresupuestoWizardFormStep2 != null) {
const clienteId = $('#clienteId'); // select2 (clienteId)
const clienteId = $('#clienteId');
clienteId.on('change.select2', function () { clienteId.on('change.select2', function () {
// Revalidate the clienteId field when an option is chosen // Revalidate the clienteId field when an option is chosen
FormValidation2.revalidateField('clienteId'); FormValidation2.revalidateField('clienteId');
}); });
// Deal Details // Deal Details
const FormValidation2 = FormValidation.formValidation(clientePresupuestoWizardFormStep2, { FormValidation2 = FormValidation.formValidation(clientePresupuestoWizardFormStep2, {
fields: { fields: {
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap5: new FormValidation.plugins.Bootstrap5({
// Use this for enabling/changing valid/invalid class
// eleInvalidClass: '',
eleValidClass: '',
rowSelector: '.col-sm-3'
}),
autoFocus: new FormValidation.plugins.AutoFocus(),
submitButton: new FormValidation.plugins.SubmitButton()
}
}).on('core.form.valid', function () {
// Jump to the next step when all fields in the current step are valid
validationStepper.next();
});
// Deal Usage
const FormValidation3 = FormValidation.formValidation(clientePresupuestoWizardFormStep3, {
fields: {
titulo: {
validators: {
notEmpty: {
message: window.Presupuestos.validation.requerido_short
},
}
}, },
clienteId: { plugins: {
validators: { trigger: new FormValidation.plugins.Trigger(),
callback: { bootstrap5: new FormValidation.plugins.Bootstrap5({
message: window.Presupuestos.validation.cliente, // Use this for enabling/changing valid/invalid class
callback: function (input) { // eleInvalidClass: '',
// Get the selected options eleValidClass: '',
const options = $("#clienteId").select2('data'); rowSelector: '.col-sm-3'
const hasValidOption = options.some(option => parseInt(option.id) > 0); }),
return options !== null && options.length > 0 && hasValidOption; autoFocus: new FormValidation.plugins.AutoFocus(),
submitButton: new FormValidation.plugins.SubmitButton()
}
}).on('core.form.valid', function () {
// Jump to the next step when all fields in the current step are valid
validationStepper.next();
});
// Deal Usage
FormValidation3 = FormValidation.formValidation(clientePresupuestoWizardFormStep3, {
fields: {
titulo: {
validators: {
notEmpty: {
message: window.Presupuestos.validation.requerido_short
}, },
} }
} },
}, clienteId: {
tirada: { validators: {
validators: { callback: {
callback: { message: window.Presupuestos.validation.cliente,
message: window.Presupuestos.validation.integer_greatherThan_0, callback: function (input) {
callback: function (input) { // Get the selected options
const value = $("#tirada").val(); const options = $("#clienteId").select2('data');
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; const hasValidOption = options.some(option => parseInt(option.id) > 0);
}, return options !== null && options.length > 0 && hasValidOption;
},
}
} }
} },
}, tirada: {
paginas: { validators: {
validators: { callback: {
callback: { message: window.Presupuestos.validation.integer_greatherThan_0,
message: window.Presupuestos.validation.integer_greatherThan_0, callback: function (input) {
callback: function (input) { const value = $("#tirada").val();
const value = $("#paginas").val();
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
},
}
}
},
paginasColor: {
validators: {
callback: {
message: window.Presupuestos.validation.integer_greatherThan_0,
callback: function (input) {
if ($('#pagColorDiv').is(':hidden'))
return true;
else {
const value = $("#paginasColor").val();
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
} },
}, }
} }
} },
}, paginas: {
gramajeInterior: { validators: {
validators: { callback: {
callback: { message: window.Presupuestos.validation.integer_greatherThan_0,
callback: function (input) { callback: function (input) {
const value = $("#tirada").val(); const value = $("#paginas").val();
if ($('#gramajeInterior option:selected').text().length == 0) { return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
if(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0){ },
return { }
valid: false, }
message: window.Presupuestos.validation.sin_gramaje, },
paginasColor: {
validators: {
callback: {
message: window.Presupuestos.validation.integer_greatherThan_0,
callback: function (input) {
if ($('#pagColorDiv').is(':hidden'))
return true;
else {
const value = $("#paginasColor").val();
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
}
},
}
}
},
gramajeInterior: {
validators: {
callback: {
callback: function (input) {
const value = $("#tirada").val();
if ($('#gramajeInterior option:selected').text().length == 0) {
if(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0){
return {
valid: false,
message: window.Presupuestos.validation.sin_gramaje,
}
}
return {
valid: value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0,
message: window.Presupuestos.validation.tirada_no_valida,
} }
} }
return { return true;
valid: value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0, },
message: window.Presupuestos.validation.tirada_no_valida, },
}
},
gramajeCubierta: {
validators: {
callback: {
message: window.Presupuestos.validation.tirada_no_valida,
callback: function (input) {
const value = $("#tirada").val();
if ($('#gramajeCubierta option:selected').text().length == 0) {
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
} }
} return true;
return true; },
},
},
}
},
gramajeCubierta: {
validators: {
callback: {
message: window.Presupuestos.validation.tirada_no_valida,
callback: function (input) {
const value = $("#tirada").val();
if ($('#gramajeCubierta option:selected').text().length == 0) {
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
}
return true;
},
},
callback: {
message: window.Presupuestos.validation.sin_gramaje,
callback: function (input) {
if ($('#gramajeCubierta option:selected').text().length == 0) {
return false;
}
return true;
}, },
callback: {
message: window.Presupuestos.validation.sin_gramaje,
callback: function (input) {
if ($('#gramajeCubierta option:selected').text().length == 0) {
return false;
}
return true;
},
}
} }
} },
}, gramajeSobrecubierta: {
gramajeSobrecubierta: { validators: {
validators: { callback: {
callback: { message: window.Presupuestos.validation.tirada_no_valida,
message: window.Presupuestos.validation.tirada_no_valida, callback: function (input) {
callback: function (input) { const value = $("#tirada").val();
const value = $("#tirada").val(); if ($('#gramajeSobrecubierta option:selected').text().length == 0) {
if ($('#gramajeSobrecubierta option:selected').text().length == 0) { return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; }
} return true;
return true; },
}, }
} }
} },
}, },
}, plugins: {
plugins: { trigger: new FormValidation.plugins.Trigger(),
trigger: new FormValidation.plugins.Trigger(), bootstrap5: new FormValidation.plugins.Bootstrap5({
bootstrap5: new FormValidation.plugins.Bootstrap5({ // Use this for enabling/changing valid/invalid class
// Use this for enabling/changing valid/invalid class // eleInvalidClass: '',
// eleInvalidClass: '', eleValidClass: '',
eleValidClass: '', rowSelector: function (field, ele) {
rowSelector: function (field, ele) { // field is the field name
// field is the field name // ele is the field element
// ele is the field element switch (field) {
switch (field) { case 'gramajeInterior':
case 'gramajeInterior': case 'gramajeCubierta':
case 'gramajeCubierta': case 'gramajeSobrecubierta':
case 'gramajeSobrecubierta': return '.col-sm-2';
return '.col-sm-2';
case 'titulo': case 'titulo':
return '.col-sm-12'; return '.col-sm-12';
case 'clienteId': case 'clienteId':
return '.col-sm-6'; return '.col-sm-6';
default: default:
return '.col-sm-3'; return '.col-sm-3';
}
} }
} }),
}), autoFocus: new FormValidation.plugins.AutoFocus(),
autoFocus: new FormValidation.plugins.AutoFocus(), submitButton: new FormValidation.plugins.SubmitButton()
submitButton: new FormValidation.plugins.SubmitButton() }
} }).on('core.form.valid', function () {
}).on('core.form.valid', function () {
validationStepper.next();
initDirecciones();
initTiradasDirecciones();
});
const tirada = $('#tirada');
tirada.on('change', function () {
// Revalidate the clienteId field when an option is chosen
FormValidation2.revalidateField('gramajeInterior');
FormValidation2.revalidateField('gramajeCubierta');
FormValidation2.revalidateField('gramajeSobrecubierta');
});
// Direcciones
const FormValidation4 = FormValidation.formValidation(clientePresupuestoWizardFormStep4, {
fields: {
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap5: new FormValidation.plugins.Bootstrap5({
// Use this for enabling/changing valid/invalid class
// eleInvalidClass: '',
eleValidClass: '',
rowSelector: '.col-md-12'
}),
autoFocus: new FormValidation.plugins.AutoFocus(),
submitButton: new FormValidation.plugins.SubmitButton()
}
}).on('core.form.valid', function () {
if(validarEnvio()){
generarResumen();
validationStepper.next(); validationStepper.next();
} initDirecciones();
else{ initTiradasDirecciones();
let text = "El número de unidades enviadas no coincie con la tirada seleccionada."; });
if($('#prototipo').is(':checked')) {
text += "<br>(Tenga en cuenta que se ha seleccionado la opción de prototipo)";
}
$('#errorDirecciones').text(text);
$('#errorDirecciones').show();
}
});
const tirada = $('#tirada');
tirada.on('change', function () {
// Revalidate the clienteId field when an option is chosen
FormValidation2.revalidateField('gramajeInterior');
FormValidation2.revalidateField('gramajeCubierta');
FormValidation2.revalidateField('gramajeSobrecubierta');
});
// Direcciones
FormValidation4 = FormValidation.formValidation(clientePresupuestoWizardFormStep4, {
fields: {
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap5: new FormValidation.plugins.Bootstrap5({
// Use this for enabling/changing valid/invalid class
// eleInvalidClass: '',
eleValidClass: '',
rowSelector: '.col-md-12'
}),
autoFocus: new FormValidation.plugins.AutoFocus(),
submitButton: new FormValidation.plugins.SubmitButton()
}
}).on('core.form.valid', function () {
if(validarEnvio()){
generarResumen();
validationStepper.next();
}
else{
let text = "El número de unidades enviadas no coincie con la tirada seleccionada.";
if($('#prototipo').is(':checked')) {
text += "<br>(Tenga en cuenta que se ha seleccionado la opción de prototipo)";
}
$('#errorDirecciones').text(text);
$('#errorDirecciones').show();
}
});
}
// Deal Usage // Deal Usage
const FormValidation5 = FormValidation.formValidation(clientePresupuestoWizardFormStep5, { FormValidation5 = FormValidation.formValidation(clientePresupuestoWizardFormStep5, {
fields: { fields: {
// * Validate the fields here based on your requirements // * Validate the fields here based on your requirements
}, },

2536
xdebug.log

File diff suppressed because it is too large Load Diff