Improve create and start permission handling (#613)

This commit is contained in:
Kevin Papst
2019-03-06 10:24:27 +01:00
committed by GitHub
parent bce85b04d6
commit e260dd84ad
31 changed files with 258 additions and 86 deletions

View File

@@ -117,7 +117,38 @@ class TimesheetEditForm extends AbstractType
if ($options['duration_only']) {
$builder->add('duration', DurationType::class, [
'required' => false,
'docu_chapter' => 'timesheet.html#duration-format',
'attr' => [
'placeholder' => '00:00',
]
]);
$builder->addEventListener(
FormEvents::POST_SET_DATA,
function (FormEvent $event) {
/** @var Timesheet $data */
$data = $event->getData();
if (null === $data->getEnd()) {
$event->getForm()->get('duration')->setData(null);
}
}
);
// make sure that duration is mapped back to end field
$builder->addEventListener(
FormEvents::SUBMIT,
function (FormEvent $event) {
/** @var Timesheet $data */
$data = $event->getData();
$duration = $data->getDuration();
$end = null;
if (null !== $duration) {
$end = clone $data->getBegin();
$end->modify('+ ' . $duration . 'seconds');
}
$data->setEnd($end);
}
);
} else {
$builder->add('end', DateTimePickerType::class, [
'label' => 'label.end',
@@ -270,7 +301,7 @@ class TimesheetEditForm extends AbstractType
'include_user' => false,
'include_exported' => false,
'include_rate' => true,
'docu_chapter' => 'timesheet',
'docu_chapter' => 'timesheet.html',
'method' => 'POST',
]);
}

View File

@@ -73,12 +73,18 @@ class DurationType extends AbstractType
}
},
function ($formatToInt) use ($formatter, $pattern) {
if (null === $formatToInt) {
return null;
}
if (empty($formatToInt)) {
return 0;
}
if (!preg_match($pattern, $formatToInt)) {
throw new TransformationFailedException('Invalid duration format given');
}
try {
return $formatter->parseDurationString($formatToInt);
} catch (\Exception $e) {

View File

@@ -55,7 +55,7 @@ class InvoiceRendererType extends AbstractType
return $choiceValue;
},
'translation_domain' => 'invoice-renderer',
'docu_chapter' => 'invoices',
'docu_chapter' => 'invoices.html',
]);
}