Skip to content

Commit

Permalink
Merge pull request #19 from silasjoisten/file-prevalidation
Browse files Browse the repository at this point in the history
file prevalidation notification
  • Loading branch information
Silas Joisten authored Jul 8, 2018
2 parents a748137 + 19396cc commit 9005734
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Resources/translations/SonataMultiUploadBundle.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ uploading: Hochladen
canceled: Abgebrochen
upload_complete: Abgeschlossen
drag_and_drop: Dateien hier ablegen
file_type_error: Dateityp wird nicht unterstützt
file_size_error: Datei ist zu groß
file_extension_error: Dateiending wird nicht unterstützt
3 changes: 3 additions & 0 deletions src/Resources/translations/SonataMultiUploadBundle.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ uploading: Uploading
canceled: Canceled
upload_complete: Upload complete
drag_and_drop: Drag & drop files here
file_type_error: Filetype is not correct
file_size_error: File is to large
file_extension_error: File extension is not supported
21 changes: 21 additions & 0 deletions src/Resources/views/multi_upload.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
{% block content %}
<div class="box box-solid">
<div class="box-body">
<div class="alert alert-dismissible hidden">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-warning"></i> Alert!</h4>
<div class="text"></div>
</div>
<div class="row">
<div class="col-md-6">
<div class="box box-solid">
Expand Down Expand Up @@ -75,6 +80,15 @@
setStatus(id, 'danger', message);
setProgress(id, 0, 'danger', false);
},
onFileTypeError: function (file) {
setNotification('danger', '<b>' + file.name + '</b> {{ 'file_type_error'|trans({}, 'SonataMultiUploadBundle') }}');
},
onFileSizeError: function (file) {
setNotification('danger', '<b>' + file.name + '</b> {{ 'file_size_error'|trans({}, 'SonataMultiUploadBundle') }}');
},
onFileExtError: function (file) {
setNotification('danger', '<b>' + file.name + '</b> {{ 'file_extension_error'|trans({}, 'SonataMultiUploadBundle') }}');
}
});
});
Expand All @@ -88,6 +102,13 @@
$('#files').prepend($template);
}
function setNotification(status, message) {
var $alert = $('div.alert')
$alert.addClass('alert-' + status);
$alert.find('.text').append('<p>' + message + '</p>');
$alert.removeClass('hidden').fadeIn();
}
function setStatus(id, status, message) {
$('#uploaderFile' + id).find('span').html(message).prop('class', 'status text-' + status);
}
Expand Down

0 comments on commit 9005734

Please sign in to comment.