52 lines
1.9 KiB
JavaScript
Vendored
52 lines
1.9 KiB
JavaScript
Vendored
/**
|
|
* Progress bar des informations du Customer dans le club des gaulois
|
|
*/
|
|
|
|
window.ProgressBarInfos = class ProgressBarInfos {
|
|
constructor(bar, text, formInputs) {
|
|
this.bar = bar;
|
|
this.text = text;
|
|
this.nbFields = formInputs.length - 1;
|
|
this.fieldPercentage = 100 / this.nbFields;
|
|
this.fieldsOk = [];
|
|
this.percent = 0;
|
|
|
|
// Gestion des inputs qui ont déjà une valeur
|
|
for (let i = 0; i <= this.nbFields; i++) {
|
|
if (formInputs[i].value.length > 0) {
|
|
if (formInputs[i].name !== "_token") {
|
|
if (
|
|
formInputs[i].type === "checkbox" &&
|
|
formInputs[i].checked
|
|
) {
|
|
this.percent += this.fieldPercentage;
|
|
this.fieldsOk.push(formInputs[i].name);
|
|
} else if (formInputs[i].type !== "checkbox") {
|
|
this.percent += this.fieldPercentage;
|
|
this.fieldsOk.push(formInputs[i].name);
|
|
}
|
|
}
|
|
}
|
|
this.percent = this.percent > 100 ? 100 : this.percent;
|
|
}
|
|
|
|
// Mise à jour des valeurs
|
|
this.bar.style.width = Math.ceil(this.percent) + "%";
|
|
this.text.innerHTML = Math.ceil(this.percent) + "%";
|
|
}
|
|
|
|
changeValue(field, size) {
|
|
let contain = this.fieldsOk.includes(field);
|
|
if (contain && size === 0) {
|
|
this.fieldsOk.splice(this.fieldsOk.indexOf(field), 1);
|
|
this.percent -= this.fieldPercentage;
|
|
this.percent < 0 ? (this.percent = 0) : null;
|
|
} else if (!contain && size > 0) {
|
|
this.fieldsOk.push(field);
|
|
this.percent += this.fieldPercentage;
|
|
this.percent > 100 ? (this.percent = 100) : null;
|
|
}
|
|
this.bar.style.width = Math.ceil(this.percent) + "%";
|
|
this.text.innerHTML = parseInt(this.percent) + "%";
|
|
}
|
|
};
|