csvxml/assets/js/csvxml-overview.min.js

5 lines
2.8 KiB
JavaScript
Raw Normal View History

(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")}}
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");if(field.classList.contains("humanTLToggled")===!1)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")===!0)continue;toggleListFieldSelectionState(linkedField)}}}
doForFieldList(function(field){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")===!1)return;if(field.classList.contains("humanTLToggled")===!0)return;toggleListFieldSelectionState(field);checkCSVBySelectionAccessibility()})});let selectAll=document.getElementById("selectAll");selectAll.addEventListener('click',function(e){doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!0)return;toggleListFieldSelectionState(field);checkCSVBySelectionAccessibility()})});unsetSelectionButton.addEventListener('click',function(e){doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!1)return;toggleListFieldSelectionState(field);checkCSVBySelectionAccessibility()})})})()