Shifts creation: Add reset to previous input

This commit is contained in:
Igor Scheller 2023-12-25 23:55:08 +01:00 committed by msquare
parent 7888dfad78
commit 197d0d724a
4 changed files with 46 additions and 18 deletions

View File

@ -351,9 +351,9 @@ function admin_shifts()
$session->set('admin_shifts_shifts', $shifts);
$session->set('admin_shifts_types', $needed_angel_types);
$hidden_types = '';
$previousEntries = [];
foreach ($needed_angel_types as $type_id => $count) {
$hidden_types .= form_hidden('angeltype_count_' . $type_id, $count);
$previousEntries['angeltype_count_' . $type_id] = $count;
}
// Number of Shifts that will be created (if over 100 its danger-red)
@ -363,20 +363,30 @@ function admin_shifts()
$shiftsCreationHint = '<span class="text-danger">' . $shiftsCreationHint . '</span>';
}
// Save as previous state to be able to reuse it
$previousEntries += [
'shifttype_id' => $shifttype_id,
'description' => $description,
'title' => $title,
'lid' => $lid,
'start' => $request->input('start'),
'end' => $request->input('end'),
'mode' => $mode,
'length' => $length,
'change_hours' => implode(', ', $change_hours),
'angelmode' => $angelmode,
'shift_over_midnight' => $shift_over_midnight ? 'true' : 'false',
];
$session->set('admin_shifts_previous', $previousEntries);
$hidden_types = '';
foreach ($previousEntries as $name => $value) {
$hidden_types .= form_hidden($name, $value);
}
return page_with_title(__('form.preview'), [
form([
$hidden_types,
form_hidden('shifttype_id', $shifttype_id),
form_hidden('description', $description),
form_hidden('title', $title),
form_hidden('lid', $lid),
form_hidden('start', $request->input('start')),
form_hidden('end', $request->input('end')),
form_hidden('mode', $mode),
form_hidden('length', $length),
form_hidden('change_hours', implode(', ', $change_hours)),
form_hidden('angelmode', $angelmode),
form_hidden('shift_over_midnight', $shift_over_midnight ? 'true' : 'false'),
form_submit('back', icon('chevron-left') . __('general.back')),
$shiftsCreationHint,
table([
@ -456,12 +466,27 @@ function admin_shifts()
}
$link = button(url('/user-shifts'), icon('chevron-left'), 'btn-sm', '', __('general.back'));
$reset = '';
if ($session->has('admin_shifts_previous')) {
$reset = form_submit(
'back',
icon('arrow-counterclockwise'),
'',
false,
'link',
__('Reset to previous state')
);
foreach ($session->get('admin_shifts_previous', []) as $name => $value) {
$reset .= form_hidden($name, $value);
}
}
return page_with_title(
$link . ' ' . admin_shifts_title() . ' ' . sprintf(
'<a href="%s">%s</a>',
url('/admin/shifts/history'),
icon('clock-history')
),
) . form([$reset], '', 'display:inline'),
[
msg(),
form([

View File

@ -285,14 +285,14 @@ function form_element($label, $input, $for = '', $class = '')
*
* @param string[] $elements
* @param string $action
* @param bool $inline
* @param string $style
* @return string
*/
function form($elements, $action = '', $inline = false, $btnGroup = false)
function form($elements, $action = '', $style = '', $btnGroup = false)
{
return '<form action="' . $action . '" enctype="multipart/form-data" method="post"'
. ($btnGroup ? ' class="btn-group"' : '')
. ($inline ? ' style="float:left"' : '') . '>'
. ($style ? ' style="' . $style . '"' : '') . '>'
. join($elements)
. form_csrf()
. '</form>';

View File

@ -615,7 +615,7 @@ function User_view(
form_hidden('action', 'arrived'),
form_hidden('user', $user_source->id),
form_submit('submit', icon('house') . __('user.arrive'), '', false),
], url('/admin-arrive'), true) : '',
], url('/admin-arrive'), 'float:left') : '',
($admin_user_privilege || $auth->can('voucher.edit')) && config('enable_voucher') ?
button(
url(

View File

@ -614,6 +614,9 @@ msgstr "Gruppe bearbeiten"
msgid "Please select a shift type."
msgstr "Bitte einen Schichttyp wählen."
msgid "Reset to previous state"
msgstr "Auf vorherigen Stand zurücksetzen"
msgid "Location"
msgstr "Ort"