Improves in Media manager and Ajax responses
This commit is contained in:
parent
eb31e298da
commit
8f7ee3fec1
|
@ -99,6 +99,10 @@ function cleanTable() {
|
||||||
|
|
||||||
// Show the files in the table
|
// Show the files in the table
|
||||||
function displayFiles(files) {
|
function displayFiles(files) {
|
||||||
|
if (!Array.isArray(files)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Clean table
|
// Clean table
|
||||||
cleanTable();
|
cleanTable();
|
||||||
|
|
||||||
|
@ -134,10 +138,12 @@ function getFiles(pageNumber) {
|
||||||
{ tokenCSRF: tokenCSRF,
|
{ tokenCSRF: tokenCSRF,
|
||||||
pageNumber: pageNumber,
|
pageNumber: pageNumber,
|
||||||
uuid: "<?php echo $uuid; ?>",
|
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) {
|
function(data) { // success function
|
||||||
displayFiles(data.files);
|
if (data.status==0) {
|
||||||
|
displayFiles(data.files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -149,8 +155,10 @@ function deleteMedia(filename) {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
uuid: "<?php echo $uuid; ?>"
|
uuid: "<?php echo $uuid; ?>"
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) { // success function
|
||||||
getFiles(1);
|
if (data.status==0) {
|
||||||
|
getFiles(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +179,7 @@ $(document).ready(function() {
|
||||||
// Check file size ?
|
// Check file size ?
|
||||||
// Check file type/extension ?
|
// Check file type/extension ?
|
||||||
|
|
||||||
$("#jsbluditProgressBar").width("1%");
|
$("#jsbluditProgressBar").width("0");
|
||||||
|
|
||||||
// Data to send via AJAX
|
// Data to send via AJAX
|
||||||
var uuid = $("#jsuuid").val();
|
var uuid = $("#jsuuid").val();
|
||||||
|
@ -198,9 +206,12 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
return xhr;
|
return xhr;
|
||||||
}
|
}
|
||||||
}).done(function() {
|
}).done(function(data) {
|
||||||
// Get the files of the first page, this include the files uploaded
|
if (data.status==0) {
|
||||||
getFiles(1);
|
$("#jsbluditProgressBar").width("0");
|
||||||
|
// Get the files for the first page, this include the files uploaded
|
||||||
|
getFiles(1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,10 +11,7 @@ $uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
if ($filename==false) {
|
if ($filename==false) {
|
||||||
exit (json_encode(array(
|
ajaxResponse(1, 'The filename is empty.');
|
||||||
'status'=>1,
|
|
||||||
'message'=>'The filename is empty.'
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($uuid && IMAGE_RESTRICT) {
|
if ($uuid && IMAGE_RESTRICT) {
|
||||||
|
@ -35,9 +32,6 @@ if (Sanitize::pathFile($thumbnailPath.$filename)) {
|
||||||
Filesystem::rmfile($thumbnailPath.$filename);
|
Filesystem::rmfile($thumbnailPath.$filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (json_encode(array(
|
ajaxResponse(0, 'Image deleted.');
|
||||||
'status'=>0,
|
|
||||||
'message'=>'Image deleted.'
|
|
||||||
)));
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -22,10 +22,7 @@ if ($path=='thumbnails') {
|
||||||
$path = PATH_UPLOADS_THUMBNAILS;
|
$path = PATH_UPLOADS_THUMBNAILS;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exit (json_encode(array(
|
ajaxResponse(1, 'Invalid path.');
|
||||||
'status'=>1,
|
|
||||||
'files'=>'Invalid path.'
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all files from the directory $path, also split the array by numberOfItems
|
// 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 number of chunks for the paginator
|
||||||
// Returns the files inside the chunk
|
// Returns the files inside the chunk
|
||||||
exit (json_encode(array(
|
ajaxResponse(0, 'List of files and number of chunks.', array(
|
||||||
'status'=>0,
|
|
||||||
'numberOfPages'=>count($listOfFilesByPage),
|
'numberOfPages'=>count($listOfFilesByPage),
|
||||||
'files'=>$files
|
'files'=>$files
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (json_encode(array(
|
ajaxResponse(1, 'Chunks out of index');
|
||||||
'status'=>1,
|
|
||||||
'files'=>'Out of index.'
|
|
||||||
)));
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -36,10 +36,7 @@ foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
|
||||||
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 = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize');
|
||||||
Log::set($message, LOG_TYPE_ERROR);
|
Log::set($message, LOG_TYPE_ERROR);
|
||||||
exit (json_encode(array(
|
ajaxResponse(1, $message);
|
||||||
'status'=>1,
|
|
||||||
'message'=>$message
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert URL characters such as spaces or quotes to characters
|
// 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) ) {
|
if (!in_array($fileExtension, $allowedExtensions) ) {
|
||||||
$message = 'Extension file not supported.';
|
$message = 'Extension file not supported.';
|
||||||
Log::set($message, LOG_TYPE_ERROR);
|
Log::set($message, LOG_TYPE_ERROR);
|
||||||
exit (json_encode(array(
|
ajaxResponse(1, $message);
|
||||||
'status'=>1,
|
|
||||||
'message'=>$message
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the next filename to not overwrite the original file
|
// 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(
|
ajaxResponse(0, 'List of files and number of chunks.', array(
|
||||||
'status'=>0,
|
|
||||||
'message'=>'Image uploaded success.',
|
|
||||||
'filename'=>$nextFilename
|
'filename'=>$nextFilename
|
||||||
)));
|
));
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -794,3 +794,9 @@ function activateTheme($themeDirectory) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ajaxResponse($status=0, $message="", $data=array()) {
|
||||||
|
$default = array('status'=>$status, 'message'=>$message);
|
||||||
|
$output = array_merge($default, $data);
|
||||||
|
exit (json_encode($output));
|
||||||
|
}
|
Loading…
Reference in New Issue