Media manager improves, alert when the file type is not supported and maximum load file

This commit is contained in:
Diego Najar 2019-02-02 16:11:36 +01:00
parent 7335196208
commit 088179f1fb
3 changed files with 22 additions and 3 deletions

View File

@ -37,6 +37,8 @@ $numberOfPages = count($listOfFilesByPage);
--> -->
<h3 class="mt-2 mb-3"><?php $L->p('Upload'); ?></h3> <h3 class="mt-2 mb-3"><?php $L->p('Upload'); ?></h3>
<div id="jsalertMedia" class="alert alert-warning d-none" role="alert"></div>
<!-- Form and Input file --> <!-- Form and Input file -->
<form name="bluditFormUpload" id="jsbluditFormUpload" enctype="multipart/form-data"> <form name="bluditFormUpload" id="jsbluditFormUpload" enctype="multipart/form-data">
<div class="custom-file"> <div class="custom-file">
@ -97,6 +99,14 @@ function cleanTable() {
$('#jsbluditMediaTable').empty(); $('#jsbluditMediaTable').empty();
} }
function showMediaAlert(message) {
$("#jsalertMedia").html(message).removeClass('d-none');
}
function hideMediaAlert() {
$("#jsalertMedia").addClass('d-none');
}
// Show the files in the table // Show the files in the table
function displayFiles(files) { function displayFiles(files) {
if (!Array.isArray(files)) { if (!Array.isArray(files)) {
@ -143,6 +153,8 @@ function getFiles(pageNumber) {
function(data) { // success function function(data) { // success function
if (data.status==0) { if (data.status==0) {
displayFiles(data.files); displayFiles(data.files);
} else {
console.log(data.message);
} }
} }
); );
@ -158,6 +170,8 @@ function deleteMedia(filename) {
function(data) { // success function function(data) { // success function
if (data.status==0) { if (data.status==0) {
getFiles(1); getFiles(1);
} else {
console.log(data.message);
} }
} }
); );
@ -211,6 +225,9 @@ $(document).ready(function() {
$("#jsbluditProgressBar").width("0"); $("#jsbluditProgressBar").width("0");
// Get the files for the first page, this include the files uploaded // Get the files for the first page, this include the files uploaded
getFiles(1); getFiles(1);
} else {
$("#jsbluditProgressBar").width("0");
showMediaAlert(data.message);
} }
}); });
}); });

View File

@ -34,7 +34,7 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
// Check for errors // Check for errors
if ($_FILES['bluditInputFiles']['error'][$key] != 0) { if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
$message = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize'); $message = $L->g('Maximum load file size allowed:').' '.ini_get('upload_max_filesize');
Log::set($message, LOG_TYPE_ERROR); Log::set($message, LOG_TYPE_ERROR);
ajaxResponse(1, $message); ajaxResponse(1, $message);
} }
@ -46,7 +46,7 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION); $fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
$fileExtension = Text::lowercase($fileExtension); $fileExtension = Text::lowercase($fileExtension);
if (!in_array($fileExtension, $allowedExtensions) ) { if (!in_array($fileExtension, $allowedExtensions) ) {
$message = 'Extension file not supported.'; $message = $L->g('File type is not supported. Allowed types:').' '.implode(', ',$allowedExtensions);
Log::set($message, LOG_TYPE_ERROR); Log::set($message, LOG_TYPE_ERROR);
ajaxResponse(1, $message); ajaxResponse(1, $message);
} }

View File

@ -376,5 +376,7 @@
"thumbnail": "Thumbnail", "thumbnail": "Thumbnail",
"thumbnail-width-in-pixels": "Thumbnail width in pixels (px).", "thumbnail-width-in-pixels": "Thumbnail width in pixels (px).",
"thumbnail-height-in-pixels": "Thumbnail height in pixels (px).", "thumbnail-height-in-pixels": "Thumbnail height in pixels (px).",
"thumbnail-quality-in-percentage": "Thumbnail quality in percentage (%)." "thumbnail-quality-in-percentage": "Thumbnail quality in percentage (%).",
"maximum-load-file-size-allowed:": "Maximum load file size allowed:",
"file-type-is-not-supported": "File type is not supported. Allowed types:"
} }