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();
|
|
|
|
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 event = form.elements['event'].value;
|
|
|
|
var cats = check_checkboxes('category');
|
|
|
|
var newcat = testor(form.elements['newcat'].value.split(','));
|
|
|
|
var tags = check_checkboxes('tags');
|
|
|
|
var newtag = testor(form.elements['newtag'].value.split(','));
|
|
|
|
var featured = check_checkboxes('featured');
|
|
|
|
|
|
|
|
if (newcat != '""') {
|
|
|
|
var ncats = newcat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cats != '') {
|
|
|
|
var ncats = cats;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cats != '' && newcat != '""') {
|
|
|
|
var ncats = cats + "," + newcat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newtag != '""') {
|
|
|
|
var ntags = newtag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tags != '') {
|
|
|
|
var ntags = tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tags != '' && newtag != '""') {
|
|
|
|
var ntags = tags + "," + newtag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!title) {
|
|
|
|
display.innerHTML += "Title is missing..<br>"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!content) {
|
|
|
|
display.innerHTML += "Content is missing..<br>"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (title && content) {
|
2022-03-27 20:39:19 +02:00
|
|
|
display.innerHTML += "<div id=\"result\">";
|
2022-03-27 19:58:39 +02:00
|
|
|
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-03-27 20:14:36 +02:00
|
|
|
if (event) {
|
|
|
|
display.innerHTML += "when: \"" + event + "\"<br>";
|
|
|
|
}
|
2022-03-27 19:58:39 +02:00
|
|
|
|
2022-03-27 20:14:36 +02:00
|
|
|
if (ncats) {
|
|
|
|
display.innerHTML += "categories: \[" + ncats + "]<br>";
|
|
|
|
}
|
|
|
|
if (ntags) {
|
|
|
|
display.innerHTML += "tags: \[" + ntags + "]<br>";
|
|
|
|
}
|
|
|
|
display.innerHTML += "---<br>";
|
|
|
|
if (content) {
|
|
|
|
display.innerHTML += content + "</div><br>";
|
|
|
|
}
|
2022-03-27 19:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|