diff --git a/assets/ts_src/event_listeners.ts b/assets/ts_src/event_listeners.ts index 2f19be50..3672011f 100644 --- a/assets/ts_src/event_listeners.ts +++ b/assets/ts_src/event_listeners.ts @@ -411,6 +411,22 @@ $(document).on("ajaxUI:start", function () { $(document).on("ajaxUI:reload", parseMarkdown); }); +$(document).on("ajaxUI:start ajaxUI:reload attachment:create", function() { + let updater = function() { + //@ts-ignore + let selected_option = $(this)[0].selectedOptions[0]; + let filter_string = $(selected_option).data('filetype_filter'); + //Find associated file input + + let $row = $(this).parents('tr'); + //Set accept filter + $('input[type="file"]', $row).prop('accept', filter_string); + }; + + //Register a change handler on all change listeners, and update it when the events are triggered + $('select.attachment_type_selector').change(updater).each(updater); +}); + //Need for proper body padding, with every navbar height $(window).resize(function () { let height : number = $('#navbar').height() + 10; diff --git a/src/Form/AttachmentFormType.php b/src/Form/AttachmentFormType.php index 4662d074..870b48b7 100644 --- a/src/Form/AttachmentFormType.php +++ b/src/Form/AttachmentFormType.php @@ -70,6 +70,7 @@ class AttachmentFormType extends AbstractType 'label' => $this->trans->trans('attachment.edit.attachment_type'), 'class' => AttachmentType::class, 'disable_not_selectable' => true, + 'attr' => ['class' => 'attachment_type_selector'] ]); $builder->add('showInTable', CheckboxType::class, ['required' => false, diff --git a/src/Form/Type/StructuralEntityType.php b/src/Form/Type/StructuralEntityType.php index d43f42ee..c0111486 100644 --- a/src/Form/Type/StructuralEntityType.php +++ b/src/Form/Type/StructuralEntityType.php @@ -23,6 +23,7 @@ namespace App\Form\Type; +use App\Entity\Attachments\AttachmentType; use App\Entity\Base\StructuralDBElement; use App\Entity\Parts\Storelocation; use App\Repository\StructuralDBElementRepository; @@ -114,6 +115,11 @@ class StructuralEntityType extends AbstractType if ($this->options['disable_not_selectable'] && $choice->isNotSelectable()) { $tmp += ['disabled' => 'disabled']; } + + if ($choice instanceof AttachmentType) { + $tmp += ['data-filetype_filter' => $choice->getFiletypeFilter()]; + } + return $tmp; }