diff --git a/templates/index.html b/templates/index.html
index 09f8a02..6fcec2b 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -304,16 +304,7 @@
console.error("Error loading folders:", textStatus, error);
});
},
- 'check_callback': true,
- 'sort': function (a, b) {
- // Сортировка по имени при загрузке
- const nodeA = this.get_node(a);
- const nodeB = this.get_node(b);
- if (nodeA.parent === nodeB.parent && nodeA.parent === '#') {
- return nodeA.text.localeCompare(nodeB.text);
- }
- return 0;
- }
+ 'check_callback': true
},
'plugins': ['dnd', 'html_data'],
'dnd': {
@@ -432,7 +423,7 @@
function sortInstalls(field, filteredInstalls = null) {
let installs = filteredInstalls || (selectedFolderId
- ? allInstalls.filter(i => i.folder_id == selectedFolderId && i.folder_id !== null)
+ ? allInstalls.filter(i => i.folder_id == folderId && i.folder_id !== null)
: allInstalls);
if (field) {
@@ -760,19 +751,46 @@
}
function sortFolders() {
+ // Получаем все папки из allFolders
+ const rootFolders = allFolders.filter(folder => !folder.parent_id || folder.parent_id === "root");
+
+ // Сортируем по имени
+ rootFolders.sort((a, b) => a.name.localeCompare(b.name));
+
+ // Обновляем порядок папок в allFolders
+ const sortedFolders = [];
+ const nonRootFolders = allFolders.filter(folder => folder.parent_id && folder.parent_id !== "root");
+ rootFolders.forEach(folder => sortedFolders.push(folder));
+ nonRootFolders.forEach(folder => sortedFolders.push(folder));
+ allFolders = sortedFolders;
+
+ // Перестраиваем дерево
const instance = $('#folder-tree').jstree(true);
- instance.sort(instance.get_container().children('ul').find('li'), function (a, b) {
- return instance.get_text(a).localeCompare(instance.get_text(b));
- });
+ instance.settings.core.data = [
+ { id: "root", text: "Корень", parent: "#" }
+ ].concat(allFolders.map(folder => ({
+ id: folder.id,
+ text: `${folder.name} ` +
+ `` +
+ ``,
+ parent: folder.parent_id ? folder.parent_id : "root"
+ })));
instance.refresh();
}
function saveFolderPosition(folderId, newParentId) {
+ // Найдём имя папки, чтобы включить его в запрос
+ const folder = allFolders.find(f => f.id == folderId);
+ if (!folder) {
+ console.error(`Folder with id ${folderId} not found`);
+ return;
+ }
+
$.ajax({
url: `${API_URL}/folders/${folderId}`,
type: 'PUT',
contentType: 'application/json',
- data: JSON.stringify({ parent_id: newParentId }),
+ data: JSON.stringify({ name: folder.name, parent_id: newParentId }),
success: function () {
console.log(`Folder ${folderId} moved to parent ${newParentId}`);
loadFolders();
@@ -780,8 +798,9 @@
},
error: function (xhr, status, error) {
console.error("Error saving folder position:", status, error);
+ console.error("Response:", xhr.responseText);
alert("Не удалось сохранить новое положение папки. Проверьте консоль.");
- $('#folder-tree').jstree(true).refresh(); // Восстанавливаем предыдущее состояние
+ $('#folder-tree').jstree(true).refresh();
}
});
}