Enable section collapse/show based off section completed flag
This commit is contained in:
parent
fc4141eaaf
commit
a7d48c1208
1 changed files with 11 additions and 7 deletions
|
@ -25,6 +25,7 @@ function getEndpointDomain() {
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a GET request to url and pass response to callback function
|
||||||
function getDataFromEndpoint(url, callback) {
|
function getDataFromEndpoint(url, callback) {
|
||||||
const token = localStorage.getItem("token");
|
const token = localStorage.getItem("token");
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
@ -54,6 +55,7 @@ function getDataFromEndpoint(url, callback) {
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wraps a Bootstrap form group around a field
|
||||||
function createFormGroup(key, field) {
|
function createFormGroup(key, field) {
|
||||||
const formGroup = document.createElement("div")
|
const formGroup = document.createElement("div")
|
||||||
formGroup.classList.add("form-group");
|
formGroup.classList.add("form-group");
|
||||||
|
@ -61,6 +63,7 @@ function createFormGroup(key, field) {
|
||||||
const label = document.createElement("label");
|
const label = document.createElement("label");
|
||||||
label.innerHTML = field.label;
|
label.innerHTML = field.label;
|
||||||
label.setAttribute("for", key);
|
label.setAttribute("for", key);
|
||||||
|
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.name = key;
|
input.name = key;
|
||||||
input.id = key;
|
input.id = key;
|
||||||
|
@ -93,11 +96,13 @@ function createFormGroup(key, field) {
|
||||||
case "file":
|
case "file":
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
input.classList.add("form-control-file");
|
input.classList.add("form-control-file");
|
||||||
|
formGroup.appendChild(label);
|
||||||
|
formGroup.appendChild(input);
|
||||||
|
let uploadMessage = document.createTextNode("Uploaded file:");
|
||||||
|
formGroup.appendChild(uploadMessage);
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = field.value;
|
link.href = field.value;
|
||||||
link.innerHTML = field.value;
|
link.innerHTML = field.value;
|
||||||
formGroup.appendChild(label);
|
|
||||||
formGroup.appendChild(input);
|
|
||||||
formGroup.appendChild(link);
|
formGroup.appendChild(link);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -129,10 +134,11 @@ function createCollapsibleCard(key, sectionTitle) {
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCollapsibleCardBody(key, form, sectionDescription) {
|
function createCollapsibleCardBody(key, form, sectionDescription, sectionCompleted) {
|
||||||
|
console.log(sectionCompleted);
|
||||||
// Create wrapper div
|
// Create wrapper div
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.classList.add("collapse", "show");
|
sectionCompleted ? div.classList.add("collapse") : div.classList.add("collapse", "show");
|
||||||
div.setAttribute("data-parent", "#editReportAccordion");
|
div.setAttribute("data-parent", "#editReportAccordion");
|
||||||
div.id = "collapse" + key;
|
div.id = "collapse" + key;
|
||||||
|
|
||||||
|
@ -185,7 +191,6 @@ function createEditReportForm(parsedData) {
|
||||||
form.classList.add("form");
|
form.classList.add("form");
|
||||||
form.id = "form" + key;
|
form.id = "form" + key;
|
||||||
|
|
||||||
|
|
||||||
// Traverse the fields of this section
|
// Traverse the fields of this section
|
||||||
let fields = section.fields;
|
let fields = section.fields;
|
||||||
for (let key in fields) {
|
for (let key in fields) {
|
||||||
|
@ -208,7 +213,7 @@ function createEditReportForm(parsedData) {
|
||||||
form.appendChild(saveButton);
|
form.appendChild(saveButton);
|
||||||
|
|
||||||
// Create collapsible card body, append form to it, append card to accordion
|
// Create collapsible card body, append form to it, append card to accordion
|
||||||
let cardBody = createCollapsibleCardBody(key, form, section.html_description);
|
let cardBody = createCollapsibleCardBody(key, form, section.html_description, section.completed);
|
||||||
card.appendChild(cardBody);
|
card.appendChild(cardBody);
|
||||||
accordion.appendChild(card);
|
accordion.appendChild(card);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +227,6 @@ function createEditReportForm(parsedData) {
|
||||||
|
|
||||||
fragment.appendChild(accordion)
|
fragment.appendChild(accordion)
|
||||||
col.appendChild(fragment);
|
col.appendChild(fragment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayListOfReports(parsedData) {
|
function displayListOfReports(parsedData) {
|
||||||
|
|
Loading…
Reference in a new issue