Improves in Media manager and Ajax responses

This commit is contained in:
Diego Najar 2019-01-30 23:15:36 +01:00
parent eb31e298da
commit 8f7ee3fec1
5 changed files with 36 additions and 40 deletions

View File

@ -99,6 +99,10 @@ function cleanTable() {
// Show the files in the table
function displayFiles(files) {
if (!Array.isArray(files)) {
return false;
}
// Clean table
cleanTable();
@ -134,10 +138,12 @@ function getFiles(pageNumber) {
{ tokenCSRF: tokenCSRF,
pageNumber: pageNumber,
uuid: "<?php echo $uuid; ?>",
path: "thumbnails" // the paths are defined in the list-images.php
path: "thumbnails" // the paths are defined in ajax/list-images
},
function(data) {
displayFiles(data.files);
function(data) { // success function
if (data.status==0) {
displayFiles(data.files);
}
}
);
}
@ -149,8 +155,10 @@ function deleteMedia(filename) {
filename: filename,
uuid: "<?php echo $uuid; ?>"
},
function(data) {
getFiles(1);
function(data) { // success function
if (data.status==0) {
getFiles(1);
}
}
);
}
@ -171,7 +179,7 @@ $(document).ready(function() {
// Check file size ?
// Check file type/extension ?
$("#jsbluditProgressBar").width("1%");
$("#jsbluditProgressBar").width("0");
// Data to send via AJAX
var uuid = $("#jsuuid").val();
@ -198,9 +206,12 @@ $(document).ready(function() {
}
return xhr;
}
}).done(function() {
// Get the files of the first page, this include the files uploaded
getFiles(1);
}).done(function(data) {
if (data.status==0) {
$("#jsbluditProgressBar").width("0");
// Get the files for the first page, this include the files uploaded
getFiles(1);
}
});
});
});

View File

@ -11,10 +11,7 @@ $uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
// ----------------------------------------------------------------------------
if ($filename==false) {
exit (json_encode(array(
'status'=>1,
'message'=>'The filename is empty.'
)));
ajaxResponse(1, 'The filename is empty.');
}
if ($uuid && IMAGE_RESTRICT) {
@ -35,9 +32,6 @@ if (Sanitize::pathFile($thumbnailPath.$filename)) {
Filesystem::rmfile($thumbnailPath.$filename);
}
exit (json_encode(array(
'status'=>0,
'message'=>'Image deleted.'
)));
ajaxResponse(0, 'Image deleted.');
?>

View File

@ -22,10 +22,7 @@ if ($path=='thumbnails') {
$path = PATH_UPLOADS_THUMBNAILS;
}
} else {
exit (json_encode(array(
'status'=>1,
'files'=>'Invalid path.'
)));
ajaxResponse(1, 'Invalid path.');
}
// Get all files from the directory $path, also split the array by numberOfItems
@ -44,16 +41,12 @@ if (isset($listOfFilesByPage[$pageNumber])) {
// Returns the number of chunks for the paginator
// Returns the files inside the chunk
exit (json_encode(array(
'status'=>0,
ajaxResponse(0, 'List of files and number of chunks.', array(
'numberOfPages'=>count($listOfFilesByPage),
'files'=>$files
)));
));
}
exit (json_encode(array(
'status'=>1,
'files'=>'Out of index.'
)));
ajaxResponse(1, 'Chunks out of index');
?>

View File

@ -36,10 +36,7 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
$message = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize');
Log::set($message, LOG_TYPE_ERROR);
exit (json_encode(array(
'status'=>1,
'message'=>$message
)));
ajaxResponse(1, $message);
}
// Convert URL characters such as spaces or quotes to characters
@ -51,10 +48,7 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
if (!in_array($fileExtension, $allowedExtensions) ) {
$message = 'Extension file not supported.';
Log::set($message, LOG_TYPE_ERROR);
exit (json_encode(array(
'status'=>1,
'message'=>$message
)));
ajaxResponse(1, $message);
}
// Generate the next filename to not overwrite the original file
@ -75,10 +69,8 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
}
}
exit (json_encode(array(
'status'=>0,
'message'=>'Image uploaded success.',
ajaxResponse(0, 'List of files and number of chunks.', array(
'filename'=>$nextFilename
)));
));
?>

View File

@ -794,3 +794,9 @@ function activateTheme($themeDirectory) {
}
return false;
}
function ajaxResponse($status=0, $message="", $data=array()) {
$default = array('status'=>$status, 'message'=>$message);
$output = array_merge($default, $data);
exit (json_encode($output));
}