File Manager only show images and attachs. FileUpload namefile fixed.
This commit is contained in:
parent
1398ca35ac
commit
6259440e34
@ -3,13 +3,22 @@
|
||||
|
||||
$AjaxFunctionMap = [];
|
||||
|
||||
$AjaxFunctionListMediaDirectory = function($route) { /* Just for testing */
|
||||
define('ROOT_CONTENT', [
|
||||
['attachs', true],
|
||||
['images', true]
|
||||
]);
|
||||
|
||||
$AjaxFunctionListMediaDirectory = function($route) {
|
||||
$newRoute = FP_CONTENT . $route;
|
||||
$dirContent = scandir($newRoute);
|
||||
if(!$dirContent) {
|
||||
throw new Exception('Error when trying to access the folder'.$newRoute);
|
||||
}
|
||||
$result = [];
|
||||
if(!strlen($route)) { // Root. We show only images and attachs dir
|
||||
checkIfDirAndAttachsDirExists();
|
||||
return ROOT_CONTENT;
|
||||
}
|
||||
for($i = 2; $i < sizeof($dirContent); ++$i) { // Result = [[dir1, true], [file1, false], [file2, false]] ...
|
||||
array_push($result, []);
|
||||
array_push($result[$i - 2], $dirContent[$i]);
|
||||
@ -18,6 +27,15 @@ $AjaxFunctionListMediaDirectory = function($route) { /* Just for testing */
|
||||
return $result;
|
||||
};
|
||||
|
||||
function checkIfDirAndAttachsDirExists() {
|
||||
if (!file_exists(IMAGES_DIR)) {
|
||||
fs_mkdir(IMAGES_DIR);
|
||||
}
|
||||
if (!file_exists(ATTACHS_DIR)) {
|
||||
fs_mkdir(ATTACHS_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
$AjaxFunctionMap['ListMediaDirectory'] = $AjaxFunctionListMediaDirectory;
|
||||
|
||||
?>
|
@ -25,40 +25,40 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-6 mb-4">
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" name="upload[]" />
|
||||
<label class="custom-file-label" for="inputGroupFile01">{$panelstrings.choose_file}</label>
|
||||
</div>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder" id="inputGroupFileAddon01"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
|
||||
<label class="custom-file-label" for="inputGroupFile01" id="inputGroupFile01Label">Choose file</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" name="upload[]" />
|
||||
<label class="custom-file-label" for="inputGroupFile01">{$panelstrings.choose_file}</label>
|
||||
</div>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder" id="inputGroupFileAddon02"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="inputGroupFile02" aria-describedby="inputGroupFileAddon02">
|
||||
<label class="custom-file-label" for="inputGroupFile02">Choose file</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" name="upload[]" />
|
||||
<label class="custom-file-label" for="inputGroupFile01">{$panelstrings.choose_file}</label>
|
||||
</div>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder" id="inputGroupFileAddon03"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="inputGroupFile03" aria-describedby="inputGroupFileAddon03">
|
||||
<label class="custom-file-label" for="inputGroupFile03">Choose file</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" name="upload[]" />
|
||||
<label class="custom-file-label" for="inputGroupFile01">{$panelstrings.choose_file}</label>
|
||||
</div>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text ti-folder" id="inputGroupFileAddon04"></span>
|
||||
</div>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04">
|
||||
<label class="custom-file-label" for="inputGroupFile04">Choose file</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 mb-4">
|
||||
@ -109,3 +109,10 @@
|
||||
</div>
|
||||
|
||||
{/html_form}
|
||||
|
||||
{literal}
|
||||
<script>
|
||||
/* This event to change name to namesfiles */
|
||||
startUploadEvent();
|
||||
</script>
|
||||
{/literal}
|
@ -31,22 +31,47 @@ function mobile_open_button() {
|
||||
}
|
||||
// End Responsive functions
|
||||
|
||||
/* Functions of uploaderFiles */
|
||||
/* This function is called in the admin.uploader.tpl */
|
||||
function startUploadEvent() {
|
||||
document.querySelector('.custom-file-input').addEventListener('change', function(e){ /* Change namefile when user select it */
|
||||
const currentInputFileID = e.srcElement.id;
|
||||
const fileName = document.getElementById(currentInputFileID).files[0].name;
|
||||
const nextSibling = e.target.nextElementSibling
|
||||
nextSibling.innerText = fileName
|
||||
});
|
||||
}
|
||||
/* Functions of FileManager */
|
||||
|
||||
let mediaManagerRoute = '';
|
||||
|
||||
let insertSCEditorFunction;
|
||||
let currentPromiseResolve;
|
||||
let currentPromiseReject; // Called in Ajax errors
|
||||
|
||||
function openMediaManagerAndGetMediaUrl(callback) {
|
||||
return new Promise(function(resolvePromise, rejectPromise) {
|
||||
currentPromiseResolve = resolvePromise;
|
||||
currentPromiseReject = rejectPromise;
|
||||
open_media_manager();
|
||||
}).then(function(value) {
|
||||
$('#flatpress-files-modal').modal('hide');
|
||||
callback(value);
|
||||
}).catch(function(err) {
|
||||
$('#flatpress-files-modal').modal('hide');
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
/* Functions of FileManager */
|
||||
// Open the botton
|
||||
function open_media_manager(insertSCEditor) {
|
||||
insertSCEditorFunction = insertSCEditor;
|
||||
function open_media_manager() {
|
||||
mediaManagerRoute = '';
|
||||
$('#flatpress-files-modal').modal('show');
|
||||
$.post('ajax.php', {Operation : 'ListMediaDirectory', Arguments : mediaManagerRoute}, function(data) {
|
||||
data = JSON.parse(data);
|
||||
if(data.result) {
|
||||
showDirectory(data.content);
|
||||
showDirectory(data.content); // data.content = Array of pairs: dirname + isdirectory
|
||||
} else {
|
||||
//throw new Error(data.content);
|
||||
currentPromiseReject(data.content);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -58,6 +83,7 @@ function showDirectory(DirectoryList) {
|
||||
let currentMediaDirectoryLI = document.createElement('li');
|
||||
currentMediaDirectoryLI.innerHTML = "..";
|
||||
currentMediaDirectoryLI.onclick = () => openNewDirectory('..');
|
||||
writeLiContent(currentMediaDirectoryLI, '..', true);
|
||||
mediaDirectoryULDOM.appendChild(currentMediaDirectoryLI);
|
||||
}
|
||||
for(let i = 0; i < DirectoryList.length; ++i) {
|
||||
@ -68,7 +94,7 @@ function showDirectory(DirectoryList) {
|
||||
} else { // It is a file
|
||||
currentMediaDirectoryLI.onclick = () => openNewFile(DirectoryList[i][0]); // File name
|
||||
}
|
||||
writeLiContent(currentMediaDirectoryLI,DirectoryList[i][0], DirectoryList[i][1]); // Content = Icon + fileName
|
||||
writeLiContent(currentMediaDirectoryLI, DirectoryList[i][0], DirectoryList[i][1]); // Content = Icon + fileName
|
||||
mediaDirectoryULDOM.appendChild(currentMediaDirectoryLI);
|
||||
}
|
||||
mediaDirectoryModal.innerHTML = '';
|
||||
@ -110,6 +136,7 @@ function openNewDirectory(DirectoryName) {
|
||||
if(data.result) {
|
||||
showDirectory(data.content);
|
||||
} else {
|
||||
currentPromiseReject(data.content);
|
||||
//throw new Error(data.content);
|
||||
}
|
||||
});
|
||||
@ -164,7 +191,7 @@ FUNCTION_BY_FILE_FORMAT.set(IMAGE, function(imageURL) {
|
||||
});
|
||||
|
||||
FUNCTION_BY_FILE_FORMAT.set(FILE, function(fileURL) {
|
||||
changeMediaPreviewContent('<p>No file preview</p>');
|
||||
changeMediaPreviewContent('<p class="text-center">No file preview</p>');
|
||||
});
|
||||
|
||||
function changeMediaPreviewContent(content) {
|
||||
@ -182,11 +209,13 @@ function insertMediaInSceditor() {
|
||||
const fileType = detectTypeFile(selectedFile);
|
||||
switch(fileType) {
|
||||
case IMAGE: {
|
||||
insertSCEditorFunction('[img]' + selectedURL + selectedFile + '[/img]')
|
||||
//insertSCEditorFunction('[img]' + selectedURL + selectedFile + '[/img]')
|
||||
currentPromiseResolve('[img]' + selectedURL + selectedFile + '[/img]');
|
||||
break;
|
||||
}
|
||||
default: { /* Other files = url link */
|
||||
insertSCEditorFunction('[url=' + selectedURL + selectedFile + ']' + selectedFile +'[/url]')
|
||||
currentPromiseResolve('[url=' + selectedURL + selectedFile + ']' + selectedFile +'[/url]');
|
||||
//insertSCEditorFunction('[url=' + selectedURL + selectedFile + ']' + selectedFile +'[/url]')
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,10 @@ sceditor.command.set('flatPressFileManager', {
|
||||
An a open bootstrap modal function
|
||||
The modal html is in the .tpl file, where sceditor is included
|
||||
*/
|
||||
open_media_manager(this.insert);
|
||||
const insertIntoSceditor = this.insert;
|
||||
openMediaManagerAndGetMediaUrl(function(value) {
|
||||
insertIntoSceditor(value);
|
||||
});
|
||||
},
|
||||
tooltip: 'Open FlatPress File Manager',
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user