mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-04 18:06:08 +01:00
Update validation of crowdfund app settings (#3708)
This commit is contained in:
parent
e5feda69c8
commit
642aad28ac
3 changed files with 51 additions and 14 deletions
|
@ -99,27 +99,29 @@ namespace BTCPayServer.Controllers
|
|||
ModelState.AddModelError(nameof(vm.ResetEveryAmount), "You must reset the goal at a minimum of 1 ");
|
||||
}
|
||||
|
||||
if (vm.DisplayPerksRanking && !vm.SortPerksByPopularity)
|
||||
if (vm.DisplayPerksRanking)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.DisplayPerksRanking), "You must sort by popularity in order to display ranking.");
|
||||
vm.SortPerksByPopularity = true;
|
||||
}
|
||||
|
||||
var parsedSounds = vm.Sounds.Split(
|
||||
var parsedSounds = vm.Sounds?.Split(
|
||||
new[] { "\r\n", "\r", "\n" },
|
||||
StringSplitOptions.None
|
||||
).Select(s => s.Trim()).ToArray();
|
||||
if (vm.SoundsEnabled && !parsedSounds.Any())
|
||||
if (vm.SoundsEnabled && (parsedSounds == null || !parsedSounds.Any()))
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.Sounds), "You must have at least one sound if you enable sounds");
|
||||
vm.SoundsEnabled = false;
|
||||
parsedSounds = new CrowdfundSettings().Sounds;
|
||||
}
|
||||
|
||||
var parsedAnimationColors = vm.AnimationColors.Split(
|
||||
var parsedAnimationColors = vm.AnimationColors?.Split(
|
||||
new[] { "\r\n", "\r", "\n" },
|
||||
StringSplitOptions.None
|
||||
).Select(s => s.Trim()).ToArray();
|
||||
if (vm.AnimationsEnabled && !parsedAnimationColors.Any())
|
||||
if (vm.AnimationsEnabled && (parsedAnimationColors == null || !parsedAnimationColors.Any()))
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.AnimationColors), "You must have at least one animation color if you enable animations");
|
||||
vm.AnimationsEnabled = false;
|
||||
parsedAnimationColors = new CrowdfundSettings().AnimationColors;
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
|
|
|
@ -121,10 +121,10 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb-0">
|
||||
<div class="form-group mb-0" id="ResetRow" hidden="@(Model.StartDate == null)">
|
||||
<label asp-for="ResetEvery" class="form-label"></label>
|
||||
<div class="input-group">
|
||||
<input type="number" inputmode="numeric" asp-for="ResetEveryAmount" placeholder="Amount" class="form-control">
|
||||
<input type="number" inputmode="numeric" asp-for="ResetEveryAmount" placeholder="Amount" class="form-control" min="0">
|
||||
<select class="form-select" asp-for="ResetEvery">
|
||||
@foreach (var opt in Model.ResetEveryValues)
|
||||
{
|
||||
|
@ -132,6 +132,7 @@
|
|||
}
|
||||
</select>
|
||||
</div>
|
||||
<span asp-validation-for="ResetEveryAmount" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -287,3 +288,32 @@
|
|||
</div>
|
||||
|
||||
<partial name="_Confirm" model="@(new ConfirmModel("Delete app", "This app will be removed from this store.", "Delete"))" />
|
||||
|
||||
<script>
|
||||
const resetRow = document.getElementById('ResetRow');
|
||||
const startDateInputId = "StartDate";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
setTimeout(() => {
|
||||
flatpickrInstances.forEach((instance) => {
|
||||
if (instance.element.id === startDateInputId) {
|
||||
instance.config.onChange.push((selectedDates) => {
|
||||
if (selectedDates.length) {
|
||||
// Show the reset row if start date is selected.
|
||||
// Since start date must be selected in order for the reset options to be set
|
||||
// we don't need to show it by default and can show it only when start date is selected
|
||||
resetRow.removeAttribute('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 0);
|
||||
|
||||
document.addEventListener('input-group-clear-input-value-cleared', ({ detail }) => {
|
||||
const input = detail[0];
|
||||
if (input.id === startDateInputId) {
|
||||
resetRow.setAttribute('hidden', 'hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const flatpickrInstances = [];
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// sticky header
|
||||
const stickyHeader = document.querySelector('.sticky-header-setup + .sticky-header');
|
||||
|
@ -36,12 +38,12 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
// support for initializing with special options per instance
|
||||
if (fdtp) {
|
||||
var parsed = JSON.parse(fdtp);
|
||||
element.flatpickr(parsed);
|
||||
flatpickrInstances.push(element.flatpickr(parsed));
|
||||
} else {
|
||||
var min = element.attr("min");
|
||||
var max = element.attr("max");
|
||||
var defaultDate = element.attr("value");
|
||||
element.flatpickr({
|
||||
flatpickrInstances.push(element.flatpickr({
|
||||
enableTime: true,
|
||||
enableSeconds: true,
|
||||
dateFormat: 'Z',
|
||||
|
@ -53,7 +55,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
time_24hr: true,
|
||||
defaultHour: 0,
|
||||
static: true
|
||||
});
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -72,7 +74,10 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
}
|
||||
|
||||
$(".input-group-clear").on("click", function () {
|
||||
$(this).parents(".input-group").find("input").val(null);
|
||||
const input = $(this).parents(".input-group").find("input");
|
||||
const event = new CustomEvent('input-group-clear-input-value-cleared', { detail: input });
|
||||
input.val(null);
|
||||
document.dispatchEvent(event);
|
||||
handleInputGroupClearButtonDisplay(this);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue