Files
jobs/web/static/settings.js
zwitschi 2185a07ff0
Some checks failed
CI/CD Pipeline / test (push) Failing after 4m9s
feat: Implement email sending utilities and templates for job notifications
- Added email_service.py for sending emails with SMTP configuration.
- Introduced email_templates.py to render job alert email subjects and bodies.
- Enhanced scraper.py to extract contact information from job listings.
- Updated settings.js to handle negative keyword input validation.
- Created email.html and email_templates.html for managing email subscriptions and templates in the admin interface.
- Modified base.html to include links for email alerts and templates.
- Expanded user settings.html to allow management of negative keywords.
- Updated utils.py to include functions for retrieving negative keywords and email settings.
- Enhanced job filtering logic to exclude jobs containing negative keywords.
2025-11-28 18:15:08 +01:00

95 lines
2.7 KiB
JavaScript

/* javascript form handling */
document.addEventListener("DOMContentLoaded", function () {
const newNkInput = document.getElementById("new-negative-keyword");
if (newNkInput) {
newNkInput.addEventListener("input", function () {
const val = this.value.trim();
const existing = Array.from(
document.querySelectorAll('input[name="negative_keyword"]')
).map((el) => el.value);
if (existing.includes(val)) {
this.setCustomValidity("Keyword already exists");
this.reportValidity();
} else {
this.setCustomValidity("");
}
});
}
});
document
.getElementById("user-settings-form")
.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent default form submission
const form = event.target;
const formData = new FormData(form);
// Collect selected regions and keywords
const selectedRegions = [];
const selectedKeywords = [];
const selectedNegativeKeywords = [];
formData.forEach((value, key) => {
if (key === "region") {
selectedRegions.push(value);
} else if (key === "keyword") {
selectedKeywords.push(value);
} else if (key === "negative_keyword") {
selectedNegativeKeywords.push(value);
}
});
// Add new region if provided
const newRegion = formData.get("new-region").trim();
if (newRegion) {
selectedRegions.push(newRegion);
}
// Add new keyword if provided
const newKeyword = formData.get("new-keyword").trim();
if (newKeyword) {
selectedKeywords.push(newKeyword);
}
// Add new negative keyword if provided
const newNegativeKeyword = formData.get("new-negative-keyword").trim();
if (newNegativeKeyword) {
if (selectedNegativeKeywords.includes(newNegativeKeyword)) {
alert("Negative keyword already exists!");
return;
}
selectedNegativeKeywords.push(newNegativeKeyword);
}
// Prepare data to send
const dataToSend = {
regions: selectedRegions,
keywords: selectedKeywords,
negative_keywords: selectedNegativeKeywords,
csrf_token: formData.get("csrf_token"),
};
// Send data via Fetch API
fetch(form.action, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector('meta[name="csrf-token"]')
.content,
},
body: JSON.stringify(dataToSend),
})
.then((response) => {
if (response.ok) {
window.location.reload(); // Reload to reflect changes
} else {
alert("Error saving preferences.");
}
})
.catch((error) => {
console.error("Error:", error);
alert("Error saving preferences.");
});
});