WebFM/src/core/static/js/post-ajax.js

74 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-02-06 04:52:46 +00:00
const postAjaxController = (data, action) => {
if (data.message) {
type = data.message.type
message = data.message.text
if (action === "reset-path") {
reloadDirectory();
return ;
}
if (action === "delete-file") {
reloadDirectory();
displayMessage(message, type);
return ;
}
if (action === "upload-text" || action === "upload-file") {
let field = null;
if (action === "upload-text") field = "settings-alert-zone-text";
if (action === "upload-file") field = "settings-alert-zone-files";
displayMessage(message, type, 3, field);
reloadDirectory();
return ;
}
if (action === "create-item") {
displayMessage(message, type, 3, "settings-alert-zone-new-items");
reloadDirectory();
return ;
}
displayMessage(message, type);
2021-02-08 02:07:13 +00:00
return ;
}
if (data.hasOwnProperty('path_head'))
2021-02-08 05:31:20 +00:00
updateHTMLDirList(data);
2021-02-08 02:07:13 +00:00
if (data.hasOwnProperty('faves_list'))
renderFavesList(data);
2021-02-08 02:07:13 +00:00
if (data.hasOwnProperty("refresh")) {
if (data.refresh == "true") {
reloadDirectory();
}
}
}
const updateHTMLDirList = async (data) => {
2021-02-08 06:30:44 +00:00
let images = data.list.images[0];
let isInFaves = data.in_fave;
2021-02-08 05:31:20 +00:00
let background_image = (images[0]) ? images[0][0] : "";
2021-02-08 06:30:44 +00:00
document.getElementById("path").innerText = data.path_head;
2021-02-08 02:07:13 +00:00
// Setup background if there is a 000.* in selection
if (background_image.match(/000\.(jpg|png|gif)\b/) != null) {
// Due to same hash for 000 we add date to make link unique for each run to bypass cache issues...
2021-02-08 05:31:20 +00:00
background_image = "api/file-manager-action/files/" + images[0][1] + '?d=' + Date.now();
2021-02-08 02:07:13 +00:00
updateBackground(background_image, false);
} else {
2021-02-08 05:31:20 +00:00
background_image = "static/imgs/backgrounds/particles.mp4";
2021-02-08 02:07:13 +00:00
updateBackground(background_image);
}
2021-02-06 04:52:46 +00:00
2021-02-10 04:47:51 +00:00
// Set faves state
2021-02-08 06:30:44 +00:00
let tggl_faves_btn = document.getElementById("tggl-faves-btn");
2021-02-08 02:07:13 +00:00
if (isInFaves == "true")
2021-02-08 06:30:44 +00:00
tggl_faves_btn.classList.add("btn-info");
2021-02-08 02:07:13 +00:00
else
2021-02-08 06:30:44 +00:00
tggl_faves_btn.classList.remove("btn-info");
2021-02-08 02:07:13 +00:00
2021-02-08 05:31:20 +00:00
renderFilesList(data.list);
2021-02-08 02:07:13 +00:00
}