mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
Extract jury-fieldset.php partial; deduplicate jury section from add.php and edit.php
The jury composition fieldset (président·e, promoteur·ice + external checkbox, dynamic
lecteur·ices list with JS add/remove) was copy-pasted verbatim between the two longest
admin forms.
- Created templates/partials/form/jury-fieldset.php
- Consumes $juryPresident, $juryPromoteur, $juryPromoteurExt, $juryLecteurs[]
- Handles both add-mode (falls back to old()/wasSelected() flash helpers) and
edit-mode (pre-populates from DB-loaded variables)
- $juryIdx initialised from max(count($juryLecteurs), 1) — correct for both modes
- add.php: 311 → 251 lines (-60); entire fieldset + <script> replaced with one require
- edit.php: 359 → 289 lines (-70); PHP variable extraction kept inline before require
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -40,7 +40,7 @@ PHP has no component system, but `include`/`require` with variable scoping works
|
|||||||
- [ ] **`select-field.php`** — accepts `$name`, `$label`, `$options[]`, `$selected`, `$required`; renders `<div>…<label>…<select>…</div>` pattern used ~6 times
|
- [ ] **`select-field.php`** — accepts `$name`, `$label`, `$options[]`, `$selected`, `$required`; renders `<div>…<label>…<select>…</div>` pattern used ~6 times
|
||||||
- [ ] **`checkbox-list.php`** — accepts `$name`, `$label`, `$options[]`, `$checked[]`; renders the checkbox group pattern (languages, formats) used ~4 times across `add.php` and `edit.php`
|
- [ ] **`checkbox-list.php`** — accepts `$name`, `$label`, `$options[]`, `$checked[]`; renders the checkbox group pattern (languages, formats) used ~4 times across `add.php` and `edit.php`
|
||||||
- [ ] **`file-field.php`** — accepts `$name`, `$label`, `$accept`, `$hint`, `$multiple`; renders file input pattern used 3 times
|
- [ ] **`file-field.php`** — accepts `$name`, `$label`, `$accept`, `$hint`, `$multiple`; renders file input pattern used 3 times
|
||||||
- [ ] **`jury-fieldset.php`** — the entire jury composition fieldset + JS is duplicated verbatim between `add.php` and `edit.php`; extract into one partial accepting `$juryPresident`, `$juryPromoteur`, `$juryPromoteurExt`, `$juryLecteurs[]`
|
- [x] **`jury-fieldset.php`** — the entire jury composition fieldset + JS is duplicated verbatim between `add.php` and `edit.php`; extract into one partial accepting `$juryPresident`, `$juryPromoteur`, `$juryPromoteurExt`, `$juryLecteurs[]`
|
||||||
|
|
||||||
### Shared UI partials — `templates/partials/`
|
### Shared UI partials — `templates/partials/`
|
||||||
- [x] **`pagination.php`** — pagination nav is duplicated between `index.php` and `search.php` with minor variations; unify into one partial accepting `$page`, `$totalPages`, `$baseParams[]`
|
- [x] **`pagination.php`** — pagination nav is duplicated between `index.php` and `search.php` with minor variations; unify into one partial accepting `$page`, `$totalPages`, `$baseParams[]`
|
||||||
|
|||||||
@@ -80,67 +80,7 @@ function wasSelected($key, $value) {
|
|||||||
value="<?= old('mail') ?>">
|
value="<?= old('mail') ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Composition du jury -->
|
<?php require APP_ROOT . '/templates/partials/form/jury-fieldset.php'; ?>
|
||||||
<fieldset>
|
|
||||||
<legend>Composition du jury</legend>
|
|
||||||
|
|
||||||
<!-- Président·e -->
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label" for="jury_president">Président·e :</label>
|
|
||||||
<input class="admin-input" type="text" id="jury_president" name="jury_president"
|
|
||||||
value="<?= old('jury_president') ?>"
|
|
||||||
placeholder="Nom du/de la président·e (interne)">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Promoteur·ice -->
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label" for="jury_promoteur">Promoteur·ice :</label>
|
|
||||||
<div class="admin-jury-row">
|
|
||||||
<input class="admin-input" type="text" id="jury_promoteur" name="jury_promoteur"
|
|
||||||
value="<?= old('jury_promoteur') ?>" placeholder="Nom">
|
|
||||||
<label class="admin-checkbox-label admin-jury-ext">
|
|
||||||
<input type="checkbox" name="jury_promoteur_ext" value="1"
|
|
||||||
<?= wasSelected('jury_promoteur_ext', '1') ? 'checked' : '' ?>>
|
|
||||||
Externe
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Lecteur·ices (dynamic) -->
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label">Lecteur·ices :</label>
|
|
||||||
<div id="jury-lecteurs-list" class="admin-jury-list">
|
|
||||||
<!-- rows injected by JS; start with one empty row -->
|
|
||||||
<div class="admin-jury-entry">
|
|
||||||
<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">
|
|
||||||
<label class="admin-checkbox-label admin-jury-ext">
|
|
||||||
<input type="checkbox" name="jury_lecteurs_ext[0]" value="1"> Externe
|
|
||||||
</label>
|
|
||||||
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button type="button" class="admin-btn-secondary admin-add-jury-btn"
|
|
||||||
onclick="addJuryRow()">+ Ajouter un·e lecteur·ice</button>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<script>
|
|
||||||
var juryIdx = 1;
|
|
||||||
function addJuryRow() {
|
|
||||||
var list = document.getElementById('jury-lecteurs-list');
|
|
||||||
var div = document.createElement('div');
|
|
||||||
div.className = 'admin-jury-entry';
|
|
||||||
div.innerHTML = '<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">'
|
|
||||||
+ '<label class="admin-checkbox-label admin-jury-ext">'
|
|
||||||
+ '<input type="checkbox" name="jury_lecteurs_ext[' + juryIdx + ']" value="1"> Externe'
|
|
||||||
+ '</label>'
|
|
||||||
+ '<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>';
|
|
||||||
list.appendChild(div);
|
|
||||||
juryIdx++;
|
|
||||||
}
|
|
||||||
function removeJuryRow(btn) {
|
|
||||||
btn.closest('.admin-jury-entry').remove();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Année -->
|
<!-- Année -->
|
||||||
<div class="admin-form-row">
|
<div class="admin-form-row">
|
||||||
|
|||||||
@@ -148,77 +148,7 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<fieldset>
|
<?php require APP_ROOT . '/templates/partials/form/jury-fieldset.php'; ?>
|
||||||
<legend>Composition du jury</legend>
|
|
||||||
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label" for="jury_president">Président·e :</label>
|
|
||||||
<input class="admin-input" type="text" id="jury_president" name="jury_president"
|
|
||||||
value="<?= htmlspecialchars($juryPresident ?? '') ?>"
|
|
||||||
placeholder="Nom (interne)">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label" for="jury_promoteur">Promoteur·ice :</label>
|
|
||||||
<div class="admin-jury-row">
|
|
||||||
<input class="admin-input" type="text" id="jury_promoteur" name="jury_promoteur"
|
|
||||||
value="<?= htmlspecialchars($juryPromoteur ?? '') ?>" placeholder="Nom">
|
|
||||||
<label class="admin-checkbox-label admin-jury-ext">
|
|
||||||
<input type="checkbox" name="jury_promoteur_ext" value="1"
|
|
||||||
<?= $juryPromoteurExt ? 'checked' : '' ?>> Externe
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="admin-form-row">
|
|
||||||
<label class="admin-label">Lecteur·ices :</label>
|
|
||||||
<div>
|
|
||||||
<div id="jury-lecteurs-list" class="admin-jury-list">
|
|
||||||
<?php if (empty($juryLecteurs)): ?>
|
|
||||||
<div class="admin-jury-entry">
|
|
||||||
<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">
|
|
||||||
<label class="admin-checkbox-label admin-jury-ext">
|
|
||||||
<input type="checkbox" name="jury_lecteurs_ext[0]" value="1"> Externe
|
|
||||||
</label>
|
|
||||||
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>
|
|
||||||
</div>
|
|
||||||
<?php else: ?>
|
|
||||||
<?php foreach ($juryLecteurs as $li => $lm): ?>
|
|
||||||
<div class="admin-jury-entry">
|
|
||||||
<input class="admin-input" type="text" name="jury_lecteurs[]"
|
|
||||||
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom">
|
|
||||||
<label class="admin-checkbox-label admin-jury-ext">
|
|
||||||
<input type="checkbox" name="jury_lecteurs_ext[<?= $li ?>]" value="1"
|
|
||||||
<?= $lm['is_external'] ? 'checked' : '' ?>> Externe
|
|
||||||
</label>
|
|
||||||
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
<button type="button" class="admin-btn-secondary admin-add-jury-btn"
|
|
||||||
onclick="addJuryRow()">+ Ajouter un·e lecteur·ice</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<script>
|
|
||||||
var juryIdx = <?= max(count($juryLecteurs), 1) ?>;
|
|
||||||
function addJuryRow() {
|
|
||||||
var list = document.getElementById('jury-lecteurs-list');
|
|
||||||
var div = document.createElement('div');
|
|
||||||
div.className = 'admin-jury-entry';
|
|
||||||
div.innerHTML = '<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">'
|
|
||||||
+ '<label class="admin-checkbox-label admin-jury-ext">'
|
|
||||||
+ '<input type="checkbox" name="jury_lecteurs_ext[' + juryIdx + ']" value="1"> Externe'
|
|
||||||
+ '</label>'
|
|
||||||
+ '<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>';
|
|
||||||
list.appendChild(div);
|
|
||||||
juryIdx++;
|
|
||||||
}
|
|
||||||
function removeJuryRow(btn) {
|
|
||||||
btn.closest('.admin-jury-entry').remove();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="admin-form-row">
|
<div class="admin-form-row">
|
||||||
<label class="admin-label" for="access_type_id">Visibilité / Accès :</label>
|
<label class="admin-label" for="access_type_id">Visibilité / Accès :</label>
|
||||||
|
|||||||
107
templates/partials/form/jury-fieldset.php
Normal file
107
templates/partials/form/jury-fieldset.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Jury composition fieldset partial.
|
||||||
|
*
|
||||||
|
* Variables consumed (all optional — defaults to empty/add-mode):
|
||||||
|
* $juryPresident string|null President name
|
||||||
|
* $juryPromoteur string|null Promoteur name
|
||||||
|
* $juryPromoteurExt int 1 if promoteur is external, 0 otherwise
|
||||||
|
* $juryLecteurs array Each element: ['name' => string, 'is_external' => int]
|
||||||
|
*
|
||||||
|
* In "add" mode (no existing jury data), callers should pass nulls/empty arrays and
|
||||||
|
* may rely on the $formData repopulation helpers (old/wasSelected) defined in add.php.
|
||||||
|
* When those helpers exist and no explicit values are set, the partial uses them.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$juryPresident = $juryPresident ?? null;
|
||||||
|
$juryPromoteur = $juryPromoteur ?? null;
|
||||||
|
$juryPromoteurExt = $juryPromoteurExt ?? 0;
|
||||||
|
$juryLecteurs = $juryLecteurs ?? [];
|
||||||
|
|
||||||
|
// In add-mode, repopulate from flash form data when helpers are available.
|
||||||
|
$addMode = ($juryPresident === null && $juryPromoteur === null && empty($juryLecteurs));
|
||||||
|
if ($addMode && function_exists('old')) {
|
||||||
|
$juryPresident = old('jury_president') ?: null;
|
||||||
|
$juryPromoteur = old('jury_promoteur') ?: null;
|
||||||
|
$juryPromoteurExt = function_exists('wasSelected') && wasSelected('jury_promoteur_ext', '1') ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$juryIdx = max(count($juryLecteurs), 1);
|
||||||
|
?>
|
||||||
|
<!-- Composition du jury -->
|
||||||
|
<fieldset>
|
||||||
|
<legend>Composition du jury</legend>
|
||||||
|
|
||||||
|
<!-- Président·e -->
|
||||||
|
<div class="admin-form-row">
|
||||||
|
<label class="admin-label" for="jury_president">Président·e :</label>
|
||||||
|
<input class="admin-input" type="text" id="jury_president" name="jury_president"
|
||||||
|
value="<?= htmlspecialchars($juryPresident ?? '') ?>"
|
||||||
|
placeholder="Nom du/de la président·e (interne)">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Promoteur·ice -->
|
||||||
|
<div class="admin-form-row">
|
||||||
|
<label class="admin-label" for="jury_promoteur">Promoteur·ice :</label>
|
||||||
|
<div class="admin-jury-row">
|
||||||
|
<input class="admin-input" type="text" id="jury_promoteur" name="jury_promoteur"
|
||||||
|
value="<?= htmlspecialchars($juryPromoteur ?? '') ?>" placeholder="Nom">
|
||||||
|
<label class="admin-checkbox-label admin-jury-ext">
|
||||||
|
<input type="checkbox" name="jury_promoteur_ext" value="1"
|
||||||
|
<?= $juryPromoteurExt ? 'checked' : '' ?>> Externe
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Lecteur·ices (dynamic list) -->
|
||||||
|
<div class="admin-form-row">
|
||||||
|
<label class="admin-label">Lecteur·ices :</label>
|
||||||
|
<div>
|
||||||
|
<div id="jury-lecteurs-list" class="admin-jury-list">
|
||||||
|
<?php if (empty($juryLecteurs)): ?>
|
||||||
|
<div class="admin-jury-entry">
|
||||||
|
<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">
|
||||||
|
<label class="admin-checkbox-label admin-jury-ext">
|
||||||
|
<input type="checkbox" name="jury_lecteurs_ext[0]" value="1"> Externe
|
||||||
|
</label>
|
||||||
|
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)"
|
||||||
|
aria-label="Supprimer ce lecteur">✕</button>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($juryLecteurs as $li => $lm): ?>
|
||||||
|
<div class="admin-jury-entry">
|
||||||
|
<input class="admin-input" type="text" name="jury_lecteurs[]"
|
||||||
|
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom">
|
||||||
|
<label class="admin-checkbox-label admin-jury-ext">
|
||||||
|
<input type="checkbox" name="jury_lecteurs_ext[<?= $li ?>]" value="1"
|
||||||
|
<?= $lm['is_external'] ? 'checked' : '' ?>> Externe
|
||||||
|
</label>
|
||||||
|
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)"
|
||||||
|
aria-label="Supprimer ce lecteur">✕</button>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="admin-btn-secondary admin-add-jury-btn"
|
||||||
|
onclick="addJuryRow()">+ Ajouter un·e lecteur·ice</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<script>
|
||||||
|
var juryIdx = <?= $juryIdx ?>;
|
||||||
|
function addJuryRow() {
|
||||||
|
var list = document.getElementById('jury-lecteurs-list');
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.className = 'admin-jury-entry';
|
||||||
|
div.innerHTML = '<input class="admin-input" type="text" name="jury_lecteurs[]" placeholder="Nom">'
|
||||||
|
+ '<label class="admin-checkbox-label admin-jury-ext">'
|
||||||
|
+ '<input type="checkbox" name="jury_lecteurs_ext[' + juryIdx + ']" value="1"> Externe'
|
||||||
|
+ '</label>'
|
||||||
|
+ '<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer ce lecteur">✕</button>';
|
||||||
|
list.appendChild(div);
|
||||||
|
juryIdx++;
|
||||||
|
}
|
||||||
|
function removeJuryRow(btn) {
|
||||||
|
btn.closest('.admin-jury-entry').remove();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user