Add wish image
This commit is contained in:
parent
d5b9ad0f7d
commit
6d6bc3d487
5 changed files with 48 additions and 41 deletions
|
@ -61,11 +61,15 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
|
||||
$wish_title = trim($_POST['wish_title']);
|
||||
$wish_description = trim($_POST['wish_description']);
|
||||
$wish_image = 'NULL';
|
||||
$wish_image = trim($_POST['wish_image']);
|
||||
$wish_url = trim($_POST['wish_url']);
|
||||
$wish_priority = isset($_POST['wish_priority']) && $_POST['wish_priority'] ? $_POST['wish_priority'] : 'NULL';
|
||||
$wish_is_purchasable = isset($_POST['wish_is_purchasable']) ? 'true' : 'false';
|
||||
|
||||
if (Wish::NO_IMAGE === $wish_image) {
|
||||
$wish_image = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['wish_id'], $_POST['wishlist_id'])) {
|
||||
/** Update wish */
|
||||
$wish = new Wish($_POST['wish_id']);
|
||||
|
@ -84,11 +88,13 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
}
|
||||
|
||||
/** Image */
|
||||
if (!empty($info->image)) {
|
||||
$codeImage = URL::getResponseCode($info->image);
|
||||
if (empty($wish_image) && empty($wish->image)) {
|
||||
if (!empty($info->image)) {
|
||||
$codeImage = URL::getResponseCode($info->image);
|
||||
|
||||
if ($codeImage >= 200 && $codeImage < 400) {
|
||||
$wish_image = '"' . $info->image . '"';
|
||||
if ($codeImage >= 200 && $codeImage < 400) {
|
||||
$wish_image = '"' . $info->image . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,9 +104,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
}
|
||||
|
||||
/** Update */
|
||||
$wish_title = empty($wish_title) ? 'NULL' : '"' . substr($wish_title, 0, 128) . '"';
|
||||
$wish_description = empty($wish_description) ? 'NULL' : '"' . $wish_description . '"';
|
||||
$wish_url = empty($wish_url) ? 'NULL' : '"' . $wish_url . '"';
|
||||
$wish_title = empty($wish_title) ? 'NULL' : '"' . substr($wish_title, 0, 128) . '"';
|
||||
$wish_description = empty($wish_description) ? 'NULL' : '"' . $wish_description . '"';
|
||||
$wish_image = empty($wish_image) || Wish::NO_IMAGE === $wish_image ? 'NULL' : '"' . $wish_image . '"';
|
||||
$wish_url = empty($wish_url) ? 'NULL' : '"' . $wish_url . '"';
|
||||
|
||||
$database
|
||||
->query(
|
||||
|
@ -153,11 +160,13 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
}
|
||||
|
||||
/** Image */
|
||||
if (!empty($info->image)) {
|
||||
$codeImage = URL::getResponseCode($info->image);
|
||||
if (empty($wish_image) && empty($wish->image)) {
|
||||
if (!empty($info->image)) {
|
||||
$codeImage = URL::getResponseCode($info->image);
|
||||
|
||||
if ($codeImage >= 200 && $codeImage < 400) {
|
||||
$wish_image = '"' . $info->image . '"';
|
||||
if ($codeImage >= 200 && $codeImage < 400) {
|
||||
$wish_image = '"' . $info->image . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,9 +176,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
}
|
||||
|
||||
/** Update */
|
||||
$wish_title = empty($wish_title) ? 'NULL' : '"' . substr($wish_title, 0, 128) . '"';
|
||||
$wish_description = empty($wish_description) ? 'NULL' : '"' . $wish_description . '"';
|
||||
$wish_url = empty($wish_url) ? 'NULL' : '"' . $wish_url . '"';
|
||||
$wish_title = empty($wish_title) ? 'NULL' : '"' . substr($wish_title, 0, 128) . '"';
|
||||
$wish_description = empty($wish_description) ? 'NULL' : '"' . $wish_description . '"';
|
||||
$wish_image = empty($wish_image) || Wish::NO_IMAGE === $wish_image ? 'NULL' : '"' . $wish_image . '"';
|
||||
$wish_url = empty($wish_url) ? 'NULL' : '"' . $wish_url . '"';
|
||||
|
||||
$database
|
||||
->query(
|
||||
|
|
|
@ -70,16 +70,13 @@ figure {
|
|||
}
|
||||
|
||||
/** Image */
|
||||
svg,
|
||||
.wishlist .ui.card > .image > svg {
|
||||
color: #f0f0f0;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
.wishlist .ui.card > .image > svg {
|
||||
width: 100%;
|
||||
height: var(--wishPreviewHeight);
|
||||
|
||||
color: #f0f0f0;
|
||||
background-color: #f4f4f4;
|
||||
|
||||
box-sizing: border-box;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,11 @@ $(function () {
|
|||
var wishlists = [];
|
||||
|
||||
function wishlistsRefresh() {
|
||||
var selectedValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
||||
|
||||
$('.ui.dropdown.wishlists').api({
|
||||
action : 'get wishlists',
|
||||
method : 'GET',
|
||||
on : 'now',
|
||||
onSuccess: function (response, element, xhr) {
|
||||
action : 'get wishlists',
|
||||
method : 'GET',
|
||||
on : 'now',
|
||||
onSuccess : function (response, element, xhr) {
|
||||
wishlists = response.results;
|
||||
|
||||
element.dropdown({
|
||||
|
@ -24,11 +22,7 @@ $(function () {
|
|||
})
|
||||
|
||||
if (wishlist.id) {
|
||||
if (wishlist.id === selectedValue) {
|
||||
element.dropdown('set selected', wishlist.id, null, true);
|
||||
} else {
|
||||
element.dropdown('set selected', wishlist.id);
|
||||
}
|
||||
element.dropdown('set selected', wishlist.id);
|
||||
} else {
|
||||
if (wishlists[0]) {
|
||||
element.dropdown('set selected', wishlists[0].value);
|
||||
|
@ -396,6 +390,7 @@ $(function () {
|
|||
$('[name="wish_id"]').val(wish.id);
|
||||
$('[name="wish_title"]').val(wish.title);
|
||||
$('[name="wish_description"]').val(wish.description);
|
||||
$('[name="wish_image"]').val(wish.image);
|
||||
$('[name="wish_url"]').val(wish.url);
|
||||
$('.ui.selection.dropdown.priority').dropdown('set selected', wish.priority);
|
||||
|
||||
|
@ -706,11 +701,7 @@ $(function () {
|
|||
/** */
|
||||
}
|
||||
})
|
||||
.catch(handleFetchCatch)
|
||||
.finally(function() {
|
||||
formAddOrEdit.removeClass('loading');
|
||||
buttonAddOrSave.removeClass('disabled');
|
||||
});
|
||||
.catch(handleFetchCatch);
|
||||
} else {
|
||||
/** Save form edit fields */
|
||||
/** This code block is a duplicate, please refactor */
|
||||
|
|
|
@ -109,10 +109,6 @@ class Wish
|
|||
$this->$key = $this->info->$key;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->image)) {
|
||||
$this->image = self::NO_IMAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,6 +186,8 @@ class Wish
|
|||
<?php } else { ?>
|
||||
<img class="preview" src="<?= $this->image ?>" loading="lazy" />
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<?= file_get_contents(ROOT . self::NO_IMAGE) ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (isset($this->info->favicon)) { ?>
|
||||
|
|
|
@ -72,6 +72,17 @@ namespace wishthis;
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label><?= __('Image') ?></label>
|
||||
|
||||
<input type="url"
|
||||
name="wish_image"
|
||||
placeholder="<?= $wish->image ?? '' ?>"
|
||||
value="<?= $wish->image ?? '' ?>"
|
||||
maxlength="255"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grouped fields">
|
||||
<label><?= __('Properties') ?></label>
|
||||
|
||||
|
|
Loading…
Reference in a new issue