bunteshaus.de/themes/buha/static/js/generator.js
2022-04-06 19:32:09 +02:00

151 lines
3.7 KiB
JavaScript

function check_checkboxes(name) {
const checkboxes = document.querySelectorAll(`input[name="${name}"]:checked`);
let values = [];
checkboxes.forEach((checkbox) => {
values.push("\"" + checkbox.value + "\"");
});
if (values) {
return values;
} else {
return null;
}
}
function testor(input) {
let v1 = [];
input.forEach((input) => {
v1.push("\"" + input.trim() + "\"");
});
if (v1) {
return v1;
} else {
return null;
}
}
function showInput(e) {
document.getElementById("display").innerHTML = '';
e.preventDefault();
document.getElementById("display").style.display = "flex";
var output_info = document.getElementById("myform");
var display = document.getElementById("display");
var d = new Date();
var datestring = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) + "T" + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":00+02:00\"";
var form = document.querySelector('form[id="myform"]');
var title = form.elements['title'].value;
var content = form.elements['content'].value;
var when = form.elements['when'].value;
// var covid = form.elements['newcovid'].value;
var price = form.elements['price'].value;
var contact = form.elements['contact'].value;
var events = check_checkboxes('events');
if (form.elements['newevents']) { var newevents = testor(form.elements['newevents'].value.split(',')); }
var categories = check_checkboxes('categories');
if (form.elements['newcategories']) { var newcategories = testor(form.elements['newcategories'].value.split(',')); }
var tags = check_checkboxes('tags');
if (form.elements['newtags']) { var newtags = testor(form.elements['newtags'].value.split(',')); }
var featured = check_checkboxes('featured');
var about = check_checkboxes('about');
if (newtags != '""') {
var ntags = newtags;
}
if (tags != '') {
var ntags = tags;
}
if (tags != '' && newtags != '""') {
var ntags = tags + "," + newtags;
}
if (newcategories != '""') {
var ncategories = newcategories;
}
if (categories != '') {
var ncategories = categories;
}
if (categories != '' && newcategories != '""') {
var ncategories = categories + "," + newcategories;
}
if (newevents != '""') {
var nevents = newevents;
}
if (events != '') {
var nevents = events;
}
if (events != '' && newevents != '""') {
var nevents = events + "," + newevents;
}
if (!title) {
display.innerHTML += "Title is missing..<br>"
}
if (!content) {
display.innerHTML += "Content is missing..<br>"
}
if (title && content) {
display.innerHTML += "---<br>";
display.innerHTML += "title: \"" + title + "\"<br>";
display.innerHTML += "date: \"" + datestring + "<br>";
if (featured != '') {
display.innerHTML += "featured: true<br>";
}
if (about != '') {
display.innerHTML += "about: true<br>";
}
if (when) {
display.innerHTML += "when: \"" + when + "\"<br>";
}
if (ncategories) {
display.innerHTML += "categories: \[" + ncategories + "]<br>";
}
if (nevents) {
display.innerHTML += "events: \[" + nevents + "]<br>";
}
if (ntags) {
display.innerHTML += "tags: \[" + ntags + "]<br>";
}
// if (covid) {
// display.innerHTML += "covid: \"" + covid + "\"<br>";
// }
if (price) {
display.innerHTML += "price: \"" + price + "\"<br>";
}
if (contact) {
display.innerHTML += "contact: \"" + contact + "\"<br>";
}
display.innerHTML += "---<br>";
if (content) {
display.innerHTML += content;
}
}
}