diff --git a/app/static/app/js/home.js b/app/static/app/js/home.js index 24b6a7a..f694f17 100644 --- a/app/static/app/js/home.js +++ b/app/static/app/js/home.js @@ -158,6 +158,17 @@ sonstigesCheck.addEventListener('change', function() { } }); +// function newEntryAfterTimer(timerStamp) { +// const seconds = parseInt(timerStamp) +// const hours = String(Math.floor(seconds / 3600)).padStart(2, '0'); +// const minutes = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0'); +// const secs = String(seconds % 60).padStart(2, '0'); +// document.getElementById('openNewEntryForm').click() +// document.getElementById('stunden').value = hours; +// document.getElementById('minuten').value = minutes; +// console.log(secs) +// } + // diff --git a/app/static/app/js/timer.js b/app/static/app/js/timer.js index 234da74..320e186 100644 --- a/app/static/app/js/timer.js +++ b/app/static/app/js/timer.js @@ -67,8 +67,7 @@ pauseButton.addEventListener('click', () => { } }); -// Timer zurücksetzen und Speicher leeren -resetButton.addEventListener('click', () => { +function clearTimer(){ clearInterval(timerInterval); elapsedTime = 0; timerIsReset(); @@ -76,12 +75,33 @@ resetButton.addEventListener('click', () => { localStorage.removeItem('startTime'); localStorage.removeItem('elapsedTime'); displayTime(0); +} - // ... ab hier wird die Funktion getriggert die das Formular zur Eintrags erstellung triggert - document.getElementById('openNewEntryForm').click() - + +// Timer zurücksetzen und Speicher leeren +resetButton.addEventListener('click', () => { + + const timerStamp = Math.floor((Date.now() - localStorage.getItem('startTime')) / 1000); + const seconds = parseInt(timerStamp) + const hours = String(Math.floor(seconds / 3600)).padStart(2, '0'); + const minutes = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0'); + const secs = String(seconds % 60).padStart(2, '0'); + + if (minutes > 0) { + document.getElementById('openNewEntryForm').click() + document.getElementById('stunden').value = hours; + document.getElementById('minuten').value = minutes; + checkInput() + document.getElementById('newEntrySubmitButton').addEventListener('click', () => { + clearTimer(); + }) + } else { + clearTimer() + } }); + + // Timer-Funktion, die die vergangene Zeit seit dem Start berechnet function startTimer(startTime) { clearInterval(timerInterval); // Vorherigen Timer stoppen, falls vorhanden