Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file prevalidation notification #19

Merged
merged 1 commit into from
Jul 8, 2018
Merged
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 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 @@ -69,6 +74,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 @@ -82,6 +96,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