več pagov, search, flashing fix
This commit is contained in:
@@ -35,4 +35,65 @@ function getLast() {
|
||||
});
|
||||
}
|
||||
|
||||
function search() {
|
||||
const field = document.getElementById("search-input");
|
||||
const val = field.value;
|
||||
if (!val || val === "" || val === "*") { return; }
|
||||
|
||||
const url = `http://localhost:3000/vnosi`;
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: `*${val}*`, // Potencialno mora biti tukaj en "*" wildcard
|
||||
limit: -1
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
console.error('API Error:', data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(data.data);
|
||||
let len = data.data.length;
|
||||
document.getElementById("page-title").innerText = `Rezultati iskanja (${len}):`;
|
||||
document.getElementById("entry-container").innerHTML = "";
|
||||
|
||||
if (len <= 0) {
|
||||
document.getElementById("entry-container").innerHTML = `
|
||||
<p class="page-paragraph">Ni bilo najednih zadetkov za poizvedbo "${val}".</p>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
for (let entry of data.data) {
|
||||
let build = `
|
||||
<div class="entry-card">
|
||||
<h3 class="entry-title">${entry.kljuc}</h3>
|
||||
<p class="entry-definition">${entry.tip}</p>
|
||||
${entry.vsebina}
|
||||
<p class="entry-example">${entry.primer}</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById("entry-container").innerHTML += build;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById("search-input").addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
search();
|
||||
}
|
||||
});
|
||||
|
||||
// DELAJ DELAJ
|
||||
getLast();
|
||||
Reference in New Issue
Block a user