update
This commit is contained in:
593
AzA march 2026/intern_portal/static/css/style.css
Normal file
593
AzA march 2026/intern_portal/static/css/style.css
Normal file
@@ -0,0 +1,593 @@
|
||||
:root {
|
||||
--aza-blue: #1a5f8a;
|
||||
--aza-blue-dark: #134a6b;
|
||||
--aza-blue-light: #e8f2f8;
|
||||
--aza-accent: #2d8bc9;
|
||||
--text: #1e293b;
|
||||
--text-muted: #64748b;
|
||||
--border: #cbd5e1;
|
||||
--bg: #f4f7fa;
|
||||
--white: #ffffff;
|
||||
--success: #059669;
|
||||
--warning: #d97706;
|
||||
--danger: #dc2626;
|
||||
--radius: 8px;
|
||||
--shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--aza-accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 240px;
|
||||
background: var(--aza-blue-dark);
|
||||
color: var(--white);
|
||||
padding: 1.5rem 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sidebar-brand {
|
||||
padding: 0 1.25rem 1.5rem;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.sidebar-brand h1 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sidebar-brand small {
|
||||
opacity: 0.75;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.sidebar nav a {
|
||||
display: block;
|
||||
padding: 0.65rem 1.25rem;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
text-decoration: none;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.sidebar nav a:hover,
|
||||
.sidebar nav a.active {
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sidebar-user {
|
||||
padding: 1rem 1.25rem;
|
||||
margin-top: auto;
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.85;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
padding: 1.5rem 2rem;
|
||||
max-width: 1200px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.page-header h2 {
|
||||
font-size: 1.5rem;
|
||||
color: var(--aza-blue-dark);
|
||||
}
|
||||
|
||||
.hint-banner {
|
||||
background: var(--aza-blue-light);
|
||||
border-left: 4px solid var(--aza-blue);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--white);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--aza-blue);
|
||||
}
|
||||
|
||||
.grid-2 {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.grid-3 {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
text-decoration: none;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--aza-blue);
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--aza-blue-dark);
|
||||
text-decoration: none;
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--white);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: var(--danger);
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 0.3rem 0.65rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
text-align: left;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
th {
|
||||
background: var(--aza-blue-light);
|
||||
color: var(--aza-blue-dark);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 0.35rem;
|
||||
font-weight: 500;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
min-height: 100px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 0.15rem 0.5rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.badge-neu { background: #dbeafe; color: #1e40af; }
|
||||
.badge-arbeit { background: #fef3c7; color: #92400e; }
|
||||
.badge-warten { background: #fce7f3; color: #9d174d; }
|
||||
.badge-erledigt { background: #d1fae5; color: #065f46; }
|
||||
.badge-archiv { background: #e2e8f0; color: #475569; }
|
||||
|
||||
.badge-niedrig { background: #e2e8f0; color: #475569; }
|
||||
.badge-normal { background: #dbeafe; color: #1e40af; }
|
||||
.badge-hoch { background: #fee2e2; color: #991b1b; }
|
||||
|
||||
.alert {
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #fee2e2;
|
||||
color: #991b1b;
|
||||
border: 1px solid #fecaca;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
border: 1px solid #a7f3d0;
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background: var(--aza-blue-light);
|
||||
color: var(--aza-blue-dark);
|
||||
border: 1px solid #bfdbfe;
|
||||
}
|
||||
|
||||
.login-page {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, var(--aza-blue-dark) 0%, var(--aza-blue) 100%);
|
||||
}
|
||||
|
||||
.login-box {
|
||||
background: var(--white);
|
||||
padding: 2rem;
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.login-box h1 {
|
||||
text-align: center;
|
||||
color: var(--aza-blue-dark);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.login-box .subtitle {
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.search-bar input {
|
||||
flex: 1;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.comment-list {
|
||||
list-style: none;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.comment-list li {
|
||||
padding: 0.75rem;
|
||||
background: var(--bg);
|
||||
border-radius: var(--radius);
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.comment-meta {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
background: var(--aza-blue-light);
|
||||
color: var(--aza-blue);
|
||||
padding: 0.1rem 0.45rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.75rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--aza-blue-light);
|
||||
border-radius: var(--radius);
|
||||
border-left: 3px solid var(--aza-blue);
|
||||
}
|
||||
|
||||
.drop-zone {
|
||||
border: 2px dashed var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 2rem 1.5rem;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background: var(--white);
|
||||
transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
|
||||
min-height: 160px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.drop-zone:hover,
|
||||
.drop-zone:focus {
|
||||
outline: none;
|
||||
border-color: var(--aza-accent);
|
||||
background: var(--aza-blue-light);
|
||||
}
|
||||
|
||||
.drop-zone-active {
|
||||
border-color: var(--aza-blue);
|
||||
background: var(--aza-blue-light);
|
||||
box-shadow: 0 0 0 3px rgba(26, 95, 138, 0.15);
|
||||
}
|
||||
|
||||
.drop-zone-icon {
|
||||
font-size: 2rem;
|
||||
color: var(--aza-blue);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.drop-zone-title {
|
||||
font-weight: 600;
|
||||
color: var(--aza-blue-dark);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.drop-zone-sub,
|
||||
.drop-zone-types {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.drop-zone-types {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.upload-meta {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.upload-status {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.file-actions {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.file-actions .btn {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.odt-edit-placeholder h3 {
|
||||
color: var(--aza-blue-dark);
|
||||
}
|
||||
|
||||
.doc-editor-header {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.doc-editor-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.save-status {
|
||||
font-size: 0.85rem;
|
||||
padding: 0.35rem 0.65rem;
|
||||
border-radius: var(--radius);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.save-status-saved {
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
}
|
||||
|
||||
.save-status-saving {
|
||||
background: #fef3c7;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.save-status-unsaved {
|
||||
background: #dbeafe;
|
||||
color: #1e40af;
|
||||
}
|
||||
|
||||
.save-status-error {
|
||||
background: #fee2e2;
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.doc-meta-card {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.doc-editor-card {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.doc-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
padding: 0.65rem 0.75rem;
|
||||
background: var(--aza-blue-light);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.doc-tb-btn {
|
||||
background: var(--white);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 0.35rem 0.55rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.doc-tb-btn:hover {
|
||||
background: var(--bg);
|
||||
border-color: var(--aza-accent);
|
||||
}
|
||||
|
||||
.doc-tb-sep {
|
||||
width: 1px;
|
||||
background: var(--border);
|
||||
margin: 0 0.25rem;
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
.doc-editor-body {
|
||||
min-height: 420px;
|
||||
padding: 1.25rem 1.5rem;
|
||||
outline: none;
|
||||
line-height: 1.6;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.doc-editor-body:focus {
|
||||
background: #fcfeff;
|
||||
}
|
||||
|
||||
.doc-editor-body h1,
|
||||
.doc-editor-body h2,
|
||||
.doc-editor-body h3 {
|
||||
color: var(--aza-blue-dark);
|
||||
margin: 0.75rem 0 0.5rem;
|
||||
}
|
||||
|
||||
.doc-editor-body ul,
|
||||
.doc-editor-body ol {
|
||||
margin: 0.5rem 0 0.5rem 1.5rem;
|
||||
padding-left: 1.25rem;
|
||||
}
|
||||
|
||||
.doc-editor-body li {
|
||||
margin: 0.2rem 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.doc-editor-body ul ul,
|
||||
.doc-editor-body ul ol,
|
||||
.doc-editor-body ol ul,
|
||||
.doc-editor-body ol ol {
|
||||
margin-top: 0.15rem;
|
||||
margin-bottom: 0.15rem;
|
||||
}
|
||||
|
||||
.doc-toolbar .doc-tb-btn {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.user-edit-details {
|
||||
display: inline-block;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.user-edit-details summary {
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.user-inline-form {
|
||||
margin-top: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
background: var(--bg);
|
||||
border-radius: var(--radius);
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 100%;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.sidebar nav {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.sidebar nav a {
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
155
AzA march 2026/intern_portal/static/js/documents.js
Normal file
155
AzA march 2026/intern_portal/static/js/documents.js
Normal file
@@ -0,0 +1,155 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var cfg = window.AZA_DOC;
|
||||
if (!cfg) return;
|
||||
|
||||
var editor = document.getElementById("doc-editor");
|
||||
var titleEl = document.getElementById("doc-title");
|
||||
var categoryEl = document.getElementById("doc-category");
|
||||
var taskEl = document.getElementById("doc-task");
|
||||
var statusEl = document.getElementById("save-status");
|
||||
var saveBtn = document.getElementById("btn-save");
|
||||
var saving = false;
|
||||
var autoTimer = null;
|
||||
var lastSaved = "";
|
||||
|
||||
function setStatus(state, text) {
|
||||
statusEl.className = "save-status save-status-" + state;
|
||||
statusEl.textContent = text;
|
||||
}
|
||||
|
||||
function payloadSnapshot() {
|
||||
return JSON.stringify({
|
||||
title: titleEl.value,
|
||||
category: categoryEl.value,
|
||||
task: taskEl.value,
|
||||
html: editor.innerHTML,
|
||||
});
|
||||
}
|
||||
|
||||
function markDirty() {
|
||||
if (!saving) {
|
||||
setStatus("unsaved", "Nicht gespeicherte Änderungen");
|
||||
}
|
||||
clearTimeout(autoTimer);
|
||||
autoTimer = setTimeout(function () {
|
||||
saveDocument(false);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function saveDocument(manual) {
|
||||
if (saving) return;
|
||||
var snap = payloadSnapshot();
|
||||
if (!manual && snap === lastSaved) {
|
||||
setStatus("saved", "Gespeichert");
|
||||
return;
|
||||
}
|
||||
saving = true;
|
||||
setStatus("saving", "Speichert...");
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append("csrf_token", cfg.csrf);
|
||||
fd.append("title", titleEl.value.trim() || "Unbenanntes Dokument");
|
||||
fd.append("content_html", editor.innerHTML);
|
||||
fd.append("category", categoryEl.value);
|
||||
fd.append("task_id", taskEl.value);
|
||||
|
||||
fetch("/api/documents/" + cfg.id + "/save", {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
credentials: "same-origin",
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
saving = false;
|
||||
if (data.ok) {
|
||||
lastSaved = snap;
|
||||
setStatus("saved", "Gespeichert");
|
||||
} else {
|
||||
setStatus("error", "Fehler beim Speichern");
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
saving = false;
|
||||
setStatus("error", "Fehler beim Speichern");
|
||||
});
|
||||
}
|
||||
|
||||
function findListItem(node) {
|
||||
var el = node && node.nodeType === 3 ? node.parentElement : node;
|
||||
while (el && el !== editor) {
|
||||
if (el.tagName === "LI") return el;
|
||||
el = el.parentElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isEmptyListItem(li) {
|
||||
if (!li) return false;
|
||||
var text = (li.textContent || "").replace(/\u00a0/g, " ").replace(/\u200B/g, "").trim();
|
||||
return text === "";
|
||||
}
|
||||
|
||||
editor.addEventListener("keydown", function (e) {
|
||||
if (e.key !== "Enter" || e.shiftKey) return;
|
||||
var li = findListItem(window.getSelection().anchorNode);
|
||||
if (!li) return;
|
||||
if (isEmptyListItem(li)) {
|
||||
e.preventDefault();
|
||||
document.execCommand("outdent");
|
||||
if (findListItem(window.getSelection().anchorNode) && isEmptyListItem(findListItem(window.getSelection().anchorNode))) {
|
||||
document.execCommand("outdent");
|
||||
}
|
||||
var p = document.createElement("p");
|
||||
p.appendChild(document.createElement("br"));
|
||||
var parent = li.parentElement;
|
||||
if (parent && (parent.tagName === "UL" || parent.tagName === "OL") && parent.children.length === 1) {
|
||||
parent.replaceWith(p);
|
||||
} else {
|
||||
li.replaceWith(p);
|
||||
}
|
||||
var sel = window.getSelection();
|
||||
var range = document.createRange();
|
||||
range.selectNodeContents(p);
|
||||
range.collapse(true);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
markDirty();
|
||||
}
|
||||
});
|
||||
|
||||
[titleEl, categoryEl, taskEl].forEach(function (el) {
|
||||
el.addEventListener("input", markDirty);
|
||||
el.addEventListener("change", markDirty);
|
||||
});
|
||||
|
||||
editor.addEventListener("input", markDirty);
|
||||
|
||||
saveBtn.addEventListener("click", function () {
|
||||
clearTimeout(autoTimer);
|
||||
saveDocument(true);
|
||||
});
|
||||
|
||||
document.querySelectorAll(".doc-tb-btn").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
var cmd = btn.getAttribute("data-cmd");
|
||||
var val = btn.getAttribute("data-value");
|
||||
editor.focus();
|
||||
if (cmd === "link") {
|
||||
var url = window.prompt("Link-URL (https://...):", "https://");
|
||||
if (url && !url.toLowerCase().startsWith("javascript:")) {
|
||||
document.execCommand("createLink", false, url);
|
||||
}
|
||||
} else if (cmd === "formatBlock" && val) {
|
||||
document.execCommand(cmd, false, val);
|
||||
} else {
|
||||
document.execCommand(cmd, false, null);
|
||||
}
|
||||
markDirty();
|
||||
});
|
||||
});
|
||||
|
||||
lastSaved = payloadSnapshot();
|
||||
})();
|
||||
203
AzA march 2026/intern_portal/static/js/upload.js
Normal file
203
AzA march 2026/intern_portal/static/js/upload.js
Normal file
@@ -0,0 +1,203 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var DEFAULT_MAX = 200 * 1024 * 1024;
|
||||
var BLOCKED_MSG = "Dieser Dateityp ist aus Sicherheitsgründen nicht erlaubt.";
|
||||
|
||||
function ext(name) {
|
||||
var i = name.lastIndexOf(".");
|
||||
return i >= 0 ? name.slice(i).toLowerCase() : "";
|
||||
}
|
||||
|
||||
function formatSize(bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
|
||||
return (bytes / (1024 * 1024)).toFixed(1) + " MB";
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
var d = document.createElement("div");
|
||||
d.textContent = s;
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function showStatus(el, type, message) {
|
||||
el.hidden = false;
|
||||
el.className = "upload-status alert alert-" + type;
|
||||
el.textContent = message;
|
||||
}
|
||||
|
||||
function isOdt(name) {
|
||||
return name && name.toLowerCase().slice(-4) === ".odt";
|
||||
}
|
||||
|
||||
function editBtn(file) {
|
||||
if (!isOdt(file.original_filename)) return "";
|
||||
return ' <a href="/files/' + file.id + '/edit" class="btn btn-sm btn-secondary">Im Browser bearbeiten</a>';
|
||||
}
|
||||
|
||||
function buildFileRow(file, mode) {
|
||||
var tr = document.createElement("tr");
|
||||
tr.dataset.fileId = String(file.id);
|
||||
if (mode === "task") {
|
||||
tr.innerHTML =
|
||||
"<td>" + escapeHtml(file.original_filename) + "</td>" +
|
||||
"<td>" + formatSize(file.size_bytes) + "</td>" +
|
||||
"<td>" + escapeHtml(file.created_at) + " (" + escapeHtml(file.uploader || "") + ")</td>" +
|
||||
'<td class="file-actions"><a href="/files/' + file.id + '/download" class="btn btn-sm btn-primary">Download</a>' +
|
||||
editBtn(file) + "</td>";
|
||||
return tr;
|
||||
}
|
||||
var tags = (file.tags || []).map(function (t) {
|
||||
return '<span class="tag">' + escapeHtml(t) + "</span>";
|
||||
}).join("");
|
||||
tr.innerHTML =
|
||||
"<td>" + escapeHtml(file.original_filename) + "</td>" +
|
||||
"<td>" + escapeHtml(file.category || "–") + "</td>" +
|
||||
"<td>" + escapeHtml(file.description || "–") + "</td>" +
|
||||
"<td>" + formatSize(file.size_bytes) + "</td>" +
|
||||
"<td>" + escapeHtml(file.created_at) + " (" + escapeHtml(file.uploader || "") + ")</td>" +
|
||||
"<td>" + tags + "</td>" +
|
||||
'<td class="file-actions"><a href="/files/' + file.id + '/download" class="btn btn-sm btn-primary">Download</a>' +
|
||||
editBtn(file) + "</td>";
|
||||
return tr;
|
||||
}
|
||||
|
||||
function parseList(raw) {
|
||||
if (!raw) return [];
|
||||
return raw.split(",").map(function (s) { return s.trim(); }).filter(Boolean);
|
||||
}
|
||||
|
||||
function initWidget(widget) {
|
||||
var dropZone = widget.querySelector("[data-drop-zone]");
|
||||
var fileInput = widget.querySelector("[data-file-input]");
|
||||
var statusEl = widget.querySelector("[data-upload-status]");
|
||||
var csrf = widget.dataset.csrf;
|
||||
var taskId = widget.dataset.taskId || "";
|
||||
var categoryEl = widget.querySelector("[data-upload-category]");
|
||||
var descriptionEl = widget.querySelector("[data-upload-description]");
|
||||
var tagsEl = widget.querySelector("[data-upload-tags]");
|
||||
var listTargetId = widget.dataset.listTarget;
|
||||
var listTarget = listTargetId ? document.getElementById(listTargetId) : null;
|
||||
var rowMode = widget.dataset.rowMode || "full";
|
||||
var emptyState = widget.dataset.emptyState
|
||||
? document.getElementById(widget.dataset.emptyState)
|
||||
: null;
|
||||
var maxBytes = parseInt(widget.dataset.maxBytes, 10) || DEFAULT_MAX;
|
||||
var maxMb = parseInt(widget.dataset.maxMb, 10) || 200;
|
||||
var allowed = parseList(widget.dataset.allowed);
|
||||
var blocked = parseList(widget.dataset.blocked);
|
||||
var uploading = false;
|
||||
var queue = [];
|
||||
|
||||
if (!dropZone || !fileInput || !csrf) return;
|
||||
|
||||
if (allowed.length && fileInput) {
|
||||
fileInput.setAttribute("accept", allowed.join(","));
|
||||
}
|
||||
|
||||
dropZone.addEventListener("click", function (e) {
|
||||
if (e.target === fileInput) return;
|
||||
fileInput.click();
|
||||
});
|
||||
|
||||
dropZone.addEventListener("keydown", function (e) {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
fileInput.click();
|
||||
}
|
||||
});
|
||||
|
||||
["dragenter", "dragover"].forEach(function (ev) {
|
||||
dropZone.addEventListener(ev, function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dropZone.classList.add("drop-zone-active");
|
||||
});
|
||||
});
|
||||
|
||||
["dragleave", "drop"].forEach(function (ev) {
|
||||
dropZone.addEventListener(ev, function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dropZone.classList.remove("drop-zone-active");
|
||||
});
|
||||
});
|
||||
|
||||
dropZone.addEventListener("drop", function (e) {
|
||||
var files = e.dataTransfer && e.dataTransfer.files;
|
||||
if (files && files.length) enqueue(Array.prototype.slice.call(files));
|
||||
});
|
||||
|
||||
fileInput.addEventListener("change", function () {
|
||||
if (fileInput.files && fileInput.files.length) {
|
||||
enqueue(Array.prototype.slice.call(fileInput.files));
|
||||
fileInput.value = "";
|
||||
}
|
||||
});
|
||||
|
||||
function enqueue(files) {
|
||||
files.forEach(function (f) { queue.push(f); });
|
||||
processQueue();
|
||||
}
|
||||
|
||||
function processQueue() {
|
||||
if (uploading || !queue.length) return;
|
||||
uploading = true;
|
||||
uploadOne(queue.shift()).finally(function () {
|
||||
uploading = false;
|
||||
processQueue();
|
||||
});
|
||||
}
|
||||
|
||||
function uploadOne(file) {
|
||||
var e = ext(file.name);
|
||||
if (blocked.indexOf(e) !== -1) {
|
||||
showStatus(statusEl, "error", file.name + ": " + BLOCKED_MSG);
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (allowed.length && allowed.indexOf(e) === -1) {
|
||||
showStatus(statusEl, "error", file.name + ": Dateityp nicht erlaubt.");
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (file.size > maxBytes) {
|
||||
showStatus(statusEl, "error", file.name + ": zu gross (max. " + maxMb + " MB).");
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
showStatus(statusEl, "info", "Lade hoch: " + file.name + " …");
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append("csrf_token", csrf);
|
||||
fd.append("upload", file);
|
||||
if (categoryEl) fd.append("category", categoryEl.value);
|
||||
if (descriptionEl) fd.append("description", descriptionEl.value);
|
||||
if (tagsEl) fd.append("tags", tagsEl.value);
|
||||
if (taskId) fd.append("task_id", taskId);
|
||||
|
||||
return fetch("/api/files/upload", { method: "POST", body: fd, credentials: "same-origin" })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
if (data.ok && data.file) {
|
||||
showStatus(statusEl, "success", file.name + " erfolgreich hochgeladen.");
|
||||
if (listTarget) {
|
||||
if (emptyState) emptyState.hidden = true;
|
||||
var tbody = listTarget.tagName === "TBODY" ? listTarget : listTarget.querySelector("tbody");
|
||||
if (tbody) {
|
||||
tbody.insertBefore(buildFileRow(data.file, rowMode), tbody.firstChild);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showStatus(statusEl, "error", (data.message || "Upload fehlgeschlagen.") + " (" + file.name + ")");
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
showStatus(statusEl, "error", "Netzwerkfehler beim Upload von " + file.name + ".");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.querySelectorAll("[data-upload-widget]").forEach(initWidget);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user