diff --git a/admin/adminAjaxOperations.php b/admin/adminAjaxOperations.php
index 8de9e58..a33d6a7 100644
--- a/admin/adminAjaxOperations.php
+++ b/admin/adminAjaxOperations.php
@@ -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;
?>
\ No newline at end of file
diff --git a/admin/panels/uploader/admin.uploader.tpl b/admin/panels/uploader/admin.uploader.tpl
index 7336dce..7419c7f 100755
--- a/admin/panels/uploader/admin.uploader.tpl
+++ b/admin/panels/uploader/admin.uploader.tpl
@@ -25,40 +25,40 @@
@@ -109,3 +109,10 @@
{/html_form}
+
+{literal}
+
+{/literal}
\ No newline at end of file
diff --git a/admin/res/admin.js b/admin/res/admin.js
index 575d6c2..8705875 100644
--- a/admin/res/admin.js
+++ b/admin/res/admin.js
@@ -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('
No file preview
');
+ changeMediaPreviewContent('
No file preview
');
});
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]')
}
}
}
\ No newline at end of file
diff --git a/admin/res/sceditor/plugins/flatPressFileManager.js b/admin/res/sceditor/plugins/flatPressFileManager.js
index d50ee0c..926269c 100644
--- a/admin/res/sceditor/plugins/flatPressFileManager.js
+++ b/admin/res/sceditor/plugins/flatPressFileManager.js
@@ -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',
});