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