Files
xamxam/app/templates/partials/form/jury-fieldset.php
Pontoporeia 77fd282e29 refactor: unify edit mode Format+Fichiers with add/partage HTMX fragment
- Edit mode now uses the same fichiers-fragment.php as add and partage,
  instead of duplicating the format checkboxes + new-file upload + website
  URL fieldsets.
- Edit-only elements (existing files list, cover replace) stay in
  a separate #edit-existing-files-block below the shared fragment.
- Removed .zip/.tar/.gz from the main TFE upload accept in both
  fichiers-fragment.php and fieldset-files.php. Archives go only
  in the Annexes file input.
- Removed admin/format-website-fragment.php dependency from edit
  (no longer needed — the shared fragment handles website too).

fix: jury repop crash + hx-preserve on file inputs, remove zip/tar from tfe accept

- Jury fieldset add-mode repopulation now handles both scalar (legacy)
  and array (new dynamic multi-row) values for jury_promoteur and
  jury_promoteur_ulb_name. htmlspecialchars() was choking on array value.
- All file inputs in fichiers-fragment.php wrapped in hx-preserve
  containers so HTMX swaps don't wipe user-selected files when toggling
  formats or the annexes checkbox.
- Removed .zip/.tar/.gz from main TFE file accept — archives only via
  annexes input (which already had multiple + correct accept).
- Edit mode now reuses the same fichiers-fragment.php fragment.

fix: file inputs re-initialize after HTMX swap via inline script

- Exposed window.XamxamInitFileUploads from file-upload-queue.js IIFE
  so HTMX fragments can trigger re-binding without a global listener.
- fichiers-fragment.php emits <script>XamxamInitFileUploads()</script>
  at the end of the #format-fichiers-block fragment.
- Removed hx-preserve wrappers — they prevented re-render after
  format/annexes toggles changed visible inputs.
- This also fixes .zip removal from TFE accept and jury repopulation
  array crash from the previous commit.

refactor: simplify file-upload-queue.js, remove file-preview.js

- file-upload-queue.js rewritten from ~250 lines to ~120 lines:
  no more DataTransfer machinery, no IIFE wrapper, uses .onchange
  instead of addEventListener for simpler HTMX re-init.
- window.XamxamInitFileUploads is the function itself (not an IIFE export).
- Merged file-preview.js functionality into file-upload-queue.js
  (single-file .data-preview handling). Deleted file-preview.js.
- fichiers-fragment.php inline script calls XamxamInitFileUploads()
  after every HTMX swap (same as before).

debug: add console.log to file-upload-queue.js for file input behavior

Adds logging at key points to diagnose why only one file is displayed:
- XamxamInitFileUploads called
- TFE queue picker init (id, multiple attribute state)
- onchange event (files count, names)
- fileArray post-concat length
- Single-file preview bindings (id, multiple attribute)

Remove after debug session.
2026-05-13 18:03:33 +02:00

270 lines
14 KiB
PHP

