Add wish title

This commit is contained in:
grandeljay 2022-02-27 00:39:08 +01:00
parent 0b2e8889d3
commit 95fce926c5
5 changed files with 51 additions and 39 deletions

View file

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

View file

@ -380,14 +380,12 @@ $(function () {
var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add'); var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add');
modalWishlistWishAdd.find('[name="wishlist_id"]').val($('.ui.dropdown.wishlists').dropdown('get value')); modalWishlistWishAdd.find('[name="wishlist_id"]').val($('.ui.dropdown.wishlists').dropdown('get value'));
modalWishlistWishAdd.find('.primary.approve.button').addClass('disabled');
modalWishlistWishAdd modalWishlistWishAdd
.modal({ .modal({
onApprove: function (button) { onApprove: function (buttonAdd) {
button.addClass('loading'); buttonAdd.addClass('loading');
var form = $('.ui.form.wishlist-wish-fetch'); var form = $('.form.wishlist-wish-add');
var formData = new URLSearchParams(new FormData(form[0])); var formData = new URLSearchParams(new FormData(form[0]));
fetch('/src/api/wishes.php', { fetch('/src/api/wishes.php', {
@ -409,7 +407,7 @@ $(function () {
modalWishlistWishAdd.modal('hide'); modalWishlistWishAdd.modal('hide');
} }
button.removeClass('loading'); buttonAdd.removeClass('loading');
}) })
.catch(function(error) { .catch(function(error) {
console.log(error); console.log(error);
@ -422,20 +420,19 @@ $(function () {
}); });
/** Fetch */ /** Fetch */
$(document).on('submit', '.wishlist-wish-fetch', function (event) { $(document).on('click', '#wishlist-wish-add-url-validate', function () {
event.preventDefault(); var buttonValidate = $(this);
var inputWishURL = buttonValidate.prev();
var form = $(event.currentTarget); var inputURLContainer = buttonValidate.parent();
var href = form.find('[name="wish_url"]').val();
var elementModalAdd = $('.ui.modal.wishlist-wish-add'); var elementModalAdd = $('.ui.modal.wishlist-wish-add');
var elementButtons = elementModalAdd.find('.actions .button'); var elementButtons = elementModalAdd.find('.actions .button');
var elementImage = elementModalAdd.find('.image img'); var elementName = elementModalAdd.find('input[name="wish_name"]');
form.addClass('loading'); buttonValidate.addClass('disabled loading');
elementButtons.addClass('disabled'); elementButtons.addClass('disabled');
fetch('/src/api/cache.php?wish_url=' + href, { fetch('/src/api/cache.php?wish_url=' + inputWishURL.val(), {
method: 'GET' method: 'GET'
}) })
.then(response => response.json()) .then(response => response.json())
@ -444,19 +441,19 @@ $(function () {
var info = response.data; var info = response.data;
/** /**
* Image * Name
*/ */
if (info.image && elementImage.length) { if (info.title && elementName.length) {
elementImage.attr('src', info.image); elementName.val(info.title);
} }
/** /**
* URL * URL
*/ */
if (info.url && info.url !== href) { if (info.url && info.url !== inputWishURL.val()) {
var elementModalFetch = $('.ui.modal.wishlist-wish-fetch'); var elementModalFetch = $('.ui.modal.wishlist-wish-fetch');
elementModalFetch.find('input.current').val(href); elementModalFetch.find('input.current').val(inputWishURL.val());
elementModalFetch.find('input.proposed').val(info.url); elementModalFetch.find('input.proposed').val(info.url);
elementButtons.addClass('disabled'); elementButtons.addClass('disabled');
@ -467,7 +464,7 @@ $(function () {
closable: false, closable: false,
onApprove: function (buttonFetch) { onApprove: function (buttonFetch) {
var formData = new URLSearchParams(); var formData = new URLSearchParams();
formData.append('wish_url_current', href); formData.append('wish_url_current', inputWishURL.val());
formData.append('wish_url_proposed', info.url); formData.append('wish_url_proposed', info.url);
buttonFetch.addClass('loading'); buttonFetch.addClass('loading');
@ -479,7 +476,7 @@ $(function () {
.then(response => response.json()) .then(response => response.json())
.then(response => { .then(response => {
if (response.success) { if (response.success) {
form.find('input[type="url"]').val(info.url); inputWishURL.val(info.url);
elementModalFetch.modal('hide'); elementModalFetch.modal('hide');
} }
@ -490,15 +487,17 @@ $(function () {
return false; return false;
}, },
onHide: function() { onHide: function() {
form.removeClass('loading'); buttonValidate.removeClass('disabled loading');
elementButtons.removeClass('disabled'); elementButtons.removeClass('disabled');
} }
}) })
.modal('show'); .modal('show');
} else { } else {
form.removeClass('loading'); buttonValidate.removeClass('disabled loading');
elementButtons.removeClass('disabled'); elementButtons.removeClass('disabled');
} }
inputURLContainer.attr('data-validated', 'true');
} }
}); });
}); });

View file

@ -89,6 +89,8 @@ class Wishlist
$cache = new EmbedCache($wish['url']); $cache = new EmbedCache($wish['url']);
$info = $cache->get(false); $info = $cache->get(false);
$exists = $cache->exists() ? 'true' : 'false'; $exists = $cache->exists() ? 'true' : 'false';
$title = $wish['title'] ?? $info->title;
?> ?>
<div class="column"> <div class="column">
<div class="ui fluid card stretch" data-id="<?= $wish['id'] ?>" data-index="<?= $cardIndex ?>" data-cache="<?= $exists ?>"> <div class="ui fluid card stretch" data-id="<?= $wish['id'] ?>" data-index="<?= $cardIndex ?>" data-cache="<?= $exists ?>">
@ -114,14 +116,13 @@ class Wishlist
<?php } ?> <?php } ?>
</div> </div>
<div class="content"> <div class="content">
<?php if ($info->title) { ?> <?php if ($title) { ?>
<div class="header"> <div class="header">
<?php if ($info->url) { ?> <?php if ($info->url) { ?>
<a href="<?= $info->url ?>" target="_blank"><?= $info->title ?></a> <a href="<?= $info->url ?>" target="_blank"><?= $title ?></a>
<?php } else { ?> <?php } else { ?>
<?= $info->title ?> <?= $title ?>
<?php } ?> <?php } ?>
</div> </div>
<?php } ?> <?php } ?>
@ -151,7 +152,7 @@ class Wishlist
<?php if ($info->url) { ?> <?php if ($info->url) { ?>
<a class="ui small labeled icon button" href="<?= $info->url ?>" target="_blank"> <a class="ui small labeled icon button" href="<?= $info->url ?>" target="_blank">
<i class="external icon"></i> <i class="external icon"></i>
View Visit
</a> </a>
<?php } ?> <?php } ?>

View file

@ -140,7 +140,7 @@ switch ($step) {
$database->query('CREATE TABLE `wishes` ( $database->query('CREATE TABLE `wishes` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`wishlist` INT NOT NULL, `wishlist` INT NOT NULL,
`type` VARCHAR(32) NULL DEFAULT NULL, `title` VARCHAR(128) NULL DEFAULT NULL,
`url` VARCHAR(255) NULL DEFAULT NULL, `url` VARCHAR(255) NULL DEFAULT NULL,
`status` VARCHAR(32) NULL DEFAULT NULL, `status` VARCHAR(32) NULL DEFAULT NULL,
FOREIGN KEY (`wishlist`) FOREIGN KEY (`wishlist`)

View file

@ -127,28 +127,38 @@ $page->navigation();
<div class="header"> <div class="header">
Add a wish Add a wish
</div> </div>
<div class="image content"> <div class="content">
<div class="ui medium image">
<img src="/src/assets/img/no-image.svg" loading="lazy" />
</div>
<div class="description"> <div class="description">
<div class="ui header">Wish</div> <div class="ui header">Wish</div>
<p>Fill out the below fields to add your new wish.</p> <p>Fill out any or all of the below fields to add your new wish.</p>
<form class="ui form wishlist-wish-fetch" method="post"> <form class="ui form wishlist-wish-add" method="post">
<input type="hidden" name="wishlist_id" /> <input type="hidden" name="wishlist_id" />
<div class="field"> <div class="field">
<label>URL</label> <label>Title</label>
<input type="url" name="wish_url" /> <input type="text" name="wish_title" maxlength="128" />
</div> </div>
<input class="ui button" type="submit" value="Fetch" /> <div class="field">
<label>URL</label>
<div class="ui action input url">
<input type="url" name="wish_url" maxlength="255" />
<button class="ui button"
id="wishlist-wish-add-url-validate"
type="button"
>
Validate
</button>
</div>
</div>
</form> </form>
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
<div class="ui primary approve button disabled"> <div class="ui primary approve button">
Add Add
</div> </div>
<div class="ui deny button"> <div class="ui deny button">