Refactoring
This commit is contained in:
@@ -64,6 +64,9 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
// Statistiken laden
|
||||
loadUserStats();
|
||||
|
||||
// Ping-IP laden
|
||||
loadPingIP();
|
||||
|
||||
loadWeek();
|
||||
|
||||
document.getElementById('prevWeek').addEventListener('click', function() {
|
||||
@@ -371,9 +374,9 @@ function renderWeek() {
|
||||
step="0.25"
|
||||
placeholder="0.00"
|
||||
${disabled}
|
||||
onblur="saveEntry(this)"
|
||||
onblur="handleOvertimeChange('${dateStr}', this.value); saveEntry(this);"
|
||||
oninput="updateOvertimeDisplay();"
|
||||
onchange="updateOvertimeDisplay();"
|
||||
onchange="handleOvertimeChange('${dateStr}', this.value); updateOvertimeDisplay();"
|
||||
style="width: 80px; margin-left: 5px;"
|
||||
class="overtime-input">
|
||||
<span>h</span>
|
||||
@@ -620,6 +623,85 @@ function updateOvertimeDisplay() {
|
||||
}
|
||||
}
|
||||
|
||||
// Überstunden-Änderung verarbeiten
|
||||
function handleOvertimeChange(dateStr, overtimeHours) {
|
||||
if (!userWochenstunden || userWochenstunden <= 0) {
|
||||
console.warn('Wochenstunden nicht verfügbar, kann Überstunden-Logik nicht anwenden');
|
||||
return;
|
||||
}
|
||||
|
||||
const fullDayHours = userWochenstunden / 5;
|
||||
const overtimeValue = parseFloat(overtimeHours) || 0;
|
||||
|
||||
// Prüfe ob ganzer Tag Überstunden
|
||||
if (overtimeValue > 0 && Math.abs(overtimeValue - fullDayHours) < 0.01) {
|
||||
// Ganzer Tag Überstunden
|
||||
// Setze Activity1 auf "Überstunden" mit 0 Stunden
|
||||
const activity1DescInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity1_desc"]`);
|
||||
const activity1HoursInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity1_hours"]`);
|
||||
|
||||
if (activity1DescInput) {
|
||||
activity1DescInput.value = 'Überstunden';
|
||||
// Trigger saveEntry für dieses Feld
|
||||
saveEntry(activity1DescInput);
|
||||
}
|
||||
|
||||
if (activity1HoursInput) {
|
||||
activity1HoursInput.value = '0';
|
||||
// Trigger saveEntry für dieses Feld
|
||||
saveEntry(activity1HoursInput);
|
||||
}
|
||||
|
||||
// Leere Start- und End-Zeit
|
||||
const startInput = document.querySelector(`input[data-date="${dateStr}"][data-field="start_time"]`);
|
||||
const endInput = document.querySelector(`input[data-date="${dateStr}"][data-field="end_time"]`);
|
||||
|
||||
if (startInput) {
|
||||
startInput.value = '';
|
||||
saveEntry(startInput);
|
||||
}
|
||||
|
||||
if (endInput) {
|
||||
endInput.value = '';
|
||||
saveEntry(endInput);
|
||||
}
|
||||
|
||||
} else if (overtimeValue > 0 && overtimeValue < fullDayHours) {
|
||||
// Weniger als ganzer Tag - füge "Überstunden" als Tätigkeit hinzu
|
||||
// Finde erste freie Activity-Spalte oder prüfe ob bereits vorhanden
|
||||
let foundOvertime = false;
|
||||
let firstEmptySlot = null;
|
||||
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
const descInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity${i}_desc"]`);
|
||||
const hoursInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity${i}_hours"]`);
|
||||
|
||||
if (descInput && descInput.value && descInput.value.trim().toLowerCase() === 'überstunden') {
|
||||
foundOvertime = true;
|
||||
break; // Bereits vorhanden
|
||||
}
|
||||
|
||||
if (!firstEmptySlot && descInput && (!descInput.value || descInput.value.trim() === '')) {
|
||||
firstEmptySlot = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn nicht gefunden und freier Slot vorhanden, füge hinzu
|
||||
if (!foundOvertime && firstEmptySlot) {
|
||||
const descInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity${firstEmptySlot}_desc"]`);
|
||||
const hoursInput = document.querySelector(`input[data-date="${dateStr}"][data-field="activity${firstEmptySlot}_hours"]`);
|
||||
|
||||
if (descInput) {
|
||||
descInput.value = 'Überstunden';
|
||||
saveEntry(descInput);
|
||||
}
|
||||
|
||||
// Stunden bleiben unverändert (werden vom User eingegeben oder bleiben leer)
|
||||
// total_hours bleibt auch unverändert
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Eintrag speichern
|
||||
async function saveEntry(input) {
|
||||
const date = input.dataset.date;
|
||||
@@ -1200,3 +1282,67 @@ function toggleSickStatus(dateStr) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ping-IP laden
|
||||
async function loadPingIP() {
|
||||
try {
|
||||
const response = await fetch('/api/user/ping-ip');
|
||||
if (!response.ok) {
|
||||
throw new Error('Fehler beim Laden der IP-Adresse');
|
||||
}
|
||||
const data = await response.json();
|
||||
const pingIpInput = document.getElementById('pingIpInput');
|
||||
if (pingIpInput) {
|
||||
pingIpInput.value = data.ping_ip || '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Ping-IP:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Ping-IP speichern (global für onclick)
|
||||
window.savePingIP = async function() {
|
||||
const pingIpInput = document.getElementById('pingIpInput');
|
||||
if (!pingIpInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pingIp = pingIpInput.value.trim();
|
||||
|
||||
// Finde den Button (nächstes Geschwisterelement oder über Parent)
|
||||
const button = pingIpInput.parentElement?.querySelector('button') ||
|
||||
document.querySelector('button[onclick*="savePingIP"]');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/user/ping-ip', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ ping_ip: pingIp })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
alert(result.error || 'Fehler beim Speichern der IP-Adresse');
|
||||
return;
|
||||
}
|
||||
|
||||
// Erfolgs-Feedback
|
||||
if (button) {
|
||||
const originalText = button.textContent;
|
||||
button.textContent = 'Gespeichert!';
|
||||
button.style.backgroundColor = '#27ae60';
|
||||
setTimeout(() => {
|
||||
button.textContent = originalText;
|
||||
button.style.backgroundColor = '';
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
console.log('Ping-IP gespeichert:', result.ping_ip);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Speichern der Ping-IP:', error);
|
||||
alert('Fehler beim Speichern der IP-Adresse');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user