Use same fields for add and edit wish

This commit is contained in:
Jay Trees 2022-04-08 13:37:22 +02:00
parent 1fde8a81be
commit 6c47875d78
13 changed files with 111 additions and 108 deletions

View file

@ -56,20 +56,24 @@ switch ($_SERVER['REQUEST_METHOD']) {
$wishlist_id = $_POST['wishlist_id'];
$wish_title = trim($_POST['wish_title']);
$wish_description = $_POST['wish_description'] ?: '';
$wish_description = trim($_POST['wish_description']);
$wish_url = trim($_POST['wish_url']);
$wish_priority = isset($_POST['wish_priority']) && $_POST['wish_priority'] ? $_POST['wish_priority'] : 'NULL';
$database->query('INSERT INTO `wishes`
$database
->query('INSERT INTO `wishes`
(
`wishlist`,
`title`,
`description`,
`url`
) VALUES ('
. $wishlist_id . ',
`url`,
`priority`
) VALUES (
' . $wishlist_id . ',
"' . $wish_title . '",
"' . $wish_description . '",
"' . $wish_url . '"
"' . $wish_url . '",
' . $wish_priority . '
)
;');

View file

@ -0,0 +1,8 @@
$(function () {
/**
* Priority
*/
$('.dropdown.priority').dropdown();
});

View file

@ -144,9 +144,4 @@ $(function () {
});
});
/**
* Priority
*/
$('.dropdown.priority').dropdown();
});

View file

