feat: convert all file inputs to FilePond for standardized uploading

- Add csv_import queue type (storeAsFile, no async upload) for CSV import dialog
- Convert file-field.php partial to FilePond with field-name→queue-type mapping
- Conditionally skip server config for storeAsFile queues in buildFilePondOptions
- Skip FilePond init for inputs inside closed <dialog> elements
- Trigger FilePond init when import dialog opens
- Load FilePond CSS/JS assets on admin index page
This commit is contained in:
Pontoporeia
2026-06-08 10:28:39 +02:00
parent fad38f4e0d
commit df70fba5d4
8 changed files with 1089 additions and 41 deletions

View File

@@ -46,7 +46,7 @@ document.addEventListener('htmx:afterSwap',()=>{document.querySelectorAll('input
</button>
<?php endif; ?>
<button type="button" class="btn btn--primary btn--sm" id="import-dialog-btn"
onclick="document.getElementById('import-dialog').showModal()">
onclick="document.getElementById('import-dialog').showModal(); window.XamxamInitFilePonds()">
Importer
</button>
</div>
@@ -214,7 +214,11 @@ document.addEventListener('htmx:afterSwap',()=>{document.querySelectorAll('input
<div>
<label for="csv_file">Fichier CSV</label>
<div class="admin-file-input">
<input type="file" id="csv_file" name="csv_file" accept=".csv" required>
<input type="file" id="csv_file"
name="csv_file"
class="tfe-file-picker"
data-queue-type="csv_import"
required>
<small class="admin-file-hint">
Colonnes : Identifiant, Titre, Sous-titre, Auteur·ice(s), Contact, Promoteur·ice(s), Format, Année, AP, Orientation, Finalité, Mots-clés, Synopsis, Contexte, Remarques, Langue, Autorisation, License, taille, Points sur 20, lien BAIU<br>
Quatre premières lignes ignorées — Séparateur : virgule — UTF-8

View File

@@ -1,16 +1,16 @@
<?php
/**
* File input partial.
* File input partial — FilePond-powered.
*
* Variables consumed:
* string $name — input name attribute (used for id too unless $id set)
* string $label — visible label text
* string $accept — MIME types / extensions for the accept attribute (e.g. 'image/jpeg,image/png')
* string $accept — MIME types / extensions (informational; FilePond validates via queue config)
* string|null $hint — optional hint shown in <small> below the input
* bool $required — whether the field is required; default false
* bool $multiple — whether to allow multiple file selection; default false
* string|null $id — override the id attribute (defaults to $name)
* string|null $fieldName — validation field name for HTMX inline validation ('couverture', 'note_intention', 'tfe', 'annexes')
* string|null $fieldName — mapped to FilePond queue-type: 'couverture'→cover, 'note_intention'→note_intention, 'annexes'→annexe
*/
$accept = $accept ?? '';
@@ -19,41 +19,29 @@ $hintRaw = $hintRaw ?? false; // when true, $hint is emitted as raw HTML
$required = $required ?? false;
$multiple = $multiple ?? false;
$id = $id ?? $name;
$fieldName = $fieldName ?? $name; // validation field name
$previewId = 'fp-' . htmlspecialchars($id);
$fieldName = $fieldName ?? $name;
// Determine HTMX POST endpoint for inline file validation
if (defined('ADMIN_MODE') && ADMIN_MODE) {
$validateUrl = '/admin/fragments/validate-file.php';
} else {
$validateUrl = '/partage/fragments/validate-file.php';
}
// Map legacy field names to FilePond queue types
$queueTypeMap = [
'couverture' => 'cover',
'note_intention' => 'note_intention',
'annexes' => 'annexe',
];
$queueType = $queueTypeMap[$fieldName] ?? null;
?>
<div>
<div class="admin-form-group">
<label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?><?= $required ? ' <span class="asterisk">*</span>' : '' ?></label>
<!-- HTMX validation: scoped to this field -->
<form class="admin-file-input file-validation-form"
hx-post="<?= htmlspecialchars($validateUrl) ?>"
hx-encoding="multipart/form-data"
hx-trigger="change from:input[type='file']"
hx-target="find .file-validation-msg"
hx-swap="innerHTML"
hx-sync="replace">
<input type="hidden" name="field_name" value="<?= htmlspecialchars($fieldName) ?>">
<input type="hidden" name="admin_mode" value="<?= ($adminMode ?? false) ? '1' : '0' ?>">
<div class="admin-file-input">
<input type="file"
id="<?= htmlspecialchars($id) ?>"
name="<?= htmlspecialchars($name) ?><?= $multiple ? '[]' : '' ?>"
<?= $accept ? 'accept="' . htmlspecialchars($accept) . '"' : '' ?>
<?= $multiple ? 'multiple' : '' ?>
<?= $required ? 'required' : '' ?>
data-preview="<?= $previewId ?>">
<div class="file-validation-msg" aria-live="polite"></div>
<div id="<?= $previewId ?>" class="file-preview-list" aria-live="polite"></div>
name="queue_file[<?= htmlspecialchars($queueType ?? $fieldName) ?>][]"
class="tfe-file-picker"
data-queue-type="<?= htmlspecialchars($queueType ?? 'annexe') ?>"
<?= $required ? 'required' : '' ?>>
<?php if ($hint): ?>
<small><?= $hintRaw ? $hint : htmlspecialchars($hint) ?></small>
<?php endif; ?>
</form>
</div>
</div>
<?php
unset($accept, $hint, $hintRaw, $required, $multiple, $id, $fieldName, $previewId, $validateUrl);
unset($accept, $hint, $hintRaw, $required, $multiple, $id, $fieldName, $queueType, $queueTypeMap);