web-wecker/index.html

369 lines
12 KiB
HTML
Raw Normal View History

2024-03-20 17:22:47 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-03-22 08:43:31 +00:00
<title>Wecker in Übersicht</title>
2024-03-20 17:22:47 +00:00
<style>
2024-03-22 08:43:31 +00:00
.add {
2024-03-20 17:22:47 +00:00
font-family: Arial, sans-serif;
text-align: center;
2024-03-22 08:43:31 +00:00
padding-bottom: 1em;
2024-03-20 17:22:47 +00:00
}
.weekday-btn-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.weekday-btn {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
}
.weekday-checkbox {
/* margin-right: 1px; /* Angepasst */
margin-bottom: 1em;
}
.weekday-text {
display: inline-block;
margin-right: 1em;
}
.timecl{
padding: 1em;
}
2024-03-22 08:43:31 +00:00
.json-element {
border: 1px solid #ccc;
margin-bottom: 10px;
padding: 10px;
position: relative; /* Um Positionierung für die Buttons zu ermöglichen */
}
.weekday-btn-container {
display: flex;
flex-wrap: wrap;
}
.weekday-btn-container div {
margin-right: 10px;
}
.custom-checkbox {
position: relative;
cursor: pointer;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 5px;
}
.custom-checkbox input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 24px;
width: 24px;
background-color: #eee;
border-radius: 50%;
z-index: -1;
}
.custom-checkbox input:checked ~ .checkmark {
background-color: #54f17b;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.custom-checkbox input:checked ~ .checkmark:after {
display: none;
}
.custom-checkbox .checkmark:after {
content: "";
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 12px;
height: 12px;
border-radius: 50%;
background: white;
}
h1{
text-align: center;
}
.edit-button, .delete-button {
position: absolute; /* Änderung von fixed auf absolute */
cursor: pointer;
width: 1.75em;
height: 1.75em;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
font-size: 20px;
}
.edit-button {
background-color: #2196F3;
color: white;
bottom: 0.35em;
right: 2.65em;
}
.delete-button {
background-color: #FF0000;
color: white;
bottom: 0.35em;
right: 0.35em; /* Anpassung der Positionierung */
}
2024-03-20 17:22:47 +00:00
</style>
</head>
<body>
2024-03-22 08:43:31 +00:00
<h1>Wecker in Übersicht</h1>
<div class="add">
2024-03-20 17:22:47 +00:00
<form >
2024-03-22 08:43:31 +00:00
<p for="weckerName0">Name des Weckers:</label><br>
2024-03-20 17:22:47 +00:00
<input type="text" id="weckerName"><br>
</form>
<div class="timecl">
<input type="text" id="timePick" value="08:06">
</div>
<div class="weekday-btn-container">
<div>
<input type="checkbox" id="montagCheckbox" class="weekday-checkbox">
<label for="montagCheckbox" class="weekday-text">Montag</label>
</div>
<div>
<input type="checkbox" id="dienstagCheckbox" class="weekday-checkbox">
<label for="dienstagCheckbox" class="weekday-text">Dienstag</label>
</div>
<div>
<input type="checkbox" id="mittwochCheckbox" class="weekday-checkbox">
<label for="mittwochCheckbox" class="weekday-text">Mittwoch</label>
</div>
<div>
<input type="checkbox" id="donnerstagCheckbox" class="weekday-checkbox">
<label for="donnerstagCheckbox" class="weekday-text">Donnerstag</label>
</div>
<div>
<input type="checkbox" id="freitagCheckbox" class="weekday-checkbox">
<label for="freitagCheckbox" class="weekday-text">Freitag</label>
</div>
<div>
<input type="checkbox" id="samstagCheckbox" class="weekday-checkbox">
<label for="samstagCheckbox" class="weekday-text">Samstag</label>
</div>
<div>
<input type="checkbox" id="sonntagCheckbox" class="weekday-checkbox">
<label for="sonntagCheckbox" class="weekday-text">Sonntag</label>
</div>
</div>
<button onclick="saveData()">Speichern</button>
2024-03-22 08:43:31 +00:00
</div>
<div id="jsonContainer"></div>
2024-03-20 17:22:47 +00:00
<script>
2024-03-22 08:43:31 +00:00
2024-03-20 17:22:47 +00:00
function saveName() {
const nameElement = document.getElementById('weckerName');
if (nameElement) {
const nameValue = nameElement.value;
if (nameValue) {
console.log('ID "weckerName" existiert und Variable NameValue ist befüllt:', nameValue);
// AJAX-Anfrage an den Server senden
const xhr = new XMLHttpRequest();
xhr.open('POST', '/saveName');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({ name: nameValue })); // Hier senden wir den Wert als "name"
} else {
console.log('ID "weckerName" existiert, aber Variable NameValue ist leer.');
}
} else {
console.log('ID "weckerName" existiert nicht.');
}
}
function saveTime() {
const timeElement = document.getElementById('timePick');
if (timeElement) {
const timeValue = timeElement.value;
if (timeValue) {
console.log('ID "timePick" existiert und Variable timeValue ist befüllt:', timeValue);
// AJAX-Anfrage an den Server senden
const xhr = new XMLHttpRequest();
xhr.open('POST', '/saveTime');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({ time: timeValue })); // Hier senden wir den Wert als "time"
} else {
console.log('ID "timePick" existiert, aber Variable timeValue ist leer.');
}
} else {
console.log('ID "timePick" existiert nicht.');
}
}
function savedays() {
const daysValue = {
Montag: document.getElementById('montagCheckbox').checked,
Dienstag: document.getElementById('dienstagCheckbox').checked,
Mittwoch: document.getElementById('mittwochCheckbox').checked,
Donnerstag: document.getElementById('donnerstagCheckbox').checked,
Freitag: document.getElementById('freitagCheckbox').checked,
Samstag: document.getElementById('samstagCheckbox').checked,
Sonntag: document.getElementById('sonntagCheckbox').checked
};
// AJAX-Anfrage an den Server senden
const xhr = new XMLHttpRequest();
xhr.open('POST', '/savedays');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(daysValue));
}
2024-03-22 08:43:31 +00:00
window.onload = function() {
fetchDataAndRender();
}
function fetchDataAndRender(){
fetch('/selectedTime')
.then(response => response.json())
.then(data => { renderData(data); // Daten rendern
})
.catch(error => console.error('Error fetching data:', error));
}
function renderData(data) {
const jsonContainer = document.getElementById('jsonContainer');
jsonContainer.innerHTML = '';
data.forEach(item => {
const jsonElement = document.createElement('div');
jsonElement.classList.add('json-element');
const name = document.createElement('p');
name.textContent = `Name: ${item.NameValue.name}`;
jsonElement.appendChild(name);
const time = document.createElement('p');
time.textContent = `Time: ${item.timeValue.time}`;
jsonElement.appendChild(time);
const daysValue = item.daysValue;
const weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
const weekdayContainer = document.createElement('div');
weekdayContainer.classList.add('weekday-btn-container');
weekdays.forEach((day, index) => {
const checkboxDiv = document.createElement('div');
const checkbox = document.createElement('label');
checkbox.classList.add('custom-checkbox');
const input = document.createElement('input');
input.type = 'checkbox';
input.id = `${day.toLowerCase()}Checkbox`;
input.checked = daysValue[Object.keys(daysValue)[index]];
// Preventing checkbox clicks
checkbox.addEventListener('click', function(event) {
event.preventDefault();
});
const checkmark = document.createElement('span');
checkmark.classList.add('checkmark');
const labelText = document.createElement('span');
labelText.textContent = day;
checkbox.appendChild(input);
checkbox.appendChild(checkmark);
checkbox.appendChild(labelText);
checkboxDiv.appendChild(checkbox);
weekdayContainer.appendChild(checkboxDiv);
});
jsonElement.appendChild(weekdayContainer);
const editButton = document.createElement('div'); // Jetzt innerhalb der Schleife erstellt
editButton.classList.add('edit-button');
editButton.innerHTML = '&#9998;';
editButton.setAttribute('id', `${item.NameValue.name}-edit-button`);
// Add click event for edit button
editButton.addEventListener('click', function() {
console.log('Edit button clicked for', item.NameValue.name);
});
jsonElement.appendChild(editButton); // Hinzufügen des edit-buttons zum JSON-Element
const deleteButton = document.createElement('div');
deleteButton.classList.add('delete-button');
deleteButton.innerHTML = '&#128465;';
deleteButton.setAttribute('id', `${item.NameValue.name}-delete-button`);
// Add click event for delete button
deleteButton.addEventListener('click', function() {
const name = item.NameValue.name;
deleteAlarm(name);
});
jsonElement.appendChild(deleteButton); // Hinzufügen des delete-buttons zum JSON-Element
jsonContainer.appendChild(jsonElement);
});
}
function deleteAlarm(name) {
fetch('/deleteAlarm', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: name })
})
.then(response => response.text())
2024-03-26 13:39:14 +00:00
/* .then(message => {
2024-03-22 08:43:31 +00:00
console.log(message);
alert(message); // Benutzerfeedback anzeigen
fetchDataAndRender(); // Daten erneut abrufen und Benutzeroberfläche neu rendern
2024-03-26 13:39:14 +00:00
})*/
.then ( fetchDataAndRender() )
2024-03-22 08:43:31 +00:00
.catch(error => console.error('Error deleting alarm:', error));
}
function saveData() {
saveName();
saveTime();
savedays();
setTimeout(fetchDataAndRender, 50);// Daten nach dem Speichern neu abrufen und rendern
console.log("hi");
console.log("h2i");
}
2024-03-20 17:22:47 +00:00
</script>
<script src="./time-pick.js"></script>
<script>
var timepicker = new TimePick('#timePick');
var timepickerz = new TimePick('.timePicker');
</script>
</body>
</html>