mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Fix relink: close modal + HTMX refresh for immediate pool update
- After relink, always close the modal (even if FilePond input not found, e.g. page refreshed by live-reload during the fetch). - After closing, re-fetch #format-fichiers-block via HTMX from /admin/fragments/fichiers.php?_thesis_id=N which loads thesis files from DB and re-renders the fragment with pre-populated FilePond pools. The afterSwap handler auto-reinitializes FilePond instances. - Updated admin/fragments/fichiers.php to accept _thesis_id, load existing files from DB, build per-queue-type JSON, and render in edit mode.
This commit is contained in:
@@ -629,15 +629,33 @@
|
||||
}
|
||||
console.log('[relink] success | new_id=' + data.id);
|
||||
|
||||
// Add the new file to the FilePond pool
|
||||
// Add the new file to the FilePond pool, then close the modal.
|
||||
// If the DOM was replaced (e.g. live-reload), refresh the
|
||||
// form fragment via HTMX so the server re-renders the pools
|
||||
// with the newly-linked file included.
|
||||
var input = document.querySelector(`.tfe-file-picker[data-queue-type="${queueType}"]`);
|
||||
console.log('[relink] looking for input | selector=' + `.tfe-file-picker[data-queue-type="${queueType}"]` + ' | found=' + !!input);
|
||||
var closeAndRefresh = function() {
|
||||
var modal = document.getElementById('relink-modal');
|
||||
if (modal) modal.close();
|
||||
// Re-fetch the fichiers fragment from the server so the
|
||||
// newly-linked file appears in the FilePond pools.
|
||||
var block = document.getElementById('format-fichiers-block');
|
||||
if (block && window.htmx) {
|
||||
var url = '/admin/fragments/fichiers.php';
|
||||
if (window.__xamxamRelinkCtx && window.__xamxamRelinkCtx.thesisId) {
|
||||
url += '?_thesis_id=' + encodeURIComponent(window.__xamxamRelinkCtx.thesisId);
|
||||
}
|
||||
htmx.ajax('GET', url, {
|
||||
target: '#format-fichiers-block',
|
||||
swap: 'outerHTML'
|
||||
});
|
||||
}
|
||||
};
|
||||
if (input) {
|
||||
var pond = FilePond.find(input);
|
||||
console.log('[relink] looking for pond | found=' + !!pond);
|
||||
if (pond) {
|
||||
// Add as LIMBO to trigger server.load, which returns the actual file blob + headers.
|
||||
// type: 'local' with file metadata skips load and may not render correctly.
|
||||
pond.addFile(String(data.id), {
|
||||
type: 'limbo',
|
||||
file: {
|
||||
@@ -647,18 +665,18 @@
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('[relink] addFile resolved | source=' + String(data.id) + ' | queueType=' + queueType);
|
||||
// Close modal after file is added to the pond.
|
||||
// syncOrderInput fires via onprocessfile / onupdatefiles.
|
||||
var modal = document.getElementById('relink-modal');
|
||||
if (modal) modal.close();
|
||||
closeAndRefresh();
|
||||
}).catch(function(err) {
|
||||
console.error('[relink] addFile rejected', err);
|
||||
closeAndRefresh();
|
||||
});
|
||||
} else {
|
||||
console.error('[relink] FilePond.find returned null for input', input);
|
||||
closeAndRefresh();
|
||||
}
|
||||
} else {
|
||||
console.error('[relink] input not found | queueType=' + queueType);
|
||||
console.warn('[relink] input not found, page may have reloaded | queueType=' + queueType);
|
||||
closeAndRefresh();
|
||||
}
|
||||
|
||||
// Mark form dirty
|
||||
|
||||
Reference in New Issue
Block a user