Add wish type

This commit is contained in:
grandeljay 2022-02-26 23:15:03 +01:00
parent 8e3d06b084
commit 14ee9d09fd
3 changed files with 21 additions and 7 deletions

View file

@ -24,9 +24,11 @@ switch ($_SERVER['REQUEST_METHOD']) {
$database->query('INSERT INTO `wishes` $database->query('INSERT INTO `wishes`
( (
`wishlist`, `wishlist`,
`type`,
`url` `url`
) VALUES (' ) VALUES ('
. $_POST['wishlist_id'] . ', . $_POST['wishlist_id'] . ',
"' . $_POST['wish_type'] . '",
"' . $_POST['wish_url'] . '" "' . $_POST['wish_url'] . '"
) )
;'); ;');

View file

@ -376,6 +376,8 @@ $(function () {
/** /**
* Add wish * Add wish
*/ */
$('.ui.dropdown.types').dropdown();
$(document).on('click', '.button.wishlist-wish-add', function () { $(document).on('click', '.button.wishlist-wish-add', function () {
var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add'); var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add');
@ -387,17 +389,16 @@ $(function () {
onApprove: function (button) { onApprove: function (button) {
button.addClass('loading'); button.addClass('loading');
var form = $('.ui.form.wishlist-wish-fetch'); var form = $('.ui.form.wishlist-wish-fetch');
var formData = new URLSearchParams(); var formData = new URLSearchParams(new FormData(form[0]));
formData.append('wishlist_id', form.find('input[name="wishlist_id"]').val());
formData.append('wish_url', form.find('input[name="wish_url"]').val());
fetch('/src/api/wishes.php', { fetch('/src/api/wishes.php', {
method: 'POST', method: 'POST',
body: formData body: formData
}) })
.then(response => response.json()) .then(handleFetchError)
.then(response => { .then(handleFetchResponse)
.then(function(response) {
if (response.success) { if (response.success) {
$('body').toast({ $('body').toast({
class: 'success', class: 'success',
@ -411,6 +412,9 @@ $(function () {
} }
button.removeClass('loading'); button.removeClass('loading');
})
.catch(function(error) {
console.log(error);
}); });
return false; return false;

View file

@ -138,6 +138,14 @@ $page->navigation();
<form class="ui form wishlist-wish-fetch" method="post"> <form class="ui form wishlist-wish-fetch" method="post">
<input type="hidden" name="wishlist_id" /> <input type="hidden" name="wishlist_id" />
<div class="field">
<label>Type</label>
<select class="ui fluid selection dropdown types" name="wish_type">
<option value="product">Product</option>
<option value="custom" disabled>Custom</option>
</select>
</div>
<div class="field"> <div class="field">
<label>URL</label> <label>URL</label>
<input type="url" name="wish_url" /> <input type="url" name="wish_url" />