WIP timesheet timers: give an error, if user overwrite stop- or pause-time before the start

This commit is contained in:
ralf 2022-10-06 13:56:44 +02:00
parent 196024a454
commit d6bfa7d9ee
3 changed files with 20 additions and 5 deletions

View File

@ -92,6 +92,7 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
* *
* @param {string} _action * @param {string} _action
* @param {string} _time * @param {string} _time
* @throws string error-message
*/ */
function timerAction(_action, _time) function timerAction(_action, _time)
{ {
@ -267,17 +268,22 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
* @param object _timer * @param object _timer
* @param bool|undefined _pause true: pause, else: stop * @param bool|undefined _pause true: pause, else: stop
* @param string|Date|undefined _time stop-time, default current time * @param string|Date|undefined _time stop-time, default current time
* @throws string error-message when timer.start < _time
*/ */
function stopTimer(_timer, _pause, _time) function stopTimer(_timer, _pause, _time)
{ {
const time = _time ? new Date(_time) : new Date(); const time = _time ? new Date(_time) : new Date();
// update _timer state object // update _timer state object
_timer.paused = _pause || false;
if (_timer.start) if (_timer.start)
{ {
if (time.valueOf() < _timer.start.valueOf())
{
throw egw.lang('Stop- or pause-time can not be before the start-time!');
}
_timer.offset = time.valueOf() - _timer.start.valueOf(); _timer.offset = time.valueOf() - _timer.start.valueOf();
_timer.start = undefined; _timer.start = undefined;
} }
_timer.paused = _pause || false;
// update timer display // update timer display
updateTimer(timer, _timer); updateTimer(timer, _timer);
@ -334,10 +340,15 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
callback: (button_id, value) => // return false to prevent dialog closing callback: (button_id, value) => // return false to prevent dialog closing
{ {
if (button_id !== 'close') { if (button_id !== 'close') {
timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'), try {
// eT2 operates in user-time, while timers here always operate in UTC timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'),
value.time ? new Date((new Date(value.time)).valueOf() + egw.getTimezoneOffset() * 60000) : undefined); // eT2 operates in user-time, while timers here always operate in UTC
dialog._overlayContentNode.querySelector('et2-date-time').value = ''; value.time ? new Date((new Date(value.time)).valueOf() + egw.getTimezoneOffset() * 60000) : undefined);
dialog._overlayContentNode.querySelector('et2-date-time').value = '';
}
catch (e) {
Et2Dialog.alert(e, egw.lang('Invalid Input'), Et2Dialog.ERROR_MESSAGE);
}
setButtonState(); setButtonState();
return false; return false;
} }

View File

@ -68,6 +68,7 @@ import options timesheet de Import Optionen
imports entries into the timesheet from a csv file. timesheet de Importiert Einträge für den Stundenzettel aus einer CSV Datei. imports entries into the timesheet from a csv file. timesheet de Importiert Einträge für den Stundenzettel aus einer CSV Datei.
insert timesheet de einfügen insert timesheet de einfügen
invalid field: %1 = %2, it needs to be a number. timesheet de Ungültiges Feld: %1 =%2, es muss eine Zahl sein invalid field: %1 = %2, it needs to be a number. timesheet de Ungültiges Feld: %1 =%2, es muss eine Zahl sein
invalid input common de Ungültige Eingabe
invalid owner id: %1. might be a bad field translation. used %2 instead. timesheet de Ungültiger Benutze ID: %1 könnte eine falsche Feldzuordnung haben. %2 wird stattdessen verwendet. invalid owner id: %1. might be a bad field translation. used %2 instead. timesheet de Ungültiger Benutze ID: %1 könnte eine falsche Feldzuordnung haben. %2 wird stattdessen verwendet.
last modified timesheet de Zuletzt geändert last modified timesheet de Zuletzt geändert
last month timesheet de Letzten Monat last month timesheet de Letzten Monat
@ -135,6 +136,7 @@ status deleted. timesheet de Status gelöscht
status of created timesheets timesheet de Status für neue Stundenzettel status of created timesheets timesheet de Status für neue Stundenzettel
status updated. timesheet de Status geändert status updated. timesheet de Status geändert
stop common de Stop stop common de Stop
stop- or pause-time can not be before the start-time! common de Stop- oder Pause-Zeit kann nicht vor der Start-Zeit liegen!
sum timesheet de Summe sum timesheet de Summe
sum %1: timesheet de Summe %1: sum %1: timesheet de Summe %1:
tag to mark positions for address labels timesheet de Platzhalter, um die Position der Adresslabels festzulegen tag to mark positions for address labels timesheet de Platzhalter, um die Position der Adresslabels festzulegen

View File

@ -68,6 +68,7 @@ import options timesheet en Import options
imports entries into the timesheet from a csv file. timesheet en Imports entries into the Time Sheet from a CSV file imports entries into the timesheet from a csv file. timesheet en Imports entries into the Time Sheet from a CSV file
insert timesheet en Insert insert timesheet en Insert
invalid field: %1 = %2, it needs to be a number. timesheet en Invalid field: %1 = %2, it needs to be a number. invalid field: %1 = %2, it needs to be a number. timesheet en Invalid field: %1 = %2, it needs to be a number.
invalid input common en Invalid input
invalid owner id: %1. might be a bad field translation. used %2 instead. timesheet en Invalid owner ID: %1. Might be a bad field translation. Used %2 instead. invalid owner id: %1. might be a bad field translation. used %2 instead. timesheet en Invalid owner ID: %1. Might be a bad field translation. Used %2 instead.
last modified timesheet en Last modified last modified timesheet en Last modified
last month timesheet en Last month last month timesheet en Last month
@ -135,6 +136,7 @@ status deleted. timesheet en Status deleted.
status of created timesheets timesheet en Status of created timesheets status of created timesheets timesheet en Status of created timesheets
status updated. timesheet en Status updated. status updated. timesheet en Status updated.
stop common en Stop stop common en Stop
stop- or pause-time can not be before the start-time! common en Stop- or pause-time can not be before the start-time!
sum timesheet en Sum sum timesheet en Sum
sum %1: timesheet en Sum %1: sum %1: timesheet en Sum %1:
tag to mark positions for address labels timesheet en Tag to mark positions for address labels tag to mark positions for address labels timesheet en Tag to mark positions for address labels