Implement global batch panel functionality with deferred loading and increment version code to 4.72.742
This commit introduces a new action for the global batch panel in the AJAX handler, allowing for deferred loading of the panel upon user interaction. The JavaScript is updated to manage the loading state and ensure the panel is populated with relevant data when opened. Additionally, a new rendering function is added to handle the display of the global batch panel shell, improving user experience by ensuring that the panel only loads when necessary. The version code is incremented to reflect these enhancements.
This commit is contained in:
@ -40,6 +40,7 @@ $arrBibAjaxActions = [
|
||||
'anomalies',
|
||||
'batch_global_analysis',
|
||||
'batch_global_simulate',
|
||||
'global_batch_panel',
|
||||
];
|
||||
|
||||
if ($action !== '' && in_array($action, $arrBibAjaxActions, true)) {
|
||||
@ -354,6 +355,43 @@ if ($action == 'batch_analysis') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// MSIN-4436 — Panneau assignation globale (chargement différé à l'ouverture).
|
||||
if ($action == 'global_batch_panel') {
|
||||
|
||||
$int_eve_id = (int)($_POST['eve_id'] ?? 0);
|
||||
|
||||
if ($int_eve_id <= 0) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => fxBibMsg('bib_v4_ajax_epr_invalid'),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$tabEpreuves = $objDatabase->fxGetResults(
|
||||
"SELECT * FROM inscriptions_epreuves e WHERE e.eve_id = " . $int_eve_id . " AND epr_actif = 1 ORDER BY epr_id"
|
||||
);
|
||||
$tabBibAssignments = $objDatabase->fxGetResults(
|
||||
"SELECT * FROM bib_assignements WHERE ba_actif = 1 ORDER BY ba_tri"
|
||||
);
|
||||
|
||||
$html = renderBibGlobalBatchPanel($int_eve_id, $tabEpreuves, $tabBibAssignments, $strLangue);
|
||||
|
||||
if ($html === '') {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => fxBibMsg('bib_v4_global_batch_need_two'),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'html' => $html,
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// MSIN-4436 — Analyse batch global (épreuves solo, séquences par épreuve).
|
||||
if ($action == 'batch_global_analysis') {
|
||||
|
||||
|
||||
@ -299,8 +299,83 @@
|
||||
});
|
||||
}
|
||||
|
||||
// MSIN-4436 — Batch global (épreuves solo).
|
||||
var bibGlobalBatchPanel = document.getElementById('bib-global-batch');
|
||||
// MSIN-4436 — Batch global (épreuves solo), chargement différé à l'ouverture.
|
||||
var bibGlobalBatchLoadPromise = null;
|
||||
|
||||
function bibGetGlobalBatchPanel() {
|
||||
return document.getElementById('bib-global-batch');
|
||||
}
|
||||
|
||||
function bibEnsureGlobalBatchPanelLoaded() {
|
||||
var mount = document.getElementById('bib-global-batch-mount');
|
||||
var panel = bibGetGlobalBatchPanel();
|
||||
|
||||
if (!mount || !panel) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (panel.getAttribute('data-global-batch-loaded') === '1') {
|
||||
return Promise.resolve(panel);
|
||||
}
|
||||
|
||||
if (bibGlobalBatchLoadPromise) {
|
||||
return bibGlobalBatchLoadPromise;
|
||||
}
|
||||
|
||||
bibGlobalBatchLoadPromise = bibFetch('/ajax_bib_range.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body:
|
||||
'action=global_batch_panel'
|
||||
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
|
||||
+ bibAjaxLangSuffix()
|
||||
})
|
||||
.then(function (res) { return res.json(); })
|
||||
.then(function (data) {
|
||||
if (!data.success || !data.html) {
|
||||
throw new Error(data.message || bibJs('jsErrGeneric'));
|
||||
}
|
||||
|
||||
mount.innerHTML = data.html;
|
||||
panel = bibGetGlobalBatchPanel();
|
||||
if (panel) {
|
||||
panel.setAttribute('data-global-batch-loaded', '1');
|
||||
panel.removeAttribute('data-global-batch-deferred');
|
||||
}
|
||||
return panel;
|
||||
})
|
||||
.finally(function () {
|
||||
bibGlobalBatchLoadPromise = null;
|
||||
});
|
||||
|
||||
return bibGlobalBatchLoadPromise;
|
||||
}
|
||||
|
||||
function bibGlobalBatchSetToggleState(toggle, isOpen) {
|
||||
if (!toggle) {
|
||||
return;
|
||||
}
|
||||
toggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
||||
var label = isOpen
|
||||
? (toggle.getAttribute('data-label-close') || '')
|
||||
: (toggle.getAttribute('data-label-open') || '');
|
||||
if (label) {
|
||||
toggle.textContent = label;
|
||||
}
|
||||
}
|
||||
|
||||
function bibGlobalBatchOpenPanel(panel) {
|
||||
if (!panel) {
|
||||
return;
|
||||
}
|
||||
var body = panel.querySelector('.bib-global-batch__body');
|
||||
var toggle = panel.querySelector('.bib-global-batch-toggle');
|
||||
if (body) {
|
||||
body.classList.remove('bib-ui-hidden');
|
||||
}
|
||||
bibGlobalBatchSetToggleState(toggle, true);
|
||||
updateGlobalBatchAnalysis();
|
||||
}
|
||||
|
||||
function bibSetGlobalBatchInfo(infoEl, text, state) {
|
||||
if (!infoEl) {
|
||||
@ -322,6 +397,7 @@
|
||||
}
|
||||
|
||||
function bibCollectGlobalBatchPlans() {
|
||||
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
|
||||
if (!bibGlobalBatchPanel) {
|
||||
return [];
|
||||
}
|
||||
@ -352,6 +428,7 @@
|
||||
}
|
||||
|
||||
function updateGlobalBatchAnalysis() {
|
||||
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
|
||||
if (!bibGlobalBatchPanel) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -417,6 +494,7 @@
|
||||
}
|
||||
|
||||
function bibRunGlobalBatchGo() {
|
||||
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
|
||||
if (!bibGlobalBatchPanel) {
|
||||
return;
|
||||
}
|
||||
@ -518,7 +596,8 @@
|
||||
refreshBibAnomaliesPanel();
|
||||
}
|
||||
|
||||
var infoEl = bibGlobalBatchPanel.querySelector('.bib-global-batch__info');
|
||||
var panelRef = bibGetGlobalBatchPanel();
|
||||
var infoEl = panelRef ? panelRef.querySelector('.bib-global-batch__info') : null;
|
||||
var totalAssigned = 0;
|
||||
var totalExpected = 0;
|
||||
|
||||
@ -557,88 +636,115 @@
|
||||
});
|
||||
}
|
||||
|
||||
if (bibGlobalBatchPanel) {
|
||||
var globalToggle = bibGlobalBatchPanel.querySelector('.bib-global-batch-toggle');
|
||||
var globalBody = bibGlobalBatchPanel.querySelector('.bib-global-batch__body');
|
||||
|
||||
if (globalToggle && globalBody) {
|
||||
globalToggle.addEventListener('click', function () {
|
||||
var hidden = globalBody.classList.toggle('bib-ui-hidden');
|
||||
globalToggle.setAttribute('aria-expanded', hidden ? 'false' : 'true');
|
||||
var label = hidden
|
||||
? (globalToggle.getAttribute('data-label-open') || '')
|
||||
: (globalToggle.getAttribute('data-label-close') || '');
|
||||
if (label) {
|
||||
globalToggle.textContent = label;
|
||||
}
|
||||
if (!hidden) {
|
||||
updateGlobalBatchAnalysis();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bibGlobalBatchPanel.addEventListener('change', function (e) {
|
||||
if (e.target.matches('.bib-global-epr-select, .bib-global-range-select, .bib-global-batch-order')) {
|
||||
var eprBlock = e.target.closest('.bib-global-epr');
|
||||
if (eprBlock && e.target.classList.contains('bib-global-epr-select')) {
|
||||
var checked = e.target.checked;
|
||||
eprBlock.querySelectorAll('.bib-global-range-select').forEach(function (cb) {
|
||||
cb.disabled = !checked;
|
||||
if (!checked) {
|
||||
cb.checked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
updateGlobalBatchAnalysis();
|
||||
}
|
||||
});
|
||||
|
||||
bibGlobalBatchPanel.addEventListener('click', function (e) {
|
||||
if (e.target.closest('.btn-simuler-global-batch')) {
|
||||
e.preventDefault();
|
||||
var plans = bibCollectGlobalBatchPlans();
|
||||
var baSelect = bibGlobalBatchPanel.querySelector('.bib-global-batch-order');
|
||||
|
||||
if (plans.length === 0) {
|
||||
alert(bibJs('jsGlobalNoEpr') || bibJs('jsBatchNone'));
|
||||
return;
|
||||
}
|
||||
|
||||
bibFetch('/ajax_bib_range.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body:
|
||||
'action=batch_global_simulate'
|
||||
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
|
||||
+ '&ba_id=' + encodeURIComponent(baSelect ? baSelect.value : '')
|
||||
+ '&plans=' + encodeURIComponent(JSON.stringify(plans))
|
||||
+ bibAjaxLangSuffix()
|
||||
})
|
||||
.then(function (res) { return res.json(); })
|
||||
.then(function (data) {
|
||||
if (!data.success) {
|
||||
alert(data.message || bibJs('jsErrGeneric'));
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = document.querySelector('.epr-row-view');
|
||||
if (existing) {
|
||||
existing.remove();
|
||||
}
|
||||
|
||||
var anchor = bibGlobalBatchPanel;
|
||||
anchor.insertAdjacentHTML('afterend', data.html);
|
||||
});
|
||||
|
||||
moduleBib.addEventListener('click', function (e) {
|
||||
var globalToggle = e.target.closest('.bib-global-batch-toggle');
|
||||
if (globalToggle) {
|
||||
var panel = globalToggle.closest('#bib-global-batch');
|
||||
if (!panel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target.closest('.btn-go-global-batch')) {
|
||||
e.preventDefault();
|
||||
bibRunGlobalBatchGo();
|
||||
var body = panel.querySelector('.bib-global-batch__body');
|
||||
if (!body) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var willOpen = body.classList.contains('bib-ui-hidden');
|
||||
|
||||
if (willOpen && panel.getAttribute('data-global-batch-deferred') === '1') {
|
||||
bibEnsureGlobalBatchPanelLoaded()
|
||||
.then(function (loadedPanel) {
|
||||
if (!loadedPanel) {
|
||||
return;
|
||||
}
|
||||
bibGlobalBatchOpenPanel(loadedPanel);
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err.message || bibJs('jsErrGeneric'));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var hidden = body.classList.toggle('bib-ui-hidden');
|
||||
bibGlobalBatchSetToggleState(globalToggle, !hidden);
|
||||
if (!hidden) {
|
||||
updateGlobalBatchAnalysis();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target.closest('.btn-simuler-global-batch')) {
|
||||
e.preventDefault();
|
||||
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
|
||||
var plans = bibCollectGlobalBatchPlans();
|
||||
var baSelect = bibGlobalBatchPanel
|
||||
? bibGlobalBatchPanel.querySelector('.bib-global-batch-order')
|
||||
: null;
|
||||
|
||||
if (plans.length === 0) {
|
||||
alert(bibJs('jsGlobalNoEpr') || bibJs('jsBatchNone'));
|
||||
return;
|
||||
}
|
||||
|
||||
bibFetch('/ajax_bib_range.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body:
|
||||
'action=batch_global_simulate'
|
||||
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
|
||||
+ '&ba_id=' + encodeURIComponent(baSelect ? baSelect.value : '')
|
||||
+ '&plans=' + encodeURIComponent(JSON.stringify(plans))
|
||||
+ bibAjaxLangSuffix()
|
||||
})
|
||||
.then(function (res) { return res.json(); })
|
||||
.then(function (data) {
|
||||
if (!data.success) {
|
||||
alert(data.message || bibJs('jsErrGeneric'));
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = document.querySelector('.epr-row-view');
|
||||
if (existing) {
|
||||
existing.remove();
|
||||
}
|
||||
|
||||
var anchor = bibGetGlobalBatchPanel();
|
||||
if (anchor) {
|
||||
anchor.insertAdjacentHTML('afterend', data.html);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target.closest('.btn-go-global-batch')) {
|
||||
e.preventDefault();
|
||||
bibRunGlobalBatchGo();
|
||||
}
|
||||
});
|
||||
|
||||
moduleBib.addEventListener('change', function (e) {
|
||||
if (!e.target.matches('.bib-global-epr-select, .bib-global-range-select, .bib-global-batch-order')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
|
||||
if (!bibGlobalBatchPanel || !bibGlobalBatchPanel.contains(e.target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var eprBlock = e.target.closest('.bib-global-epr');
|
||||
if (eprBlock && e.target.classList.contains('bib-global-epr-select')) {
|
||||
var checked = e.target.checked;
|
||||
eprBlock.querySelectorAll('.bib-global-range-select').forEach(function (cb) {
|
||||
cb.disabled = !checked;
|
||||
if (!checked) {
|
||||
cb.checked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
updateGlobalBatchAnalysis();
|
||||
});
|
||||
|
||||
function bibRowPendingBibs(row) {
|
||||
if (!row) return 0;
|
||||
|
||||
@ -3891,9 +3891,48 @@ function fxBibParseGlobalBatchPlans($plans, $int_eve_id) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* MSIN-4436 — Coquille assignation globale (aucun calcul séquence au chargement page).
|
||||
*/
|
||||
function renderBibGlobalBatchPanelShell($int_eve_id, $tabEpreuves, $strLangue) {
|
||||
$int_eve_id = (int)$int_eve_id;
|
||||
$intSolo = 0;
|
||||
|
||||
foreach ($tabEpreuves as $epr) {
|
||||
if ((int)($epr['epr_equipe'] ?? 0) !== 1) {
|
||||
$intSolo++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($intSolo < 2) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div id="bib-global-batch-mount">
|
||||
<div id="bib-global-batch" class="bib-global-batch" data-global-batch-deferred="1">
|
||||
<div class="bib-global-batch__header">
|
||||
<?php echo fxBibBlockHeader('bib_v4_global_batch_title', 'bib_v4_global_batch_doc'); ?>
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-secondary bib-global-batch-toggle"
|
||||
aria-expanded="false"
|
||||
data-label-open="<?php echo fxBibEsc(fxBibTexte('bib_v4_global_batch_open', 0)); ?>"
|
||||
data-label-close="<?php echo fxBibEsc(fxBibTexte('bib_v4_global_batch_close', 0)); ?>">
|
||||
<?php fxBibTexte('bib_v4_global_batch_open', 1); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="bib-global-batch__body bib-ui-hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* MSIN-4436 — Panneau assignation globale (épreuves solo uniquement).
|
||||
* Pré-coche toutes les séquences disponibles ; l'utilisateur peut en retirer avant GO.
|
||||
* Appelé en AJAX à l'ouverture du panneau (pas au chargement page).
|
||||
*/
|
||||
function renderBibGlobalBatchPanel($int_eve_id, $tabEpreuves, $tabBibAssignments, $strLangue) {
|
||||
$int_eve_id = (int)$int_eve_id;
|
||||
@ -4055,7 +4094,7 @@ function fxShowBibTool4($str_code, $int_eve_id, $strLangue){
|
||||
<?php echo renderBibAnomaliesPanelShell((int)$int_eve_id, $strLangue); ?>
|
||||
</div>
|
||||
|
||||
<?php echo renderBibGlobalBatchPanel((int)$int_eve_id, $tabEpreuves, $tabBibAssignments, $strLangue); ?>
|
||||
<?php echo renderBibGlobalBatchPanelShell((int)$int_eve_id, $tabEpreuves, $strLangue); ?>
|
||||
|
||||
<?php for($i = 1; $i <= count($tabEpreuves); $i++){ ?>
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
* Constantes *
|
||||
*
|
||||
**************/
|
||||
define('_VERSION_CODE', '4.72.741');
|
||||
define('_VERSION_CODE', '4.72.742');
|
||||
define('_DATE_CODE', '2026-07-08');
|
||||
//MSIN-4290
|
||||
define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');
|
||||
|
||||
Reference in New Issue
Block a user