Dieser Ordner ist leer.
');
+ if (count && empty) empty.remove();
+ if (!f) return;
+ f.querySelector('small').textContent = count + ' Element(e)';
+ var icon = f.querySelector('.netbox-explorer-icon');
+ icon.classList.toggle('mdi-folder', count > 0);
+ icon.classList.toggle('mdi-folder-outline', count === 0);
+ }
+
+ var dragged = null, lastHighlight = null;
+ function clearHighlight() {
+ if (lastHighlight) lastHighlight.classList.remove('netbox-explorer-drop', 'netbox-explorer-nodrop');
+ lastHighlight = null;
+ }
+
+ function moveDocument(doc, folderId) {
+ var source = doc.closest('.netbox-explorer-pane[data-folder]').dataset.folder;
+ if (source === folderId) return;
+ var conflict = tenantConflict(doc, folderId);
+ if (conflict) { toast(conflict, false); return; }
+ var body = new FormData();
+ body.append('category', folderId === 'root' ? '' : folderId);
+ body.append('csrfmiddlewaretoken', document.querySelector('#doc-explorer-export [name=csrfmiddlewaretoken]').value);
+ fetch(doc.dataset.move, { method: 'POST', body: body, credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
+ .then(function (r) { return r.json().catch(function () { return { error: 'Unerwartete Antwort vom Server (' + r.status + ').' }; }); })
+ .then(function (data) {
+ if (data.error) { toast(data.error, false); return; }
+ pane(folderId).appendChild(doc);
+ refreshFolderTile(source);
+ refreshFolderTile(folderId);
+ treeStale = true;
+ toast('„' + doc.title + '“ verschoben nach „' + pane(folderId).dataset.title + '“.', true);
+ applySearch();
+ })
+ .catch(function () { toast('Verschieben fehlgeschlagen – keine Verbindung zum Server.', false); });
+ }
+
+ if (explorer) {
+ explorer.addEventListener('dragstart', function (e) {
+ var tile = e.target.closest && e.target.closest('.netbox-explorer-tile[data-move]');
+ if (!tile) return;
+ dragged = originalTile(tile.dataset.pk);
+ closeMenu();
+ tile.classList.add('dragging');
+ e.dataTransfer.effectAllowed = 'move';
+ e.dataTransfer.setData('text/plain', tile.title);
+ });
+ explorer.addEventListener('dragend', function (e) {
+ if (e.target.classList) e.target.classList.remove('dragging');
+ dragged = null;
+ clearHighlight();
+ });
+ explorer.addEventListener('dragover', function (e) {
+ if (!dragged) return;
+ var folderId = dropFolder(e.target);
+ var el = folderId && dropHighlight(e.target);
+ if (el !== lastHighlight) clearHighlight();
+ if (!folderId) return;
+ var ok = !tenantConflict(dragged, folderId);
+ e.preventDefault();
+ e.dataTransfer.dropEffect = ok ? 'move' : 'none';
+ lastHighlight = el;
+ el.classList.add(ok ? 'netbox-explorer-drop' : 'netbox-explorer-nodrop');
+ });
+ explorer.addEventListener('drop', function (e) {
+ if (!dragged) return;
+ e.preventDefault();
+ var folderId = dropFolder(e.target);
+ clearHighlight();
+ if (folderId) moveDocument(dragged, folderId);
+ });
+ }
+
// --- View switcher ---
+ var treeStale = false;
function setView(v) {
+ if (v === 'tree' && treeStale) {
+ try { localStorage.setItem(VIEW_KEY, v); } catch (e) {}
+ window.location.reload();
+ return;
+ }
view = explorer ? v : 'tree';
if (explorer) explorer.hidden = view !== 'explorer';
treeView.hidden = view === 'explorer';
diff --git a/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html b/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html
index b456f47..e0f4266 100644
--- a/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html
+++ b/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html
@@ -1,6 +1,7 @@
{{ document.title }}
diff --git a/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html b/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html
index 623723a..2146bf8 100644
--- a/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html
+++ b/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html
@@ -1,5 +1,6 @@
diff --git a/netbox_documentation/urls.py b/netbox_documentation/urls.py
index 9866955..24ca257 100644
--- a/netbox_documentation/urls.py
+++ b/netbox_documentation/urls.py
@@ -16,6 +16,7 @@ urlpatterns = (
path("documents//print/", views.DocumentPrintView.as_view(), name="document_print"),
path("documents//edit/", views.DocumentEditView.as_view(), name="document_edit"),
path("documents//media-upload/", views.DocumentMediaUploadView.as_view(), name="document_media_upload"),
+ path("documents//move/", views.DocumentMoveView.as_view(), name="document_move"),
path("documents//delete/", views.DocumentDeleteView.as_view(), name="document_delete"),
path("documents//changelog/", ObjectChangeLogView.as_view(), name="document_changelog", kwargs={"model": models.Document}),
path("assignments/", views.AssignmentListView.as_view(), name="documentassignment_list"),
diff --git a/netbox_documentation/views.py b/netbox_documentation/views.py
index 24ef372..b5ff1db 100644
--- a/netbox_documentation/views.py
+++ b/netbox_documentation/views.py
@@ -6,7 +6,7 @@ import tinymce
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
-from django.core.exceptions import PermissionDenied
+from django.core.exceptions import PermissionDenied, ValidationError
from django.db import transaction
from django.db.models import Count, Q
from django.http import FileResponse, Http404, JsonResponse
@@ -126,6 +126,35 @@ class DocumentEditView(generic.ObjectEditView):
template_name = "netbox_documentation/document_edit.html"
+class DocumentMoveView(PermissionRequiredMixin, View):
+ """Move a document into another folder (drag & drop in the Explorer). The tenant never changes."""
+
+ permission_required = "netbox_documentation.change_document"
+
+ def post(self, request, pk):
+ document = get_object_or_404(Document.objects.restrict(request.user, "change"), pk=pk)
+ category_id = request.POST.get("category") or None
+ category = None
+ if category_id is not None:
+ category = DocumentCategory.objects.restrict(request.user, "view").filter(pk=category_id).first()
+ if category is None:
+ return JsonResponse({"error": "Der Zielordner existiert nicht."}, status=404)
+ if category.tenant_id and category.tenant_id != document.tenant_id:
+ return JsonResponse({
+ "error": f"Der Ordner „{category.name}“ gehört zum Mandanten „{category.tenant}“. "
+ f"Das Dokument muss im selben Mandanten bleiben.",
+ }, status=400)
+ if document.category_id != (category.pk if category else None):
+ document.snapshot()
+ document.category = category
+ try:
+ document.full_clean()
+ except ValidationError as error:
+ return JsonResponse({"error": " ".join(error.messages)}, status=400)
+ document.save()
+ return JsonResponse({"ok": True, "category": category.pk if category else None})
+
+
class DocumentDeleteView(generic.ObjectDeleteView):
queryset = Document.objects.all()