Update configuration and enhance newsletter generation features
- Change WIKI_API_URL in .env.example and config to point to the new API endpoint. - Set COOKIE_SECURE to false for local development in .env.example and config. - Improve the newsletter generation logic to handle new and edited articles separately. - Add display options for showing date, user, and category in the newsletter output. - Enhance error handling for Wiki API requests and update templates for better user feedback. - Update CSS for new UI elements and improve overall layout in dashboard and login pages.
This commit is contained in:
83
app/static/js/newsletter.js
Normal file
83
app/static/js/newsletter.js
Normal file
@@ -0,0 +1,83 @@
|
||||
function setCopyStatus(message, isError) {
|
||||
const status = document.getElementById("copy-status");
|
||||
if (!status) return;
|
||||
status.textContent = message;
|
||||
status.className = isError ? "copy-status error" : "copy-status success";
|
||||
}
|
||||
|
||||
async function copyForOutlook() {
|
||||
const htmlSource = document.getElementById("newsletter-html-source");
|
||||
const plainSource = document.getElementById("newsletter-plain-source");
|
||||
if (!htmlSource || !htmlSource.value.trim()) {
|
||||
setCopyStatus("Bitte zuerst einen Newsletter generieren.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
const html = htmlSource.value;
|
||||
const plain = plainSource ? plainSource.value : "";
|
||||
|
||||
try {
|
||||
if (navigator.clipboard && window.ClipboardItem) {
|
||||
await navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
"text/html": new Blob([html], { type: "text/html" }),
|
||||
"text/plain": new Blob([plain], { type: "text/plain" }),
|
||||
}),
|
||||
]);
|
||||
setCopyStatus("Newsletter mit Hyperlinks kopiert. In Outlook mit Strg+V einfügen.");
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Clipboard API failed, using fallback.", err);
|
||||
}
|
||||
|
||||
const container = document.createElement("div");
|
||||
container.innerHTML = html;
|
||||
container.style.position = "fixed";
|
||||
container.style.left = "-9999px";
|
||||
document.body.appendChild(container);
|
||||
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(container);
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
|
||||
let ok = false;
|
||||
try {
|
||||
ok = document.execCommand("copy");
|
||||
} finally {
|
||||
selection.removeAllRanges();
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
|
||||
setCopyStatus(
|
||||
ok ? "Newsletter mit Hyperlinks kopiert. In Outlook mit Strg+V einfügen." : "Kopieren fehlgeschlagen.",
|
||||
!ok
|
||||
);
|
||||
}
|
||||
|
||||
async function copyHtmlSource() {
|
||||
const htmlSource = document.getElementById("newsletter-html-source");
|
||||
if (!htmlSource || !htmlSource.value.trim()) {
|
||||
setCopyStatus("Bitte zuerst einen Newsletter generieren.", true);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(htmlSource.value);
|
||||
setCopyStatus("HTML-Quelltext kopiert.");
|
||||
} catch (err) {
|
||||
setCopyStatus("Kopieren fehlgeschlagen.", true);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const htmlSource = document.getElementById("newsletter-html-source");
|
||||
const frame = document.getElementById("newsletter-preview-frame");
|
||||
if (htmlSource && frame && htmlSource.value.trim()) {
|
||||
frame.srcdoc = htmlSource.value;
|
||||
}
|
||||
|
||||
document.getElementById("copy-outlook-btn")?.addEventListener("click", copyForOutlook);
|
||||
document.getElementById("copy-html-source-btn")?.addEventListener("click", copyHtmlSource);
|
||||
});
|
||||
Reference in New Issue
Block a user