@ -55,8 +55,6 @@ $(function () {
/** Update URL */
urlParams.set('id', wishlistValue);
console.log(wishlistValue);
fetch('/src/api/url.php?url=' + window.btoa(urlParams.toString()), {
method: 'GET'
})
@ -369,7 +367,7 @@ $(function () {
modalWishlistWishAdd
.modal({
autoShow : true,
onApprove: function (buttonAdd) {
onApprove : function (buttonAdd) {
buttonAdd.addClass('loading');
var form = $('.form.wishlist-wish-add');

View file

@ -31,7 +31,7 @@ switch ($step) {
<p><?= __('Welcome to the wishthis installer.') ?></p>
<p><?= __('wishthis needs a database to function properly. Please enter your credentials.') ?></p>
<form class="ui form" action="/?page=install" method="post">
<form class="ui form" action="/?page=install" method="POST">
<input type="hidden" name="install" value="true" />
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
@ -101,7 +101,7 @@ switch ($step) {
<h2 class="ui header"><?= sprintf(__('Step %d'), $step) ?></h2>
<p><?= __('Click continue to test the database connection.') ?></p>
<form class="ui form" action="?page=install" method="post">
<form class="ui form" action="?page=install" method="POST">
<input type="hidden" name="install" value="true" />
<input type="hidden" name="step" value="<?= $step + 1; ?>" />

View file

@ -43,7 +43,7 @@ $page->navigation();
?>
<div class="ui segment">
<form class="ui form" method="post">
<form class="ui form" method="POST">
<div class="field">
<label><?= __('Email') ?></label>
<input type="email" name="email" placeholder="john.doe@domain.tld" />

View file

@ -105,7 +105,7 @@ $page->navigation();
<div class="column">
<h2 class="ui header"><?= __('Credentials') ?></h2>
<form class="ui form login" method="post">
<form class="ui form login" method="POST">
<div class="field">
<label><?= __('Email') ?></label>
@ -147,7 +147,7 @@ $page->navigation();
<?php if ($options->getOption('mjml_api_key') && $options->getOption('mjml_api_secret')) { ?>
<p>
<form class="ui form reset" method="post">
<form class="ui form reset" method="POST">
<div class="field">
<div class="ui action input">
<div class="ui left icon action input">

View file

@ -0,0 +1,71 @@
<?php
/**
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\Wish;
$scriptPart = '/src/assets/js/parts/wish-priority.js';
?>
<script defer src="<?= $scriptPart ?>?m=<?= filemtime(ROOT . $scriptPart) ?>"></script>
<div class="stackable row">
<div class="column">
<div class="field">
<label><?= __('Title') ?></label>
<div class="ui input">
<input type="text"
name="wish_title"
placeholder="<?= $wish->title ?? '' ?>"
value="<?= $wish->title ?? '' ?>"
maxlength="128"
/>
</div>
</div>
<div class="field">
<label><?= __('Description') ?></label>
<textarea name="wish_description"
placeholder="<?= $wish->description ?? '' ?>"
><?= $wish->description ?? '' ?></textarea>
</div>
</div>
<div class="column">
<div class="field">
<label><?= __('URL') ?></label>
<input type="url"
name="wish_url"
placeholder="<?= $wish->url ?? '' ?>"
value="<?= $wish->url ?? '' ?>"
maxlength="255"
/>
</div>
<div class="field">
<label><?= __('Priority') ?></label>
<select class="ui selection clearable dropdown priority"
name="wish_priority"
>
<option value=""><?= __('Select priority') ?></option>
<?php foreach (Wish::$priorities as $priority => $item) { ?>
<?php if (isset($wish->priority) && $wish->priority === $priority) { ?>
<option value="<?= $priority ?>" selected><?= $item['name'] ?></option>
<?php } else { ?>
<option value="<?= $priority ?>"><?= $item['name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
</div>

View file

@ -8,7 +8,7 @@ use wishthis\Wish;
$scriptPart = '/src/assets/js/parts/wishlist-filter.js';
?>
<script defer src="/src/assets/js/parts/wishlist-filter.js?m=<?= filemtime(ROOT . $scriptPart) ?>"></script>
<script defer src="<?= $scriptPart ?>?m=<?= filemtime(ROOT . $scriptPart) ?>"></script>
<div>
<div class="ui stackable grid">

View file

@ -164,7 +164,7 @@ $page->navigation();
<?= $page->messages() ?>
<div class="ui segment">
<form class="ui form" method="post">
<form class="ui form" method="POST">
<div class="ui divided relaxed stackable two column grid">
<div class=" row">

View file

@ -67,7 +67,7 @@ $page->navigation();
<h2 class="ui header"><?= __('Database migration') ?></h2>
<p><?= __('Thank you for updating wishthis! To complete this update, some changes are required to the database structure.') ?></p>
<form class="ui form" method="post">
<form class="ui form" method="POST">
<button class="ui orange button"
type="submit"
title="<?= sprintf(__('Migrate to %s'), 'v' . VERSION) ?>"

View file

@ -106,66 +106,7 @@ $referer = '/?page=wishlists&id=' . $wish->wishlist;
<input type="hidden" name="wish_image" value="<?= $wish->image ?>" />
<div class="ui two column grid">
<div class="stackable row">
<div class="column">
<div class="field">
<label><?= __('Title') ?></label>
<div class="ui input">
<input type="text"
name="wish_title"
placeholder="<?= $wish->title ?>"
value="<?= $wish->title ?>"
maxlength="128"
/>
</div>
</div>
<div class="field">
<label><?= __('Description') ?></label>
<textarea name="wish_description"
placeholder="<?= $wish->description ?>"
><?= $wish->description ?></textarea>
</div>
</div>
<div class="column">
<div class="field">
<label><?= __('URL') ?></label>
<input type="url"
name="wish_url"
placeholder="<?= $wish->url ?>"
value="<?= $wish->url ?>"
maxlength="255"
/>
</div>
<div class="field">
<label><?= __('Priority') ?></label>
<select class="ui selection clearable dropdown priority"
name="wish_priority"
>
<option value=""><?= __('Select priority') ?></option>
<?php foreach (Wish::$priorities as $priority => $item) { ?>
<?php if ($wish->priority === $priority) { ?>
<option value="<?= $priority ?>" selected><?= $item['name'] ?></option>
<?php } else { ?>
<option value="<?= $priority ?>"><?= $item['name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
</div>
<?php include 'parts/wish-add.php' ?>
<div class="stackable row">
<div class="sixteen wide column">

View file

@ -175,25 +175,11 @@ $page->navigation();
<div class="description">
<p><?= __('Fill out any or all of the below fields to add your new wish.') ?></p>
<form class="ui form wishlist-wish-add" method="post">
<input type="hidden" name="wishlist_id" />
<form class="ui form wishlist-wish-add" method="POST">
<input type="hidden" name="wishlist_id" value="<?= $_GET['id'] ?>" />
<div class="field">
<label><?= __('Title') ?></label>
<input type="text" name="wish_title" maxlength="128" />
</div>
<div class="field">
<label><?= __('Description') ?></label>
<textarea name="wish_description"></textarea>
</div>
<div class="field">
<label><?= __('URL') ?></label>
<div class="ui input url">
<input type="url" name="wish_url" maxlength="255" />
</div>
<div class="ui two column grid">
<?php include 'parts/wish-add.php' ?>
</div>
</form>
</div>