bunteshaus.de/themes/buha/static/js/generator.js

134 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-03-27 19:58:39 +02:00
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();
2022-04-04 05:39:34 +02:00
document.getElementById("display").style.display = "flex";
2022-03-27 19:58:39 +02:00
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"]');
2022-04-04 00:42:08 +02:00
var title = form.elements['newtitle'].value;
2022-03-27 19:58:39 +02:00
var content = form.elements['content'].value;
2022-04-04 00:42:08 +02:00
var when = form.elements['newwhen'].value;
2022-04-04 01:13:42 +02:00
// var covid = form.elements['newcovid'].value;
2022-04-04 00:42:08 +02:00
var price = form.elements['newprice'].value;
var registeremail = form.elements['newregisteremail'].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(',')); }
2022-03-27 19:58:39 +02:00
var tags = check_checkboxes('tags');
2022-04-04 00:42:08 +02:00
if (form.elements['newtags']) { var newtags = testor(form.elements['newtags'].value.split(',')); }
2022-03-27 19:58:39 +02:00
var featured = check_checkboxes('featured');
2022-04-04 01:13:42 +02:00
var about = check_checkboxes('about');
2022-03-27 19:58:39 +02:00
2022-04-04 00:42:08 +02:00
if (newtags != '""') {
var ntags = newtags;
2022-03-27 19:58:39 +02:00
}
if (tags != '') {
var ntags = tags;
}
2022-04-04 00:42:08 +02:00
if (tags != '' && newtags != '""') {
var ntags = tags + "," + newtags;
2022-03-27 19:58:39 +02:00
}
2022-04-04 00:42:08 +02:00
if (newcategories != '""') {
var ncategories = newcategories;
}
if (categories != '') {
var ncategories = categories;
}
if (categories != '' && newcategories != '""') {
var ncategories = categories + "," + newcategories;
}
2022-03-27 19:58:39 +02:00
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>";
2022-03-27 20:14:36 +02:00
if (featured != '') {
display.innerHTML += "featured: true<br>";
}
2022-03-27 19:58:39 +02:00
2022-04-04 01:13:42 +02:00
if (about != '') {
display.innerHTML += "about: true<br>";
}
2022-04-03 21:08:42 +02:00
if (when) {
display.innerHTML += "when: \"" + when + "\"<br>";
}
2022-04-04 00:42:08 +02:00
if (ncategories) {
display.innerHTML += "categories: \[" + ncategories + "]<br>";
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
2022-04-04 00:42:08 +02:00
if (events != '') {
display.innerHTML += "events: \[" + events + "]<br>";
2022-03-27 20:14:36 +02:00
}
2022-04-03 21:08:42 +02:00
2022-03-27 20:14:36 +02:00
if (ntags) {
display.innerHTML += "tags: \[" + ntags + "]<br>";
}
2022-04-04 01:13:42 +02:00
// if (covid) {
// display.innerHTML += "covid: \"" + covid + "\"<br>";
// }
2022-04-03 21:08:42 +02:00
if (price) {
display.innerHTML += "price: \"" + price + "\"<br>";
}
if (registeremail) {
display.innerHTML += "registeremail: \"" + registeremail + "\"<br>";
}
2022-03-27 20:14:36 +02:00
display.innerHTML += "---<br>";
if (content) {
2022-03-27 20:40:45 +02:00
display.innerHTML += content;
2022-03-27 20:14:36 +02:00
}
2022-03-27 19:58:39 +02:00
}
}