Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## next feature release
* Add file type check to form type `file` (key: `allowedFileTypes`) ([PR#147](https://github.com/mapbender/mapbender-digitizer/pull/147))

## 2.0.6
* Show error message when a YAML syntax error occurs in manager ([PR#145](https://github.com/mapbender/mapbender-digitizer/pull/145))
* Fix popup width & height was ignored ([PR#146](https://github.com/mapbender/mapbender-digitizer/pull/146))
Expand Down
29 changes: 23 additions & 6 deletions src/Mapbender/DataManagerBundle/Resources/public/FormRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,17 @@
}
var self = this;
$('input[type="file"][data-upload-url][data-name]', scope).each(function() {
var $input = $(this);
var name = $input.attr('data-name');
var $group = $input.closest('.mb-3');
var $realInput = $('input[name="' + name + '"]', $group);
var url = $input.attr('data-upload-url');
var $loadingIcon = $('.-js-loading-indicator', $group);
const $input = $(this);
const name = $input.attr('data-name');
const $group = $input.closest('.mb-3');
const $realInput = $('input[name="' + name + '"]', $group);
const url = $input.attr('data-upload-url');
const allowedExtensions = $input.attr('data-allowed-types');
const $loadingIcon = $('.-js-loading-indicator', $group);
$input.fileupload({
dataType: 'json',
url: url,
submit: (e, data) => self.checkFileExtension(data.files, allowedExtensions),
success: function(response) {
var values = {};
values[name] = response.filename;
Expand All @@ -273,6 +275,20 @@
return false;
});
},
checkFileExtension: function (files, allowedExtensionsCsv) {
// no value means no restriction
if (!allowedExtensionsCsv) return true;
const allowedExtensions = allowedExtensionsCsv.split(',').map(s => s.trim().toLowerCase());
for (let i = 0; i < files.length; ++i) {
const file = files[i];
const fileExt = (file.name.split('.').pop() || '').toLowerCase();
if (!allowedExtensions.includes(fileExt)) {
Mapbender.info(Mapbender.trans('mb.data-manager.error.invalid_file_extension') + ' ' + allowedExtensions.join(', '));
return false;
}
}
return true;
},
getAttachmentUrl_: function(baseUrl, fieldName, inputValue) {
if (inputValue && !/^(http[s]?)?:?\/\//.test(inputValue)) {
var baseName = inputValue.replace(/^.*?\/([^/]*)$/, '$1');
Expand Down Expand Up @@ -374,6 +390,7 @@
.attr(settings.attr || {})
.attr('accept', (settings.attr || settings).accept || null)
.attr('data-upload-url', settings.__uploadUrl__)
.attr('data-allowed-types', settings.allowedFileTypes)
.attr('data-name', settings.name)
;
var $btnText = $('<span class="upload-button-text">')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Objektdetails
attachment:
open: Anhang öffnen
error:
invalid_file_extension: 'Ungültiger Dateityp. Erlaubte Dateitypen:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Detail data
attachment:
open: Open attachment
error:
invalid_file_extension: 'Invalid file type. Allowed file types:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Detalles del objeto
attachment:
open: Abrir archivo adjunto
error:
invalid_file_extension: 'Tipo de archivo no válido. Tipos de archivo permitidos:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Données détaillées
attachment:
open: Ouvrir la pièce jointe
error:
invalid_file_extension: 'Type de fichier non valide. Types de fichiers autorisés:'
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ mb:
details_title: Dettagli oggetto
attachment:
open: Apri allegato
error:
invalid_file_extension: 'Tipo di file non valido. Tipi di file consentiti:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Detailgegevens
attachment:
open: Bijlage openen
error:
invalid_file_extension: 'Ongeldig bestandstype. Toegestane bestandstypen:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Dane szczegółowe
attachment:
open: Otwórz załącznik
error:
invalid_file_extension: 'Nieprawidłowy typ pliku. Dozwolone typy plików:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Detalhes do objeto
attachment:
open: Abrir anexo
error:
invalid_file_extension: 'Tipo de arquivo inválido. Tipos de arquivo permitidos:'
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ mb:
details_title: Детали объекта
attachment:
open: Открыть вложение
error:
invalid_file_extension: 'Недопустимый тип файла. Разрешённые типы файлов:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Ayrıntılı veriler
attachment:
open: Eki aç
error:
invalid_file_extension: 'Geçersiz dosya türü. İzin verilen dosya türleri:'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mb:
details_title: Детальні дані
attachment:
open: Відкрити вкладення
error:
invalid_file_extension: 'Недійсний тип файлу. Дозволені типи файлів:'