mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 17:04:14 +01:00
WIP timesheet timer: ask user to start/stop working time with session/login/logout
if working time is not disabled in timesheet config, or asking is disabled in user preferences
This commit is contained in:
parent
aa139d2f15
commit
49f608159c
@ -402,8 +402,10 @@ import "sortablejs/Sortable.min.js";
|
||||
{
|
||||
$logout.on('click', function(e){
|
||||
e.preventDefault();
|
||||
self.callOnLogout(e);
|
||||
window.framework.redirect(this.href);
|
||||
egw.onLogout_timer().then(() => {
|
||||
self.callOnLogout(e);
|
||||
window.framework.redirect(this.href);
|
||||
});
|
||||
});
|
||||
$logout.addClass('onLogout');
|
||||
}
|
||||
@ -556,4 +558,4 @@ import "sortablejs/Sortable.min.js";
|
||||
}
|
||||
}
|
||||
});
|
||||
})(window);
|
||||
})(window);
|
@ -96,6 +96,7 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
||||
* @param {string} _action
|
||||
* @param {string} _time
|
||||
* @param {string} _app_id
|
||||
* @return Promise from egw.request() to wait for state being persisted on server
|
||||
* @throws string error-message
|
||||
*/
|
||||
function timerAction(_action, _time, _app_id)
|
||||
@ -135,7 +136,7 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
||||
specific.app_id = _app_id;
|
||||
}
|
||||
// persist state
|
||||
egw.request('timesheet.EGroupware\\Timesheet\\Events.ajax_event', [getState(_action, _time)]).then((tse_id) => {
|
||||
return egw.request('timesheet.EGroupware\\Timesheet\\Events.ajax_event', [getState(_action, _time)]).then((tse_id) => {
|
||||
if (_action.substring(0, 8) === 'specific')
|
||||
{
|
||||
specific.id = tse_id;
|
||||
@ -390,6 +391,59 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
||||
return formatTime(new Date(date.valueOf() - egw.getTimezoneOffset() * 60000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the timer dialog to start/stop timers
|
||||
*
|
||||
* @param {Array} disable
|
||||
* @param {string} _title default "Start & stop timer"
|
||||
*/
|
||||
function timerDialog(disable, _title)
|
||||
{
|
||||
// Pass egw in the constructor
|
||||
dialog = new Et2Dialog(egw);
|
||||
|
||||
// Set attributes. They can be set in any way, but this is convenient.
|
||||
dialog.transformAttributes({
|
||||
// If you use a template, the second parameter will be the value of the template, as if it were submitted.
|
||||
callback: (button_id, value) => // return false to prevent dialog closing
|
||||
{
|
||||
if (button_id !== 'close') {
|
||||
try {
|
||||
timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'),
|
||||
// eT2 operates in user-time, while timers here always operate in UTC
|
||||
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();
|
||||
return false;
|
||||
}
|
||||
dialog = undefined;
|
||||
},
|
||||
title: _title || 'Start & stop timer',
|
||||
template: egw.webserverUrl + '/timesheet/templates/default/timer.xet',
|
||||
buttons: [
|
||||
{label: egw.lang("Close"), id: "close", default: true, image: "cancel"},
|
||||
],
|
||||
value: {
|
||||
content: {
|
||||
disable: disable.join(':')
|
||||
},
|
||||
sel_options: {}
|
||||
}
|
||||
});
|
||||
// Add to DOM, dialog will auto-open
|
||||
document.body.appendChild(dialog);
|
||||
dialog.getUpdateComplete().then(() => {
|
||||
// enable/disable buttons based on timer state
|
||||
setButtonState();
|
||||
// update timers in dialog
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Start timer for given app and id
|
||||
@ -449,50 +503,68 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
||||
|
||||
// bind click handler
|
||||
timer_container.addEventListener('click', (ev) => {
|
||||
// Pass egw in the constructor
|
||||
dialog = new Et2Dialog(egw);
|
||||
timerDialog(state.disable);
|
||||
});
|
||||
|
||||
// Set attributes. They can be set in any way, but this is convenient.
|
||||
dialog.transformAttributes({
|
||||
// If you use a template, the second parameter will be the value of the template, as if it were submitted.
|
||||
callback: (button_id, value) => // return false to prevent dialog closing
|
||||
// check if overall working time is not disabled
|
||||
if (state.disable.indexOf('overall') === -1)
|
||||
{
|
||||
// check if we should ask on login to start working time
|
||||
this.preference('workingtime_session', 'timesheet', true).then(pref =>
|
||||
{
|
||||
if (pref === 'no') return;
|
||||
|
||||
// overall timer not running, ask to start
|
||||
if (overall && !overall.start)
|
||||
{
|
||||
if (button_id !== 'close') {
|
||||
try {
|
||||
timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'),
|
||||
// eT2 operates in user-time, while timers here always operate in UTC
|
||||
value.time ? new Date((new Date(value.time)).valueOf() + egw.getTimezoneOffset() * 60000) : undefined);
|
||||
dialog._overlayContentNode.querySelector('et2-date-time').value = '';
|
||||
Et2Dialog.show_dialog((button) => {
|
||||
if (button === Et2Dialog.YES_BUTTON)
|
||||
{
|
||||
timerAction('overall-start');
|
||||
}
|
||||
catch (e) {
|
||||
Et2Dialog.alert(e, egw.lang('Invalid Input'), Et2Dialog.ERROR_MESSAGE);
|
||||
}
|
||||
setButtonState();
|
||||
return false;
|
||||
}
|
||||
dialog = undefined;
|
||||
},
|
||||
title: 'Start & stop timer',
|
||||
template: egw.webserverUrl + '/timesheet/templates/default/timer.xet',
|
||||
buttons: [
|
||||
{label: egw.lang("Close"), id: "close", default: true, image: "cancel"},
|
||||
],
|
||||
value: {
|
||||
content: {
|
||||
disable: state.disable.join(':')
|
||||
},
|
||||
sel_options: {}
|
||||
}, 'Do you want to start your working time?', 'Working time', {}, Et2Dialog.BUTTONS_YES_NO);
|
||||
}
|
||||
// overall timer running for more than 16 hours, ask to stop
|
||||
else if (overall?.start && (((new Date()).valueOf() - overall.start.valueOf()) / 3600000) >= 16)
|
||||
{
|
||||
// gives a JS error, if called direct
|
||||
window.setTimeout(() => {
|
||||
timerDialog(state.disable, 'Forgot to switch off working time?');
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
// Add to DOM, dialog will auto-open
|
||||
document.body.appendChild(dialog);
|
||||
dialog.getUpdateComplete().then(() => {
|
||||
// enable/disable buttons based on timer state
|
||||
setButtonState();
|
||||
// update timers in dialog
|
||||
update();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Ask user to stop working time
|
||||
*
|
||||
* @returns {Promise<void>} resolved once user answered, to continue logout
|
||||
*/
|
||||
onLogout_timer: function()
|
||||
{
|
||||
let promise;
|
||||
if (overall.start || overall.paused)
|
||||
{
|
||||
promise = new Promise((_resolve, _reject) =>
|
||||
{
|
||||
Et2Dialog.show_dialog((button) => {
|
||||
if (button === Et2Dialog.YES_BUTTON)
|
||||
{
|
||||
timerAction('overall-stop').then(_resolve);
|
||||
}
|
||||
else
|
||||
{
|
||||
_resolve();
|
||||
}
|
||||
}, 'Do you want to stop your working time?', 'Working time', {}, Et2Dialog.BUTTONS_YES_NO);
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
promise = Promise.resolve();
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
});
|
@ -165,6 +165,18 @@ class timesheet_hooks
|
||||
if (is_null(self::$timesheet_bo)) self::$timesheet_bo = new timesheet_bo();
|
||||
if (self::$timesheet_bo->status_labels)
|
||||
{
|
||||
$settings['workingtime_session'] = array(
|
||||
'type' => 'select',
|
||||
'label' => 'Ask to start and stop working time with session',
|
||||
'name' => 'workingtime_session',
|
||||
'values' => [
|
||||
'' => 'yes',
|
||||
'no' => 'no',
|
||||
],
|
||||
'help' => 'Would you like to be asked, to start and stop working time, when login in or off',
|
||||
'xmlrpc' => True,
|
||||
'admin' => False,
|
||||
);
|
||||
$settings['predefined_status'] = array(
|
||||
'type' => 'select',
|
||||
'label' => 'Status of created timesheets',
|
||||
|
@ -8,6 +8,7 @@ all projects timesheet de Alle Projekte
|
||||
and its members timesheet de und die Mitglieder
|
||||
applies the changes timesheet de Änderungen durchführen
|
||||
apply the action on the whole query, not only the shown timesheets!!! timesheet de Wendet den Befehl auf die gesamte Abfrage an, NICHT nur die angezeigten Stundenzettel!!
|
||||
ask to start and stop working time with session timesheet de Fragen die Arbeitszeit mit der Sitzung zu starten oder stoppen
|
||||
both: allow to use projectmanager and free project-names admin de Beides: verwende Projektmanager und freie Projektnamen
|
||||
by timesheet de von
|
||||
category for 'working time' admin de Kategorie für 'Arbeitszeit'
|
||||
@ -30,6 +31,8 @@ determines the order the fields are displayed timesheet de verändert die Reihen
|
||||
directory with documents to insert entries timesheet de Ordner mit Dokumenten zum Einfügen.
|
||||
disable timers timesheet de Zeitnehmer ausschalten
|
||||
do you want to associate it with the selected %1 entry? common de Wollen Sie ihn mit dem ausgewählten %1 Eintrag verbinden?
|
||||
do you want to start your working time? common de Wollen Sie Ihre Arbeitszeit starten?
|
||||
do you want to stop your working time? common de Wollen Sie Ihre Arbeitszeit beenden?
|
||||
each value is a line like <id>[=<label>] timesheet de jeder Wert ist eine Zeile in dem Format <id>[=|label>]
|
||||
edit status common de Status bearbeiten
|
||||
edit this entry timesheet de diesen Eintrag bearbeiten
|
||||
@ -54,6 +57,7 @@ exports entries from your timesheet into a csv file. csv means 'comma separated
|
||||
favorites timesheet de Favoriten
|
||||
field must not be empty !!! timesheet de Dieses Feld darf nicht leer sein!!!
|
||||
for serial letter use this tag. put the content, you want to repeat between two tags. timesheet de Für den Seriendruck, wählen die diesen Platzhalter. Fügen Sie den Inhalt, den Sie wiederholen möchten, zwischen zwei Platzhaltern ein.
|
||||
forgot to switch off working time? common de Haben Sie vergessen Ihre Arbeitszeit zu beenden?
|
||||
full: use only projectmanager admin de Komplett: verwende nur Projektmanager
|
||||
general fields: timesheet de Das Löschen von Einträgen verhindern
|
||||
global categories timesheet de Globale Kategorien
|
||||
@ -180,6 +184,7 @@ working time common de Arbeitszeit
|
||||
working time and timer timesheet de Arbeitszeit und Zeitnehmer
|
||||
working time from %1 timesheet de Arbeitszeit vom %1
|
||||
working time of %1 hours stored timesheet de Arbeitszeit von %1 Stunden gespeichert
|
||||
would you like to be asked, to start and stop working time, when login in or off timesheet de Wollen Sie gefragt werden die Arbeitszeit to starten oder stoppen, wenn Sie sich an- oder abmelden
|
||||
yes, only admins can purge deleted items admin de Ja, nur Administratoren dürfen gelöschte Einträge endgültig löschen
|
||||
yes, users can purge their deleted items admin de Ja, Benutzer dürfen ihre gelöschten Einträge endgültig löschen
|
||||
yesterday timesheet de Gestern
|
||||
|
@ -8,6 +8,7 @@ all projects timesheet en All projects
|
||||
and its members timesheet en And its members
|
||||
applies the changes timesheet en Applies the changes
|
||||
apply the action on the whole query, not only the shown timesheets!!! timesheet en Apply the action on the whole query, NOT only the shown timesheets!
|
||||
ask to start and stop working time with session timesheet en Ask to start and stop working time with session
|
||||
both: allow to use projectmanager and free project-names admin en Both: allow to use Project Manager and free project names
|
||||
by timesheet en by
|
||||
category for 'working time' admin en Category for 'Working time'
|
||||
@ -30,6 +31,8 @@ determines the order the fields are displayed timesheet en Determines the order
|
||||
directory with documents to insert entries timesheet en Directory with documents to insert entries
|
||||
disable timers timesheet en Disable timers
|
||||
do you want to associate it with the selected %1 entry? common en Do you want to associate it with the selected %1 entry?
|
||||
do you want to start your working time? common en Do you want to start your working time?
|
||||
do you want to stop your working time? common en Do you want to stop your working time?
|
||||
each value is a line like <id>[=<label>] timesheet en Each value is a line like <id>[=<label>]
|
||||
edit status common en Edit status
|
||||
edit this entry timesheet en Edit this entry
|
||||
@ -54,6 +57,7 @@ exports entries from your timesheet into a csv file. csv means 'comma separated
|
||||
favorites timesheet en Favorites
|
||||
field must not be empty !!! timesheet en Field must not be empty!
|
||||
for serial letter use this tag. put the content, you want to repeat between two tags. timesheet en For serial letter use this tag. Put the content, you want to repeat between two Tags.
|
||||
forgot to switch off working time? common en Forgot to switch off working time?
|
||||
full: use only projectmanager admin en Full: use only Project Manager
|
||||
general fields: timesheet en General fields:
|
||||
global categories timesheet en Global categories
|
||||
@ -180,6 +184,7 @@ working time common en Working time
|
||||
working time and timer timesheet en Working time and timer
|
||||
working time from %1 timesheet en Working time from %1
|
||||
working time of %1 hours stored timesheet en Working time of %1 hours stored
|
||||
would you like to be asked, to start and stop working time, when login in or off timesheet en Would you like to be asked, to start and stop working time, when login in or off
|
||||
yes, only admins can purge deleted items admin en Yes, only admins can purge deleted items
|
||||
yes, users can purge their deleted items admin en Yes, users can purge their deleted items
|
||||
yesterday timesheet en Yesterday
|
||||
|
Loading…
Reference in New Issue
Block a user