File size: 2,715 Bytes
9609d3b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
// read form input
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('crosswalkForm');
if (form) {
form.addEventListener('submit', function(event) {
event.preventDefault();
// Fetch API to submit form data without reloading the page
// fetch('http://127.0.0.1:8989/getoptions', {
fetch("{{ url_for('get_options') }}", {
method: 'POST',
body: new FormData(form),
headers: {
'Accept': 'application/json',
}
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => console.error('Error:', error));
});
}else {
console.error("Form not found")
}
});
function uploadFile() {
const input = document.getElementById('crosswalkcsvFile');
const data = new FormData();
data.append('crosswalkcsv_file', input.files[0]);
fetch("{{ url_for('parse_crosswalk') }}", {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(data => {
// console.log(data);
// document.getElementById("crosswalkdata").innerHTML = data.message;
})
.catch(error => console.error('Error:', error));
}
// convert JSON to CSV
function jsonToCSV(json) {
const items = json;
const replacer = (key, value) => value === null ? '' : value;
const header = Object.keys(items[0]);
const csv = [
header.join(','),
...items.map(row => header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join(','))
];
return csv.join('\r\n');
}
// return interactive results
document.addEventListener('DOMContentLoaded', function() {
const resultsDiv = document.getElementById('interactiveOutput');
const urlParams = new URLSearchParams(window.location.search);
const result = urlParams.get('result');
if (result) {
resultsDiv.textContent = 'Crosswalked to: ' + result;
};
const checked_onet2soc = urlParams.get('checked_onet2soc');
if (checked_onet2soc) {
document.querySelector('input[name="codingSystem"][value="onet2soc"]').checked = true;
}
const checked_soc2cen = urlParams.get('checked_soc2cen');
if (checked_soc2cen) {
document.querySelector('input[name="codingSystem"][value="soc2cen"]').checked = true;
}
});
|