fix w formularzu

This commit is contained in:
Mateusz Gruszczyński
2025-09-26 23:07:17 +02:00
parent f7a99df93d
commit 95b01665b9

View File

@@ -1,7 +1,8 @@
{# templates/zbiorka_form.html #}
{# templates/formularz_zbiorek.html #}
{% extends 'base.html' %}
{% set is_edit = zbiorka is not none %}
{% set has_obj = zbiorka is not none %}
{% set is_edit = has_obj and zbiorka.id is not none %}
{% block title %}{{ 'Edytuj zbiórkę' if is_edit else 'Dodaj zbiórkę' }}{% endblock %}
@@ -15,17 +16,15 @@
<!-- Nawigacja / powrót -->
<div class="d-flex align-items-center gap-2 mb-3">
{% if is_edit %}
<a href="{{ url_for('zbiorka', zbiorka_id=zbiorka.id) }}" class="btn btn-sm btn-outline-light border">
Szczegóły zbiórki</a>
{% if is_edit and zbiorka and zbiorka.id %}
<a href="{{ url_for('zbiorka', zbiorka_id=zbiorka.id) }}" class="btn btn-sm btn-outline-light border"> Szczegóły zbiórki</a>
{% else %}
<a href="{{ url_for('admin_dashboard') }}" class="btn btn-sm btn-outline-light border">← Panel Admina</a>
{% endif %}
</div>
<div class="card shadow-sm">
<div
class="card-header bg-secondary text-white d-flex flex-wrap align-items-center justify-content-between gap-2">
<div class="card-header bg-secondary text-white d-flex flex-wrap align-items-center justify-content-between gap-2">
<h3 class="card-title mb-0">
{{ 'Edytuj zbiórkę' if is_edit else 'Dodaj nową zbiórkę' }}
</h3>
@@ -40,32 +39,32 @@
{% if not zbiorka.ukryj_kwote %}
<span class="badge bg-dark border" style="border-color: var(--border);">
Stan: {{ zbiorka.stan|round(2) }} PLN
Stan: {{ (zbiorka.stan or 0)|round(2) }} PLN
</span>
{% if zbiorka.cel %}
{% set delta = zbiorka.cel - zbiorka.stan %}
{% set delta = (zbiorka.cel or 0) - (zbiorka.stan or 0) %}
{% if delta > 0 %}
<span class="badge bg-dark border" style="border-color: var(--border);">
Brakuje: {{ delta|round(2) }} PLN
</span>
{% elif delta < 0 %} <span class="badge bg-dark border" style="border-color: var(--border);">
{% elif delta < 0 %}
<span class="badge bg-dark border" style="border-color: var(--border);">
Nadwyżka: {{ (-delta)|round(2) }} PLN
</span>
{% endif %}
{% endif %}
{% endif %}
</span>
{% endif %}
{% endif %}
{% endif %}
{% if zbiorka.ukryj_kwote %}
<span class="badge bg-secondary">Kwoty niepubliczne</span>
{% else %}
<span class="badge bg-success">Kwoty widoczne</span>
{% endif %}
{% if zbiorka.ukryj_kwote %}
<span class="badge bg-secondary">Kwoty niepubliczne</span>
{% else %}
<span class="badge bg-success">Kwoty widoczne</span>
{% endif %}
</div>
{% else %}
<small class="opacity-75">Uzupełnij podstawowe dane i dane płatności</small>
{% endif %}
</div>
<div class="card-body">
@@ -78,19 +77,33 @@
<div class="row g-3">
<div class="col-12">
<label for="nazwa" class="form-label">Nazwa zbiórki</label>
<input type="text" class="form-control" id="nazwa" name="nazwa" maxlength="120"
<input
type="text"
class="form-control"
id="nazwa"
name="nazwa"
maxlength="120"
placeholder="{{ 'Krótki, zrozumiały tytuł' if is_edit else 'Np. Wsparcie dla schroniska Azor' }}"
value="{{ zbiorka.nazwa if is_edit else '' }}" required aria-describedby="nazwaHelp">
value="{{ (zbiorka.nazwa if zbiorka else request.form.get('nazwa','')) }}"
required
aria-describedby="nazwaHelp"
>
<div id="nazwaHelp" class="form-text">Krótki, zrozumiały tytuł. Max 120 znaków.</div>
</div>
<div class="col-12">
<label for="opis" class="form-label">Opis (Markdown)</label>
<textarea class="form-control" id="opis" name="opis" rows="8" required
aria-describedby="opisHelp">{{ zbiorka.opis if is_edit else '' }}</textarea>
<textarea
class="form-control"
id="opis"
name="opis"
rows="8"
required
aria-describedby="opisHelp"
>{{ (zbiorka.opis if zbiorka else request.form.get('opis','')) }}</textarea>
<div class="d-flex justify-content-between">
<small id="opisHelp" class="form-text text-muted">
Możesz używać **Markdown** (nagłówki, listy, linki). W edytorze włącz podgląd 👁️.
Możesz używać Markdown (nagłówki, listy, linki). W edytorze włącz podgląd 👁️.
</small>
<small class="text-muted"><span id="opisCount">0</span> znaków</small>
</div>
@@ -120,51 +133,38 @@
</tr>
</thead>
<tbody id="produkty-body">
{% set items = zbiorka.przedmioty if is_edit and zbiorka and zbiorka.przedmioty else []
%}
{% set items = (zbiorka.przedmioty if zbiorka and zbiorka.przedmioty else []) %}
{% if items %}
{% for it in items %}
{% set i = loop.index0 %}
<tr>
<td>
<input type="text" class="form-control" name="item_nazwa[]"
value="{{ it.nazwa }}" placeholder="np. Karma Brit 10kg" required>
<input type="text" class="form-control" name="item_nazwa[]" value="{{ it.nazwa }}" placeholder="np. Karma Brit 10kg" required>
</td>
<td>
<input type="url" class="form-control" name="item_link[]"
value="{{ it.link or '' }}" placeholder="https://...">
<input type="url" class="form-control" name="item_link[]" value="{{ it.link or '' }}" placeholder="https://...">
</td>
<td>
<input type="text" inputmode="decimal" class="form-control text-end"
name="item_cena[]"
value="{{ (it.cena|round(2)) if it.cena is not none else '' }}"
placeholder="0,00">
<input type="text" inputmode="decimal" class="form-control text-end" name="item_cena[]" value="{{ (it.cena|round(2)) if it.cena is not none else '' }}" placeholder="0,00">
</td>
<td>
<div class="form-check form-switch">
<input class="form-check-input kupione-switch" type="checkbox" {% if
it.kupione %}checked{% endif %}>
<input type="hidden" name="item_kupione_val_{{ i }}"
value="{{ 1 if it.kupione else 0 }}">
<label class="form-check-label small">{{ 'Kupione' if it.kupione else 'Do
kupienia' }}</label>
<input class="form-check-input kupione-switch" type="checkbox" {% if it.kupione %}checked{% endif %}>
<input type="hidden" name="item_kupione_val_{{ i }}" value="{{ 1 if it.kupione else 0 }}">
<label class="form-check-label small">{{ 'Kupione' if it.kupione else 'Do kupienia' }}</label>
</div>
</td>
<td class="text-end">
<button type="button" class="btn btn-sm btn-outline-light border remove-row"
title="Usuń wiersz"></button>
<button type="button" class="btn btn-sm btn-outline-light border remove-row" title="Usuń wiersz"></button>
</td>
</tr>
{% endfor %}
{% else %}
<!-- pusty wiersz startowy -->
<tr>
<td><input type="text" class="form-control" name="item_nazwa[]"
placeholder="np. Karma Brit 10kg" required></td>
<td><input type="url" class="form-control" name="item_link[]"
placeholder="https://..."></td>
<td><input type="text" inputmode="decimal" class="form-control text-end"
name="item_cena[]" placeholder="0,00"></td>
<td><input type="text" class="form-control" name="item_nazwa[]" placeholder="np. Karma Brit 10kg" required></td>
<td><input type="url" class="form-control" name="item_link[]" placeholder="https://..."></td>
<td><input type="text" inputmode="decimal" class="form-control text-end" name="item_cena[]" placeholder="0,00"></td>
<td>
<div class="form-check form-switch">
<input class="form-check-input kupione-switch" type="checkbox">
@@ -173,8 +173,7 @@
</div>
</td>
<td class="text-end">
<button type="button" class="btn btn-sm btn-outline-light border remove-row"
title="Usuń wiersz"></button>
<button type="button" class="btn btn-sm btn-outline-light border remove-row" title="Usuń wiersz"></button>
</td>
</tr>
{% endif %}
@@ -183,10 +182,8 @@
</div>
<div class="d-flex gap-2">
<button type="button" class="btn btn-sm btn-outline-light border" id="add-row">+ Dodaj
pozycję</button>
<button type="button" class="btn btn-sm btn-outline-light border" id="clear-empty">Usuń puste
wiersze</button>
<button type="button" class="btn btn-sm btn-outline-light border" id="add-row">+ Dodaj pozycję</button>
<button type="button" class="btn btn-sm btn-outline-light border" id="clear-empty">Usuń puste wiersze</button>
</div>
</div>
@@ -200,34 +197,51 @@
<label for="numer_konta" class="form-label">Numer konta (IBAN)</label>
<div class="input-group">
<span class="input-group-text">PL</span>
<input type="text" class="form-control" id="numer_konta" name="numer_konta"
inputmode="numeric" autocomplete="off"
placeholder="12 3456 7890 1234 5678 9012 3456" required aria-describedby="ibanHelp"
value="{% if is_edit and zbiorka.numer_konta %}{{ zbiorka.numer_konta }}{% elif global_settings %}{{ global_settings.numer_konta }}{% else %}{% endif %}">
<input
type="text"
class="form-control"
id="numer_konta"
name="numer_konta"
inputmode="numeric"
autocomplete="off"
placeholder="12 3456 7890 1234 5678 9012 3456"
required
aria-describedby="ibanHelp"
value="{% if zbiorka and zbiorka.numer_konta %}{{ zbiorka.numer_konta }}{% elif global_settings %}{{ global_settings.numer_konta }}{% else %}{{ request.form.get('numer_konta','') }}{% endif %}"
>
</div>
<div id="ibanHelp" class="form-text">Wpisz ciąg cyfr; spacje dodadzą się automatycznie dla
czytelności.</div>
<div id="ibanHelp" class="form-text">Wpisz ciąg cyfr; spacje dodadzą się automatycznie dla czytelności.</div>
</div>
<div class="col-12 col-md-6">
<label for="numer_telefonu_blik" class="form-label">Numer telefonu BLIK</label>
<div class="input-group">
<span class="input-group-text">+48</span>
<input type="tel" class="form-control" id="numer_telefonu_blik"
name="numer_telefonu_blik" inputmode="tel" pattern="[0-9 ]{9,13}"
placeholder="123 456 789" required aria-describedby="blikHelp"
value="{% if is_edit and zbiorka.numer_telefonu_blik %}{{ zbiorka.numer_telefonu_blik }}{% elif global_settings %}{{ global_settings.numer_telefonu_blik }}{% else %}{% endif %}">
<input
type="tel"
class="form-control"
id="numer_telefonu_blik"
name="numer_telefonu_blik"
inputmode="tel"
pattern="[0-9 ]{9,13}"
placeholder="123 456 789"
required
aria-describedby="blikHelp"
value="{% if zbiorka and zbiorka.numer_telefonu_blik %}{{ zbiorka.numer_telefonu_blik }}{% elif global_settings %}{{ global_settings.numer_telefonu_blik }}{% else %}{{ request.form.get('numer_telefonu_blik','') }}{% endif %}"
>
</div>
<div id="blikHelp" class="form-text">Dziewięć cyfr telefonu powiązanego z BLIK. Spacje
opcjonalne.</div>
<div id="blikHelp" class="form-text">Dziewięć cyfr telefonu powiązanego z BLIK. Spacje opcjonalne.</div>
</div>
{% if is_edit %}
<div class="col-12 col-md-12 d-flex align-items-end">
<button type="button" class="btn btn-sm btn-outline-light border" id="ustaw-globalne"
title="Wstaw wartości z ustawień globalnych" {% if global_settings %}
title="Wstaw wartości z ustawień globalnych"
{% if global_settings %}
data-iban="{{ global_settings.numer_konta }}"
data-blik="{{ global_settings.numer_telefonu_blik }}" {% endif %}>
data-blik="{{ global_settings.numer_telefonu_blik }}"
{% endif %}
>
Wstaw globalne ustawienia
</button>
</div>
@@ -244,8 +258,7 @@
<div id="celSyncBox" class="alert d-none py-2 px-3 mb-3" role="alert">
<div class="d-flex flex-wrap align-items-center justify-content-between gap-2">
<div id="celSyncMsg" class="small"></div>
<button type="button" id="btnApplyCelFromSum"
class="btn btn-sm btn-outline-light border d-none"></button>
<button type="button" id="btnApplyCelFromSum" class="btn btn-sm btn-outline-light border d-none"></button>
</div>
</div>
@@ -254,60 +267,75 @@
<label for="cel" class="form-label">Cel zbiórki</label>
<div class="input-group">
<span class="input-group-text">PLN</span>
<input type="number" class="form-control" id="cel" name="cel" step="0.01" min="0.01"
placeholder="0,00" required aria-describedby="celHelp"
value="{{ zbiorka.cel if is_edit else '' }}">
<input
type="text"
inputmode="decimal"
class="form-control"
id="cel"
name="cel"
placeholder="0,00"
required
aria-describedby="celHelp"
value="{% if zbiorka and zbiorka.cel is not none %}{{ zbiorka.cel }}{% else %}{{ request.form.get('cel','') }}{% endif %}"
>
</div>
<div id="celHelp" class="form-text">Minimalnie 0,01 PLN. Możesz to później edytować.</div>
<div id="celHelp" class="form-text">Minimalnie 0,01 PLN. Można później edytować.</div>
</div>
<div class="col-12 col-md-12 d-flex align-items-end">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="ukryj_kwote" name="ukryj_kwote" {%
if is_edit and zbiorka.ukryj_kwote %}checked{% endif %}>
<input
class="form-check-input"
type="checkbox"
id="ukryj_kwote"
name="ukryj_kwote"
{% if zbiorka %}{% if zbiorka.ukryj_kwote %}checked{% endif %}{% endif %}
>
<label class="form-check-label" for="ukryj_kwote">Ukryj kwoty (cel i stan)</label>
</div>
</div>
</div>
<div class="row g-3 mt-2">
<div class="col-12 col-md-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="pokaz_postep_finanse"
name="pokaz_postep_finanse" {% if is_edit and zbiorka.pokaz_postep_finanse or not
is_edit %}checked{% endif %}>
<input
class="form-check-input"
type="checkbox"
id="pokaz_postep_finanse"
name="pokaz_postep_finanse"
{% if zbiorka %}{% if zbiorka.pokaz_postep_finanse %}checked{% endif %}{% else %}checked{% endif %}
>
<label class="form-check-label" for="pokaz_postep_finanse">Pokaż postęp: Finanse</label>
</div>
</div>
<div class="col-12 col-md-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="pokaz_postep_pozycje"
name="pokaz_postep_pozycje" {% if is_edit and zbiorka.pokaz_postep_pozycje or not
is_edit %}checked{% endif %}>
<label class="form-check-label" for="pokaz_postep_pozycje">Pokaż postęp: Zakupy
(liczba)</label>
<input
class="form-check-input"
type="checkbox"
id="pokaz_postep_pozycje"
name="pokaz_postep_pozycje"
{% if zbiorka %}{% if zbiorka.pokaz_postep_pozycje %}checked{% endif %}{% else %}checked{% endif %}
>
<label class="form-check-label" for="pokaz_postep_pozycje">Pokaż postęp: Zakupy (liczba)</label>
</div>
</div>
<div class="col-12 col-md-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="pokaz_postep_kwotowo"
name="pokaz_postep_kwotowo" {% if is_edit and zbiorka.pokaz_postep_kwotowo or not
is_edit %}checked{% endif %}>
<label class="form-check-label" for="pokaz_postep_kwotowo">Pokaż postęp: Zakupy
(kwotowo)</label>
<input
class="form-check-input"
type="checkbox"
id="pokaz_postep_kwotowo"
name="pokaz_postep_kwotowo"
{% if zbiorka %}{% if zbiorka.pokaz_postep_kwotowo %}checked{% endif %}{% else %}checked{% endif %}
>
<label class="form-check-label" for="pokaz_postep_kwotowo">Pokaż postęp: Zakupy (kwotowo)</label>
</div>
</div>
</div>
</div>
<!-- CTA -->
<div class="d-flex flex-wrap gap-2">
<button type="submit" class="btn btn-success">
@@ -328,4 +356,4 @@
<script src="{{ url_for('static', filename='js/formularz_zbiorek.js') }}?v={{ APP_VERSION }}"></script>
<script src="{{ url_for('static', filename='js/produkty_formularz.js') }}?v={{ APP_VERSION }}"></script>
<script src="{{ url_for('static', filename='js/kwoty_formularz.js') }}?v={{ APP_VERSION }}"></script>
{% endblock %}
{% endblock %}