mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
feat: add FilePond pools for couverture, note_intention, video, audio; refactor queue config
This commit is contained in:
@@ -15,24 +15,38 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// ── Constants (mirrors file-upload-queue.js ALLOWED_BY_TYPE) ──────────
|
||||
// ── Per-queue-type configuration ────────────────────────────────────
|
||||
|
||||
var ALLOWED_BY_TYPE = {
|
||||
var QUEUE_CONFIG = {
|
||||
tfe: {
|
||||
exts: ["jpg","jpeg","png","gif","webp","pdf","mp4","webm","ogv","mov","mp3","ogg","oga","wav","flac","aac","m4a","vtt","zip","tar","gz","tgz"],
|
||||
maxSize: function (f) { return (/\.pdf$/i.test(f.name) ? 100 : 500) * 1024 * 1024; },
|
||||
multiple: true,
|
||||
},
|
||||
video: {
|
||||
exts: ["mp4","webm","ogv","mov"],
|
||||
maxSize: function () { return 500 * 1024 * 1024; },
|
||||
multiple: true,
|
||||
},
|
||||
audio: {
|
||||
exts: ["mp3","ogg","oga","wav","flac","aac","m4a"],
|
||||
maxSize: function () { return 500 * 1024 * 1024; },
|
||||
multiple: true,
|
||||
},
|
||||
annexe: {
|
||||
exts: ["pdf","zip","tar","gz","tgz"],
|
||||
maxSize: function () { return 500 * 1024 * 1024; },
|
||||
multiple: true,
|
||||
},
|
||||
cover: {
|
||||
exts: ["jpg","jpeg","png","webp"],
|
||||
maxSize: function () { return 20 * 1024 * 1024; },
|
||||
multiple: false,
|
||||
},
|
||||
note_intention: {
|
||||
exts: ["pdf"],
|
||||
maxSize: function () { return 100 * 1024 * 1024; },
|
||||
multiple: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -43,6 +57,8 @@
|
||||
"video-files-input": "video",
|
||||
"audio-files-input": "audio",
|
||||
"annexe-files-input": "annexe",
|
||||
"couverture": "cover",
|
||||
"note_intention": "note_intention",
|
||||
};
|
||||
|
||||
function ext(fn) {
|
||||
@@ -53,10 +69,9 @@
|
||||
// ── FilePond configuration per queue type ─────────────────────────────
|
||||
|
||||
function buildFilePondOptions(queueType, input) {
|
||||
var rules = ALLOWED_BY_TYPE[queueType];
|
||||
if (!rules) return null;
|
||||
var cfg = QUEUE_CONFIG[queueType];
|
||||
if (!cfg) return null;
|
||||
|
||||
// Build acceptedFileTypes from extensions
|
||||
var mimeMap = {
|
||||
jpg: "image/jpeg", jpeg: "image/jpeg", png: "image/png",
|
||||
gif: "image/gif", webp: "image/webp",
|
||||
@@ -67,29 +82,20 @@
|
||||
vtt: "text/vtt",
|
||||
zip: "application/zip", tar: "application/x-tar", gz: "application/gzip", tgz: "application/gzip",
|
||||
};
|
||||
var accepted = rules.exts.map(function(e) { return mimeMap[e] || ("." + e); });
|
||||
var accepted = cfg.exts.map(function(e) { return mimeMap[e] || ("." + e); });
|
||||
|
||||
return {
|
||||
allowMultiple: (queueType !== "video" && queueType !== "audio"),
|
||||
allowMultiple: cfg.multiple,
|
||||
allowReorder: true,
|
||||
storeAsFile: true,
|
||||
labelIdle: "Glissez-déposez vos fichiers ou <span class='filepond--label-action'>Parcourir</span>",
|
||||
acceptedFileTypes: accepted,
|
||||
labelFileTypeNotAllowed: "Type de fichier non accepté",
|
||||
fileValidateTypeLabelExpectedTypes: "Types acceptés : " + rules.exts.map(function(e) { return "." + e; }).join(", "),
|
||||
fileValidateSizeLabelMaxFileSize: function (fileSize) {
|
||||
var max = rules.maxSize({name: "", size: 0});
|
||||
return "Taille maximale : " + Math.round(max / 1024 / 1024) + " MB";
|
||||
},
|
||||
maxFileSize: function () {
|
||||
// We can't do per-file max based on extension easily with FilePond.
|
||||
// Use the larger limit and validate PDFs as a special case in the
|
||||
// beforeAddFile callback.
|
||||
return "500MB";
|
||||
},
|
||||
fileValidateTypeLabelExpectedTypes: "Types acceptés : " + cfg.exts.map(function(e) { return "." + e; }).join(", "),
|
||||
maxFileSize: function () { return "500MB"; },
|
||||
beforeAddFile: function (item) {
|
||||
var f = item.file;
|
||||
var max = rules.maxSize(f);
|
||||
var max = cfg.maxSize(f);
|
||||
if (f.size > max) {
|
||||
var maxMb = Math.round(max / 1024 / 1024);
|
||||
return {
|
||||
@@ -123,9 +129,8 @@
|
||||
var id = input.id;
|
||||
var queueType = INPUT_ID_TO_TYPE[id];
|
||||
if (!queueType) {
|
||||
// Try to infer from data attr on the container
|
||||
var container = input.closest("[data-queue-type]");
|
||||
if (container) queueType = container.dataset.queueType;
|
||||
// Try data-queue-type on the input itself
|
||||
queueType = input.dataset.queueType || null;
|
||||
}
|
||||
if (!queueType) return;
|
||||
|
||||
|
||||
@@ -197,36 +197,35 @@ $hasAnnexesChecked = !empty($_POST['has_annexes']);
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- ── 1. Couverture (always) ── -->
|
||||
<div>
|
||||
<!-- ── 1. Couverture (always, FilePond single-file) ── -->
|
||||
<?php
|
||||
$_cover = $_POST['_cover'] ?? null;
|
||||
// Only show upload field in add mode or when no existing cover
|
||||
if (!$editMode || !$_cover):
|
||||
$name = 'couverture';
|
||||
$label = 'Image de couverture (optionnel)';
|
||||
$accept = 'image/jpeg,image/png,image/webp';
|
||||
$hint = 'JPG, PNG ou WEBP. Format 4:3 recommandé. Max 20 MB.';
|
||||
$required = false;
|
||||
$id = 'couverture';
|
||||
include APP_ROOT . '/templates/partials/form/file-field.php';
|
||||
endif;
|
||||
unset($_cover);
|
||||
?>
|
||||
if (!$editMode || !$_cover): ?>
|
||||
<div class="admin-form-group">
|
||||
<label for="couverture">Image de couverture (optionnel)</label>
|
||||
<div class="admin-file-input">
|
||||
<input type="file" id="couverture"
|
||||
name="couverture"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
class="tfe-file-picker tfe-file-picker--single"
|
||||
data-queue-type="cover">
|
||||
<small>JPG, PNG ou WEBP. Format 4:3 recommandé. Max 20 MB.</small>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; unset($_cover); ?>
|
||||
|
||||
<!-- ── 2. Note d'intention (always) ── -->
|
||||
<div>
|
||||
<?php
|
||||
$name = 'note_intention';
|
||||
$label = 'Note d\'intention';
|
||||
$accept = '.pdf';
|
||||
$hint = 'PDF uniquement. Max 100 MB. Si votre fichier est trop lourd, compressez-le avec <a href="https://www.bentopdf.com" target="_blank" rel="noopener">bentopdf.com</a>.';
|
||||
$hintRaw = true;
|
||||
$required = !$adminMode;
|
||||
$id = 'note_intention';
|
||||
include APP_ROOT . '/templates/partials/form/file-field.php';
|
||||
?>
|
||||
<!-- ── 2. Note d'intention (always, FilePond single-file) ── -->
|
||||
<div class="admin-form-group">
|
||||
<label for="note_intention">Note d'intention<?= !$adminMode ? ' <span class="asterisk">*</span>' : '' ?></label>
|
||||
<div class="admin-file-input">
|
||||
<input type="file" id="note_intention"
|
||||
name="note_intention"
|
||||
accept=".pdf"
|
||||
class="tfe-file-picker tfe-file-picker--single"
|
||||
data-queue-type="note_intention"
|
||||
<?= !$adminMode ? 'required' : '' ?>>
|
||||
<small>PDF uniquement. Max 100 MB. Si votre fichier est trop lourd, compressez-le avec <a href="https://www.bentopdf.com" target="_blank" rel="noopener">bentopdf.com</a>.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── 3. TFE — multi-file upload (FilePond) ── -->
|
||||
|
||||
Reference in New Issue
Block a user