2019-08-27 00:32:24 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
let csvBySelectionButton = document.getElementById("csvBySelection");
|
|
|
|
let unsetSelectionButton = document.getElementById("unsetSelection");
|
|
|
|
|
|
|
|
function checkCSVBySelectionAccessibility() {
|
|
|
|
|
|
|
|
let selected = document.getElementsByClassName("humanTLToggled");
|
|
|
|
if (selected.length === 0) {
|
|
|
|
csvBySelectionButton.classList.add("invisible");
|
|
|
|
unsetSelection.classList.add("invisible");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
csvBySelectionButton.classList.remove("invisible");
|
|
|
|
unsetSelection.classList.remove("invisible");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Takes a callback function
|
|
|
|
function doForFieldList(callback) {
|
|
|
|
let fieldLists = document.getElementsByClassName("fieldList");
|
|
|
|
for (let i = 0, max = fieldLists.length; i < max; i++) {
|
|
|
|
|
|
|
|
let fields = fieldLists[i].getElementsByTagName("li");
|
|
|
|
for (let j = 0, maxj = fields.length; j < maxj; j++) {
|
|
|
|
|
|
|
|
callback(fields[j]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleListFieldSelectionState(field) {
|
|
|
|
|
|
|
|
let newValue = field.getAttribute("data-alt");
|
|
|
|
field.setAttribute("data-alt", field.textContent);
|
|
|
|
field.textContent = newValue;
|
|
|
|
field.classList.toggle("humanTLToggled");
|
|
|
|
|
2019-09-01 21:16:37 +02:00
|
|
|
if (field.classList.contains("humanTLToggled") === false) return;
|
|
|
|
|
|
|
|
let dependencies = field.getAttribute("data-dependencies");
|
|
|
|
if (dependencies !== undefined && dependencies !== null) {
|
|
|
|
let linkedFields = dependencies.split(";");
|
|
|
|
for (let i = 0, max = linkedFields.length; i < max; i++) {
|
|
|
|
let linkedField = document.getElementById(linkedFields[i]);
|
|
|
|
if (linkedField.classList.contains("humanTLToggled") === true) continue;
|
|
|
|
toggleListFieldSelectionState(linkedField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
doForFieldList(function(field) {
|
|
|
|
|
|
|
|
// Each field should switch its visible content and human-readable
|
|
|
|
// translation on a click.
|
|
|
|
field.addEventListener('click', function(e) {
|
|
|
|
|
|
|
|
toggleListFieldSelectionState(field);
|
|
|
|
checkCSVBySelectionAccessibility();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
csvBySelectionButton.addEventListener('click', function(e) {
|
|
|
|
|
|
|
|
let selectionForm = document.createElement("form");
|
|
|
|
selectionForm.method = "POST";
|
|
|
|
selectionForm.action = "csv.php";
|
|
|
|
|
|
|
|
let hiddenInput = document.createElement("input");
|
|
|
|
hiddenInput.type = "hidden";
|
|
|
|
hiddenInput.name = "selectedFields";
|
|
|
|
hiddenInput.value = "";
|
|
|
|
|
|
|
|
let selected = document.getElementsByClassName("humanTLToggled");
|
|
|
|
for (let i = 0, max = selected.length; i < max; i++) {
|
|
|
|
hiddenInput.value += selected[i].getAttribute("data-value") + ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionForm.appendChild(hiddenInput);
|
|
|
|
document.documentElement.appendChild(selectionForm);
|
|
|
|
selectionForm.submit();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
let selectRequired = document.getElementById("selectRequired");
|
|
|
|
selectRequired.addEventListener('click', function(e) {
|
|
|
|
|
|
|
|
doForFieldList(function(field) {
|
|
|
|
if (field.classList.contains("requiredField") === false) return;
|
|
|
|
if (field.classList.contains("humanTLToggled") === true) return;
|
|
|
|
|
|
|
|
toggleListFieldSelectionState(field);
|
|
|
|
checkCSVBySelectionAccessibility();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
let selectAll = document.getElementById("selectAll");
|
|
|
|
selectAll.addEventListener('click', function(e) {
|
|
|
|
|
|
|
|
doForFieldList(function(field) {
|
|
|
|
if (field.classList.contains("humanTLToggled") === true) return;
|
|
|
|
|
|
|
|
toggleListFieldSelectionState(field);
|
|
|
|
checkCSVBySelectionAccessibility();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
unsetSelectionButton.addEventListener('click', function(e) {
|
|
|
|
|
|
|
|
doForFieldList(function(field) {
|
|
|
|
if (field.classList.contains("humanTLToggled") === false) return;
|
|
|
|
|
|
|
|
toggleListFieldSelectionState(field);
|
|
|
|
checkCSVBySelectionAccessibility();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|