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`
(
`wishlist`,
`title`,
`url`
) VALUES ('
. $_POST['wishlist_id'] . ',
"' . $_POST['wish_title'] . '",
"' . $_POST['wish_url'] . '"
)
;');

View file

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

View file

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

View file

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

View file

@ -127,28 +127,38 @@ $page->navigation();
<div class="header">
Add a wish
</div>
<div class="image content">
<div class="ui medium image">
<img src="/src/assets/img/no-image.svg" loading="lazy" />
</div>
<div class="content">
<div class="description">
<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" />
<div class="field">
<label>URL</label>
<input type="url" name="wish_url" />
<label>Title</label>
<input type="text" name="wish_title" maxlength="128" />
</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>
</div>
</div>
<div class="actions">
<div class="ui primary approve button disabled">
<div class="ui primary approve button">
Add
</div>
<div class="ui deny button">