Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
ec559f5c72 |
@@ -119,7 +119,7 @@
|
||||
let lastResults = [];
|
||||
|
||||
function createPhoneLink(phone) {
|
||||
if (!phone) return 'N/A';
|
||||
if (!phone) return '';
|
||||
|
||||
const clientIP = '{{ request.headers.get("X-Forwarded-For", request.remote_addr) }}';
|
||||
const allowedIPRanges = '{{ allowed_ip_ranges }}'.split(',');
|
||||
@@ -143,7 +143,7 @@
|
||||
}
|
||||
|
||||
function createEmailLink(email) {
|
||||
if (!email) return 'N/A';
|
||||
if (!email) return '';
|
||||
return `<a href="mailto:${email}" class="email-link">${email}</a>`;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
}
|
||||
|
||||
function createAddressLink(street, plz, city) {
|
||||
if (!street || !plz || !city) return 'N/A';
|
||||
if (!street || !plz || !city) return '';
|
||||
const address = `${street}, ${plz} ${city}`;
|
||||
const searchQuery = encodeURIComponent(address);
|
||||
const routeQuery = encodeURIComponent(address);
|
||||
@@ -243,7 +243,7 @@
|
||||
const resultsDiv = document.getElementById('results');
|
||||
const resultCount = document.getElementById('resultCount');
|
||||
|
||||
if (results.length === 0) {
|
||||
if (!results || results.length === 0) {
|
||||
resultsDiv.innerHTML = '<p>Keine Ergebnisse gefunden.</p>';
|
||||
resultCount.textContent = '0 Ergebnisse';
|
||||
return;
|
||||
@@ -251,7 +251,15 @@
|
||||
|
||||
resultCount.textContent = `${results.length} Ergebnisse`;
|
||||
|
||||
const resultsList = results.map(customer => `
|
||||
const resultsList = results.map(customer => {
|
||||
// Hilfsfunktion zum Erstellen von Feldern nur wenn sie Werte haben
|
||||
const createFieldIfValue = (label, value, formatter = (v) => v) => {
|
||||
if (!value || value === 'N/A' || value === 'n/a' || value === 'N/a' || (typeof value === 'string' && value.trim() === '')) return '';
|
||||
const formattedValue = formatter(value);
|
||||
return `<p><strong>${label}:</strong> ${formattedValue}</p>`;
|
||||
};
|
||||
|
||||
return `
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
@@ -264,12 +272,18 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-text">
|
||||
<p><strong>Nummer:</strong> ${customer.nummer}</p>
|
||||
<p><strong>Adresse:</strong> ${createAddressLink(customer.strasse, customer.plz, customer.ort)}</p>
|
||||
<p><strong>Telefon:</strong> ${createPhoneLink(customer.telefon)}</p>
|
||||
<p><strong>Mobil:</strong> ${createPhoneLink(customer.mobil)}</p>
|
||||
<p><strong>E-Mail:</strong> ${createEmailLink(customer.email)}</p>
|
||||
<p><strong>Fachrichtung:</strong> ${customer.fachrichtung}</p>
|
||||
${createFieldIfValue('Nummer', customer.nummer)}
|
||||
${createFieldIfValue('Adresse', (customer.strasse && customer.plz && customer.ort) ? true : false,
|
||||
() => createAddressLink(customer.strasse, customer.plz, customer.ort))}
|
||||
${createFieldIfValue('Telefon', customer.telefon, createPhoneLink)}
|
||||
${createFieldIfValue('Mobil', customer.mobil, createPhoneLink)}
|
||||
${createFieldIfValue('Handy', customer.handy, createPhoneLink)}
|
||||
${createFieldIfValue('Telefon Firma', customer.tele_firma, createPhoneLink)}
|
||||
${createFieldIfValue('E-Mail', customer.email, createEmailLink)}
|
||||
${createFieldIfValue('Fachrichtung', customer.fachrichtung)}
|
||||
${createFieldIfValue('Kontakt 1', customer.kontakt1, createPhoneLink)}
|
||||
${createFieldIfValue('Kontakt 2', customer.kontakt2, createPhoneLink)}
|
||||
${createFieldIfValue('Kontakt 3', customer.kontakt3, createPhoneLink)}
|
||||
${customer.tags && customer.tags.length > 0 ? `
|
||||
<p><strong>Tags:</strong>
|
||||
${customer.tags.map(tag => `<span class="badge bg-primary me-1">${tag}</span>`).join('')}
|
||||
@@ -278,7 +292,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
`}).join('');
|
||||
|
||||
resultsDiv.innerHTML = resultsList;
|
||||
}
|
||||
@@ -309,12 +323,18 @@
|
||||
|
||||
// Führe die Suche durch
|
||||
fetch('/search?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Netzwerk-Antwort war nicht ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
// Verstecke das Lade-Icon
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
|
||||
if (data.error) {
|
||||
console.error('Fehler bei der Suche:', data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -324,6 +344,8 @@
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
console.error('Fehler bei der Suche:', error);
|
||||
document.getElementById('results').innerHTML = '<p>Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.</p>';
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user