Ordner-Zuweisung als klickbare Tabelle statt Checkboxen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kroonk
2026-04-16 22:06:43 +02:00
parent 2dcd559501
commit 2c040b651d
3 changed files with 66 additions and 36 deletions

View File

@@ -122,50 +122,70 @@ $(document).ready(function() {
// ==================== ORDNER-ZUWEISUNG ====================
var allFolders = [];
var assignedFolders = [];
function loadFolders() {
$.get('/api/admin/folders').done(function(folders) {
$('#folder-checkboxes').empty();
if (folders.length === 0) {
$('#folder-checkboxes').html('<p>Keine Unterordner in Websitebilder gefunden. Erstelle Ordner in Nextcloud.</p>');
return;
}
folders.forEach(function(f) {
$('#folder-checkboxes').append(
'<div class="folder-check"><label>' +
'<input type="checkbox" value="' + f + '" class="folder-cb"/> ' +
'<i class="fa fa-folder"></i> ' + f +
'</label></div>'
);
});
allFolders = folders;
});
}
// Bei User-Auswahl: zugewiesene Ordner laden
function renderFolderTable() {
var $tbody = $('#folder-tbody');
$tbody.empty();
if (allFolders.length === 0) {
$tbody.html('<tr><td colspan="2" style="text-align:center;">Keine Unterordner gefunden. Erstelle Ordner in Nextcloud.</td></tr>');
return;
}
allFolders.forEach(function(f) {
var isAssigned = assignedFolders.indexOf(f) !== -1;
var cls = isAssigned ? 'folder-row assigned' : 'folder-row';
var statusCls = isAssigned ? 'folder-status yes' : 'folder-status no';
var statusText = isAssigned ? 'Zugewiesen' : '—';
$tbody.append(
'<tr class="' + cls + '" data-folder="' + f + '">' +
'<td><i class="fa fa-folder"></i> ' + f + '</td>' +
'<td style="text-align:center;"><span class="' + statusCls + '">' + statusText + '</span></td>' +
'</tr>'
);
});
}
// Bei User-Auswahl: zugewiesene Ordner laden und Tabelle anzeigen
$('#user-select').change(function() {
var uid = $(this).val();
$('.folder-cb').prop('checked', false);
if (!uid) return;
$.get('/api/admin/assign?user_id=' + uid).done(function(assignedFolders) {
assignedFolders.forEach(function(f) {
$('.folder-cb[value="' + f + '"]').prop('checked', true);
});
if (!uid) {
$('#folder-table-wrap').hide();
assignedFolders = [];
return;
}
$.get('/api/admin/assign?user_id=' + uid).done(function(folders) {
assignedFolders = folders || [];
renderFolderTable();
$('#folder-table-wrap').show();
});
});
// Zuweisung speichern
$('#save-assignments').click(function() {
// Klick auf Ordner-Zeile: Toggle + sofort speichern
$(document).on('click', '.folder-row', function() {
var uid = $('#user-select').val();
if (!uid) return alert('Bitte Nutzer waehlen');
var selected = [];
$('.folder-cb:checked').each(function() { selected.push($(this).val()); });
if (!uid) return;
var folder = $(this).data('folder');
var idx = assignedFolders.indexOf(folder);
if (idx !== -1) {
assignedFolders.splice(idx, 1);
} else {
assignedFolders.push(folder);
}
renderFolderTable();
$.ajax({
url: '/api/admin/assign',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ user_id: uid, folders: selected })
data: JSON.stringify({ user_id: uid, folders: assignedFolders })
}).done(function() {
$('#assign-status').text('Gespeichert!').fadeIn().delay(2000).fadeOut();
$('#assign-status').text('Gespeichert!').show().delay(1500).fadeOut();
}).fail(function() {
alert('Fehler beim Speichern');
});