Apply the filetype filter to accept attribute of file input.

This way only files are shown which match the current attachment type and the user knows directly which file types are allowed or not.
This commit is contained in:
Jan Böhmer 2019-11-01 22:04:30 +01:00
parent 7a9c528d6d
commit 767ee59fb8
3 changed files with 23 additions and 0 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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;
}