<?php
/**
* Jury composition fieldset partial.
*
* Variables consumed (all optional — defaults to empty/add-mode):
* $juryPromoteur string|null Promoteur interne name (single or primary)
* $juryPromoteurs array [{name: string}] Multiple promoteurs internes
* $juryPromoteurUlb string|null Promoteur ULB name (single or primary)
* $juryPromoteursUlb array [{name: string}] Multiple promoteurs ULB
* $lecteursInternes array [{name: string}]
* $lecteursExternes array [{name: string}]
* $juryPresident string|null President name (edit-only, optional)
* $showPresident bool Show president field (default: false)
* $showPromoteurUlb bool Show ULB promoteur field (default: true)
* $promoteurUlbConditional bool If true, field is hidden unless finality=Approfondi
*
* In add-mode repopulation: if old() exists and values are null, populate from it.
*/
$juryPromoteur = $juryPromoteur ?? null;
$juryPromoteurs = $juryPromoteurs ?? [];
$juryPromoteurUlb = $juryPromoteurUlb ?? null;
$juryPromoteursUlb = $juryPromoteursUlb ?? [];
$lecteursInternes = $lecteursInternes ?? [];
$lecteursExternes = $lecteursExternes ?? [];
$juryPresident = $juryPresident ?? null;
$showPresident = $showPresident ?? false;
$showPromoteurUlb = $showPromoteurUlb ?? true;
$promoteurUlbConditional = $promoteurUlbConditional ?? false;
$adminMode = $adminMode ?? false;
// Add-mode repopulation from flash data
$addMode = ($juryPromoteur === null && empty($juryPromoteurs) && $juryPromoteurUlb === null && empty($juryPromoteursUlb) && empty($lecteursInternes) && empty($lecteursExternes) && $juryPresident === null);
if ($addMode && function_exists('old')) {
// jury_promoteur may be array (new form) or scalar (legacy)
$promoteursOld = old('jury_promoteur');
if (is_array($promoteursOld)) {
foreach ($promoteursOld as $name) {
$name = trim($name ?? '');
if ($name !== '') $juryPromoteurs[] = ['name' => $name];
}
} elseif (is_string($promoteursOld) && trim($promoteursOld) !== '') {
$juryPromoteur = $promoteursOld;
}
// jury_promoteur_ulb_name may be array (new form) or scalar (legacy)
$promoteursUlbOld = old('jury_promoteur_ulb_name');
if (is_array($promoteursUlbOld)) {
foreach ($promoteursUlbOld as $name) {
$name = trim($name ?? '');
if ($name !== '') $juryPromoteursUlb[] = ['name' => $name];
}
} elseif (is_string($promoteursUlbOld) && trim($promoteursUlbOld) !== '') {
$juryPromoteurUlb = $promoteursUlbOld;
}
$juryPresident = old('jury_president') ?: null;
for ($i = 0; $i < 10; $i++) {
$n = old("jury_lecteur_interne:$i");
if ($n !== '') $lecteursInternes[] = ['name' => $n];
}
for ($i = 0; $i < 10; $i++) {
$n = old("jury_lecteur_externe:$i");
if ($n !== '') $lecteursExternes[] = ['name' => $n];
}
}
?>
<fieldset>
<legend>Composition du jury</legend>
<!-- Promoteur·ice(s) interne -->
<fieldset class="admin-jury-lecteurs">
<legend>Promoteur·ice(s) interne<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
<div id="jury-promoteur-interne-list" class="admin-jury-list">
<?php if (empty($juryPromoteurs) && $juryPromoteur === null): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
id="jury_promoteur" aria-label="Promoteur·ice interne 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php elseif (!empty($juryPromoteurs)): ?>
<?php foreach ($juryPromoteurs as $pi => $pm): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur[]"
value="<?= htmlspecialchars($pm['name']) ?>" placeholder="Nom"
<?= (!$adminMode && $pi === 0) ? 'required' : '' ?>
aria-label="Promoteur·ice interne <?= $pi + 1 ?> — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur[]"
value="<?= htmlspecialchars($juryPromoteur ?? '') ?>" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
aria-label="Promoteur·ice interne 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endif; ?>
</div>
<button type="button" class="btn btn--secondary admin-add-jury-btn"
onclick="addJuryRow('jury-promoteur-interne-list', 'jury_promoteur', 'Promoteur·ice interne')">
+ Ajouter un·e promoteur·ice interne
</button>
</fieldset>
<?php if ($showPromoteurUlb): ?>
<!-- Promoteur·ice(s) ULB -->
<fieldset class="admin-jury-lecteurs" id="jury-promoteur-ulb-row"<?= $promoteurUlbConditional ? ' style="display:none"' : '' ?>>
<legend>Promoteur·ice(s) ULB<span id="jury-ulb-asterisk" style="display:none"> <span class="asterisk">*</span></span></legend>
<div id="jury-promoteur-ulb-list" class="admin-jury-list">
<?php if (empty($juryPromoteursUlb) && $juryPromoteurUlb === null): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur_ulb_name[]" placeholder="Nom"
aria-label="Promoteur·ice ULB 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php elseif (!empty($juryPromoteursUlb)): ?>
<?php foreach ($juryPromoteursUlb as $pi => $pm): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur_ulb_name[]"
value="<?= htmlspecialchars($pm['name']) ?>" placeholder="Nom"
aria-label="Promoteur·ice ULB <?= $pi + 1 ?> — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="admin-jury-entry">
<input type="text" name="jury_promoteur_ulb_name[]"
value="<?= htmlspecialchars($juryPromoteurUlb ?? '') ?>" placeholder="Nom"
aria-label="Promoteur·ice ULB 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endif; ?>
</div>
<button type="button" class="btn btn--secondary admin-add-jury-btn"
onclick="addJuryRow('jury-promoteur-ulb-list', 'jury_promoteur_ulb_name', 'Promoteur·ice ULB')">
+ Ajouter un·e promoteur·ice ULB
</button>
</fieldset>
<?php if ($promoteurUlbConditional): ?>
<script>
(function() {
var finalitySelect = document.querySelector('select[name="finality"]');
var ulbRow = document.getElementById('jury-promoteur-ulb-row');
var ulbInput = ulbRow ? ulbRow.querySelector('input') : null;
var ulbAsterisk = document.getElementById('jury-ulb-asterisk');
function isApprofondiSelected() {
if (!finalitySelect) return false;
var selected = finalitySelect.options[finalitySelect.selectedIndex];
var text = (selected && selected.text) ? selected.text.toLowerCase() : '';
return text.includes('approfondi');
}
function toggleUlb() {
if (!ulbRow) return;
var show = isApprofondiSelected();
ulbRow.style.display = show ? '' : 'none';
if (ulbAsterisk) ulbAsterisk.style.display = show ? '' : 'none';
// Mark first ULB input required when finality is Approfondi
if (ulbRow) {
var inputs = ulbRow.querySelectorAll('input[name="jury_promoteur_ulb_name[]"]');
inputs.forEach(function(inp, idx) {
inp.required = <?= $adminMode ? 'false' : 'show && idx === 0' ?>;
inp.disabled = !show;
if (!show) inp.value = '';
});
}
}
if (finalitySelect) {
finalitySelect.addEventListener('change', toggleUlb);
toggleUlb();
}
})();
</script>
<?php endif; ?>
<?php endif; ?>
<!-- Lecteur·ice(s) interne -->
<fieldset class="admin-jury-lecteurs">
<legend>Lecteur·ice(s) interne<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
<div id="jury-lecteurs-internes-list" class="admin-jury-list">
<?php if (empty($lecteursInternes)): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_lecteur_interne[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
aria-label="Lecteur·ice interne 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php else: ?>
<?php foreach ($lecteursInternes as $li => $lm): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_lecteur_interne[]"
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom"
<?= (!$adminMode && $li === 0) ? 'required' : '' ?>
aria-label="Lecteur·ice interne <?= $li + 1 ?> — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<button type="button" class="btn btn--secondary admin-add-jury-btn"
onclick="addJuryRow('jury-lecteurs-internes-list', 'jury_lecteur_interne[]', 'Lecteur·ice interne')">
+ Ajouter un·e lecteur·ice interne
</button>
</fieldset>
<!-- Lecteur·ice(s) externe -->
<fieldset class="admin-jury-lecteurs">
<legend>Lecteur·ice(s) externe<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
<div id="jury-lecteurs-externes-list" class="admin-jury-list">
<?php if (empty($lecteursExternes)): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_lecteur_externe[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
aria-label="Lecteur·ice externe 1 — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php else: ?>
<?php foreach ($lecteursExternes as $li => $lm): ?>
<div class="admin-jury-entry">
<input type="text" name="jury_lecteur_externe[]"
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom"
<?= (!$adminMode && $li === 0) ? 'required' : '' ?>
aria-label="Lecteur·ice externe <?= $li + 1 ?> — nom">
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<button type="button" class="btn btn--secondary admin-add-jury-btn"
onclick="addJuryRow('jury-lecteurs-externes-list', 'jury_lecteur_externe[]', 'Lecteur·ice externe')">
+ Ajouter un·e lecteur·ice externe
</button>
</fieldset>
<?php if ($showPresident): ?>
<!-- Président·e (admin edit only) -->
<div>
<label for="jury_president">Président·e :</label>
<input type="text" id="jury_president" name="jury_president"
value="<?= htmlspecialchars($juryPresident ?? '') ?>"
placeholder="Nom du/de la président·e (interne)">
</div>
<?php endif; ?>
</fieldset>
<script>
function addJuryRow(listId, inputName, roleLabel) {
var list = document.getElementById(listId);
if (!list) return;
var n = list.querySelectorAll('.admin-jury-entry').length + 1;
var div = document.createElement('div');
div.className = 'admin-jury-entry';
div.innerHTML = '<input type="text" name="' + inputName + '" placeholder="Nom"'
+ ' aria-label="' + roleLabel + ' ' + n + ' \u2014 nom">'
+ '<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"'
+ ' onclick="removeJuryRow(this)" aria-label="Supprimer">'
+ '<span aria-hidden="true">\u2715</span></button>';
list.appendChild(div);
}
function removeJuryRow(btn) {
btn.closest('.admin-jury-entry').remove();
}
</script>