Compare commits
4 Commits
9a3d2da412
...
f336917b62
| Author | SHA1 | Date | |
|---|---|---|---|
| f336917b62 | |||
| 4ccb8ac05e | |||
| a6a7fbade6 | |||
| 3f67fe27d0 |
@ -12,6 +12,7 @@ the_header(
|
||||
?>
|
||||
|
||||
<div id="recipe-id" hidden><?= $context['recipe']->get_id() ?></div>
|
||||
<div id="in-usermenu" hidden><?= $context['recipe']->in_usermenu; ?></div>
|
||||
|
||||
<div class="container">
|
||||
<div class="single-recipe">
|
||||
|
||||
@ -15,13 +15,41 @@ document.addEventListener('click', (e) => {
|
||||
|
||||
|
||||
const options = document.querySelectorAll('.dropdown-item');
|
||||
const inUsermenu = document.getElementById('in-usermenu').textContent;
|
||||
|
||||
if (inUsermenu) {
|
||||
options.forEach(option => {
|
||||
if (option.getAttribute('data-value') === inUsermenu && option.getAttribute('data-value') !== 'remove') {
|
||||
option.classList.add('dropdown-selected');
|
||||
toggleBtn.textContent = option.textContent;
|
||||
}
|
||||
});
|
||||
}
|
||||
options.forEach(option => {
|
||||
option.addEventListener('click', () => {
|
||||
option.addEventListener('click', async (e) => {
|
||||
const selectedValue = option.getAttribute('data-value');
|
||||
|
||||
options.forEach(opt => opt.classList.remove('dropdown-selected'));
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'usermenu');
|
||||
formData.append('recipe_id', recipeId);
|
||||
formData.append('dayofweek', selectedValue);
|
||||
|
||||
const response = await fetch('/ajax', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
const message = json.error;
|
||||
showToastify(message, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (selectedValue === 'remove') {
|
||||
toggleBtn.textContent = 'Add to list';
|
||||
} else {
|
||||
@ -31,7 +59,7 @@ options.forEach(option => {
|
||||
|
||||
dropdown.classList.add('hidden');
|
||||
|
||||
alert(`You selected: ${selectedValue}`);
|
||||
showToastify(json.success, 'success');
|
||||
});
|
||||
});
|
||||
|
||||
@ -64,8 +92,8 @@ qrBtn.addEventListener("click", () => {
|
||||
}, 500);
|
||||
});
|
||||
|
||||
document.addEventListener('click', (e) =>{
|
||||
if(!qrPopup.contains(e.target) && !qrBtn.contains(e.target)){
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!qrPopup.contains(e.target) && !qrBtn.contains(e.target)) {
|
||||
qrPopup.classList.add("hidden");
|
||||
overlay.classList.add("hidden");
|
||||
}
|
||||
@ -93,14 +121,14 @@ favoriteBtn.addEventListener('click', async (e) => {
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if(!response.ok) {
|
||||
if (!response.ok) {
|
||||
const message = json.error;
|
||||
showToastify(message, 'error');
|
||||
return;
|
||||
}
|
||||
favoriteBtn.classList.toggle('active');
|
||||
|
||||
if(type == 'add') {
|
||||
if (type == 'add') {
|
||||
favoriteIcon.classList.remove('fa-regular');
|
||||
favoriteIcon.classList.add('fa-solid');
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user