Search dropdown: keyboard navigation, edit/delete actions; edit page delete
- Search dropdown now supports arrow up/down to highlight items, Enter navigates to edit page of highlighted recipe - Each dropdown item shows edit (pencil) and delete (trash) buttons - Edit page now has a "Recept törlése" button with confirmation modal - Successful delete on edit page redirects back to /recipes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -274,9 +274,22 @@
|
||||
<div class="flex mt-2">
|
||||
<button class="btn btn-primary" id="saveBtn" onclick="saveRecipe()">Mentés</button>
|
||||
<a href="/recipes" class="btn btn-secondary">Mégsem</a>
|
||||
<button class="btn btn-danger" onclick="confirmDelete()" style="margin-left:auto;">Recept törlése</button>
|
||||
<span id="saveStatus"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete confirmation modal -->
|
||||
<div id="deleteModal" style="position:fixed;inset:0;background:rgba(0,0,0,0.6);z-index:1000;display:none;align-items:center;justify-content:center;">
|
||||
<div class="card" style="max-width:450px;width:90%;">
|
||||
<h2 style="color:#f85149;margin-bottom:1rem;">Recept törlése</h2>
|
||||
<p id="deleteModalText">Biztosan törölni szeretnéd ezt a receptet? Ez a művelet nem vonható vissza!</p>
|
||||
<div class="flex" style="justify-content:flex-end;gap:0.5rem;margin-top:1rem;">
|
||||
<button class="btn btn-secondary" onclick="closeDeleteModal()">Mégsem</button>
|
||||
<button class="btn btn-danger" onclick="executeDelete()" id="confirmDeleteBtn">Törlés</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
@@ -559,6 +572,46 @@ async function saveRecipe() {
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Delete ===== */
|
||||
function confirmDelete() {
|
||||
const title = document.getElementById('recipeTitle').value.trim() || 'ezt a receptet';
|
||||
document.getElementById('deleteModalText').textContent =
|
||||
'Biztosan törölni szeretnéd a következő receptet: „' + title + '"? Ez a művelet nem vonható vissza!';
|
||||
document.getElementById('deleteModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeDeleteModal() {
|
||||
document.getElementById('deleteModal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function executeDelete() {
|
||||
const btn = document.getElementById('confirmDeleteBtn');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="spinner"></span> Törlés...';
|
||||
|
||||
try {
|
||||
const resp = await fetch('/api/recipes/' + BACKEND + '/delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ids: [RECIPE_ID] }),
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.ok) {
|
||||
window.location.href = '/recipes';
|
||||
} else {
|
||||
closeDeleteModal();
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Törlés';
|
||||
showToast(data.error || 'Hiba történt.', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
closeDeleteModal();
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Törlés';
|
||||
showToast('Hiba: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Toast ===== */
|
||||
function showToast(msg, type) {
|
||||
const el = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user