Skip to content
Snippets Groups Projects
Commit 382bae09 authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Refactor : factorize code of select area in results

parent 05337d8c
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,8 @@ class ResultZoneComponent {
}
} else if (event.target.id == "select-sections") {
let area = resultHandler.parent.results.areasResults.find(
(areaFind) => areaFind.ID == document.getElementById("select-areas").value
(areaFind) =>
areaFind.ID == document.getElementById("select-areas").value
);
let section = area.Sections.find(
(sectionFind) => sectionFind.ID == event.target.value
......@@ -342,42 +343,19 @@ class ResultZoneComponent {
}
displayAreasResults() {
let selectAreas = document.getElementById("select-areas");
this.refreshAreas();
document.getElementById("select-sections").parentNode.style.display =
"none";
for (let i = selectAreas.options.length - 1; i >= 0; i--) {
selectAreas.remove(i);
}
this.parent.results.areasResults.forEach((area) => {
let el = document.createElement("option");
el.textContent = area.Name;
el.value = area.ID;
selectAreas.appendChild(el);
});
if (this.parent.zone == "areas" && this.areaDisplayed != undefined) {
document.getElementById("select-areas").value = this.areaDisplayed.ID;
} else this.displayZoneResults(this.parent.results.areasResults[0]);
}
displaySectionsResults() {
let selectAreas = document.getElementById("select-areas");
this.refreshAreas();
document.getElementById("select-sections").parentNode.style.display =
"block";
for (let i = selectAreas.options.length - 1; i >= 0; i--) {
selectAreas.remove(i);
}
this.parent.results.areasResults.forEach((area) => {
let el = document.createElement("option");
el.textContent = area.Name;
el.value = area.ID;
selectAreas.appendChild(el);
});
this.refreshSections(this.parent.results.areasResults[0]);
if (this.parent.zone == "sections" && this.sectionDisplayed != undefined) {
......@@ -524,4 +502,19 @@ class ResultZoneComponent {
selectSections.appendChild(el);
}
}
refreshAreas() {
let selectAreas = document.getElementById("select-areas");
for (let i = selectAreas.options.length - 1; i >= 0; i--) {
selectAreas.remove(i);
}
this.parent.results.areasResults.forEach((area) => {
let el = document.createElement("option");
el.textContent = area.Name;
el.value = area.ID;
selectAreas.appendChild(el);
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment