This commit is contained in:
2025-03-04 17:56:37 +03:00
parent 9c3b36cb6f
commit 64931747cf
2 changed files with 30 additions and 27 deletions
+15 -21
View File
@@ -14,7 +14,6 @@
.form-container { margin-bottom: 20px; }
.jstree-node { position: relative; }
.folder-actions { display: inline; margin-left: 10px; }
#root-btn { margin-top: 10px; }
</style>
</head>
<body>
@@ -22,7 +21,6 @@
<h2>Папки</h2>
<div id="folder-tree"></div>
<button onclick="addFolder()">Добавить папку</button>
<button id="root-btn" onclick="showRoot()">Показать все записи</button>
</div>
<div id="installs-container">
<h1>Органайзер RustDesk</h1>
@@ -46,13 +44,19 @@
'core': {
'data': function (node, cb) {
$.getJSON(`${API_URL}/folders`, function (data) {
const treeData = data.map(folder => ({
const treeData = [
{
id: "root",
text: "Корень",
parent: "#"
}
].concat(data.map(folder => ({
id: folder.id,
text: `${folder.name} <span class="folder-actions">` +
`<button onclick="editFolder(${folder.id}, '${folder.name}')">✏️</button>` +
`<button onclick="deleteFolder(${folder.id})">🗑️</button></span>`,
parent: folder.parent_id ? folder.parent_id : '#'
}));
parent: folder.parent_id ? folder.parent_id : "root"
})));
cb(treeData);
});
},
@@ -60,7 +64,7 @@
},
'plugins': ['dnd', 'html_data']
}).on('select_node.jstree', function (e, data) {
selectedFolderId = data.node.id;
selectedFolderId = data.node.id === "root" ? null : data.node.id;
loadInstalls(selectedFolderId);
});
@@ -74,14 +78,16 @@
}).on('drop', function (e) {
e.preventDefault();
const installId = e.originalEvent.dataTransfer.getData('text');
const targetFolderId = $(e.target).closest('.jstree-node').attr('id');
if (installId && targetFolderId && targetFolderId !== 'undefined') {
let targetFolderId = $(e.target).closest('.jstree-node').attr('id');
if (installId && targetFolderId) {
targetFolderId = targetFolderId === "root" ? null : targetFolderId;
moveInstallToFolder(installId, targetFolderId);
}
});
// Загрузка всех записей при старте
loadInstalls(null);
$('#folder-tree').jstree('select_node', 'root'); // Выбираем корень по умолчанию
});
function loadInstalls(folderId) {
@@ -135,7 +141,6 @@
url: `${API_URL}/folders/${folderId}`,
type: 'DELETE',
success: function () {
// Перемещаем записи в корень
$.getJSON(`${API_URL}/installs`, function (data) {
const folderInstalls = data.filter(i => i.folder_id == folderId);
folderInstalls.forEach(item => {
@@ -200,12 +205,7 @@
contentType: 'application/json',
data: JSON.stringify({ folder_id: folderId }),
success: function () {
// Если текущая папка выбрана, обновляем её, иначе показываем целевую
if (selectedFolderId === folderId) {
loadInstalls(selectedFolderId);
} else {
loadInstalls(selectedFolderId); // Остаемся в текущей папке
}
loadInstalls(selectedFolderId); // Обновляем текущую папку
},
error: function (xhr, status, error) {
console.error("Ошибка переноса:", status, error);
@@ -218,12 +218,6 @@
window.location.href = `rustdesk://${rustId}`;
}
}
function showRoot() {
selectedFolderId = null;
loadInstalls(null);
$('#folder-tree').jstree('deselect_all'); // Снимаем выделение с папок
}
</script>
</body>
</html>