Manage optionnal fields

This commit is contained in:
William Bouzourène 2025-01-06 17:05:03 +01:00
parent dcc322c71d
commit d35b06e2a9
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
7 changed files with 518 additions and 0 deletions

68
views/field.html Normal file
View file

@ -0,0 +1,68 @@
{% extends "layouts/main.html" %}
{% block main %}
<div class="container mt-4">
<div class="mb-4">
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item"><a href="/admin">Administration</a></li>
<li class="breadcrumb-item"><a href="/admin/fields">Champs supplémentaires</a></li>
<li class="breadcrumb-item active">{{ Field.Name }}</li>
</ol>
</nav>
<hr>
</div>
<div class="mb-3">
<b>Nom du champ</b><br>
{{ Field.Name }}
</div>
<div class="mb-3">
<b>Population</b><br>
{% for Key, Value in PersonTypes %}
{% if Key == Field.PersonType %}
{{ Value }}
{% endif %}
{% endfor %}
</div>
<div class="mb-3">
<b>Type de champ</b><br>
{% for Key, Value in FieldTypes %}
{% if Key == Field.FieldType %}
{{ Value }}
{% endif %}
{% endfor %}
</div>
{% if Field.ListID %}
<div class="mb-3">
<b>Liste</b><br>
<a href="/admin/lists/{{ Field.List.ID }}">
{{ Field.List.Name }}
</a>
</div>
{% endif %}
<div class="mt-3">
<a class="btn btn-md btn-primary" href="/admin/fields/{{ Field.ID }}/edit">
<i class="bi-pencil-square"></i>
Modifier
</a>
<form
action="/admin/fields/{{ Field.ID }}/delete"
method="post"
class="d-inline p-0"
>
<button class="btn btn-md btn-danger areyousure" type="submit">
<i class="bi-trash3"></i>
Supprimer
</button>
</form>
</div>
</div>
{% endblock %}

130
views/field_form.html Normal file
View file

@ -0,0 +1,130 @@
{% extends "layouts/main.html" %}
{% block main %}
<div class="container mt-4">
<div class="mb-4">
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item"><a href="/admin">Administration</a></li>
<li class="breadcrumb-item"><a href="/admin/fields">Champs supplémentaires</a></li>
{% if Field.ID %}
<li class="breadcrumb-item">
<a href="/admin/fields/{{ Field.ID }}">{{ Field.Name }}</a>
</li>
<li class="breadcrumb-item active">Modifier</li>
{% else %}
<li class="breadcrumb-item active">Ajouter</li>
{% endif %}
</ol>
</nav>
<hr>
</div>
{% if Errors %}
<div class="alert alert-danger">
<ul class="m-0">
{% for Error in Errors %}
<li>{{ Error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<form id="field" method="post">
<div class="mb-3">
<label for="name" class="form-label">
Nom du champ
</label>
<input
id="name"
class="form-control"
type="text"
name="name"
required
value="{{ Field.Name }}"
>
</div>
{% if !Field.ID %}
<div class="mb-3">
<label for="person_type" class="form-label">
Population
</label>
<select
name="person_type"
id="person_type"
class="form-control"
required
>
{% for Key, Value in PersonTypes %}
<option value="{{ Key }}">{{ Value }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="field_type" class="form-label">
Type de champ
</label>
<select
name="field_type"
id="field_type"
class="form-control"
required
>
{% for Key, Value in FieldTypes %}
<option value="{{ Key }}">{{ Value }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="list" class="form-label">
Liste
</label>
<select
name="list"
id="list"
class="form-control"
required
>
{% for List in Lists %}
<option value="{{ List.ID }}">
{{ List.Name }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="mt-4">
<button class="btn btn-primary" type="submit">
<i class="me-1 bi-floppy"></i>
Enregistrer
</button>
</div>
</form>
</div>
{% endblock %}
{% block javascript %}
<script>
$(document).ready(function() {
$("#field_type").on("change", function() {
var enable = false;
if ($(this).val() == "list") {
enable = true;
}
$("#list").prop("disabled", !enable);
$("#list").prop("required", enable);
});
$("#field_type").trigger("change");
});
</script>
{% endblock %}

67
views/fields.html Normal file
View file

@ -0,0 +1,67 @@
{% extends "layouts/main.html" %}
{% block main %}
<div class="container mt-4">
<div class="mb-4">
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item"><a href="/admin">Administration</a></li>
<li class="breadcrumb-item active">Champs supplémentaires</li>
</ol>
</nav>
<hr>
</div>
{% if Fields %}
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Nom</th>
<th>Population</th>
<th>Type de champ</th>
</tr>
</thead>
<tbody>
{% for Field in Fields %}
<tr>
<td>
<a href="/admin/fields/{{ Field.ID }}">
{{ Field.Name }}
</a>
</td>
<td>
{% for Key, Value in PersonTypes %}
{% if Key == Field.PersonType %}
{{ Value }}
{% endif %}
{% endfor %}
</td>
<td>
{% for Key, Value in FieldTypes %}
{% if Key == Field.FieldType %}
{{ Value }}
{% endif %}
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="my-4">
Pas de champs pour le moment
</div>
{% endif %}
<div class="mt-3">
<a class="btn btn-md btn-primary" href="/admin/fields/add">
<i class="bi-plus-lg"></i>
Ajouter
</a>
</div>
</div>
{% endblock %}