Enhance promoteur hub functionality with AJAX loading and access control improvements

This commit introduces significant updates to the promoteur hub, including the addition of a new JavaScript file for AJAX handling of event statistics and links. The PHP file `ajax_promoteur_hub.php` is modified to support new actions for fetching event statistics and links, improving the user experience with better error handling and loading indicators. Additionally, a new batch access control function is implemented in `inc_fx_promoteur_hub.php` to streamline permission checks for events. The version code is incremented to reflect these enhancements, aiming to improve functionality and maintainability across the promoteur hub.
This commit is contained in:
2026-07-08 08:48:23 -04:00
parent dd4a83043a
commit 4522ddde8d
5 changed files with 280 additions and 77 deletions

111
js/v2/promoteur-hub.js Normal file
View File

@ -0,0 +1,111 @@
/**
* Hub promoteur — chargement AJAX stats + menu fonctionnalités.
* Chargé uniquement sur compte_promoteur_hub.
*/
(function () {
'use strict';
var cfg = window.MS1_V2_PROMOTEUR_HUB || {};
var $ = window.jQuery;
if (!$) {
return;
}
var strAjaxUrl = cfg.ajaxUrl || '';
var strWaitMsg = cfg.preloaderWait || 'Chargement…';
var intHubLoaderPending = 0;
function fxHubShowLoader() {
intHubLoaderPending++;
if (intHubLoaderPending !== 1) {
return;
}
if (window.Ms1Loader) {
Ms1Loader.show(strWaitMsg);
return;
}
var $preloader = $('#preloader');
if ($preloader.length) {
$('#preloader_text').html(strWaitMsg);
$preloader.show();
}
}
function fxHubHideLoader() {
intHubLoaderPending = Math.max(0, intHubLoaderPending - 1);
if (intHubLoaderPending !== 0) {
return;
}
if (window.Ms1Loader) {
Ms1Loader.hide();
return;
}
$('#preloader').fadeOut('slow');
}
function fxHubLoadStats($collapse) {
if ($collapse.data('hub-loaded') || !strAjaxUrl) {
return;
}
var intEve = $collapse.data('hub-eve-id');
var strLang = $collapse.data('hub-lang') || 'fr';
fxHubShowLoader();
$.getJSON(strAjaxUrl, { a: 'event_stats', eve_id: intEve, lang: strLang })
.done(function (r) {
if (!r || !r.ok) {
$collapse.find('.promoteur-hub-stats-placeholder').text(r && r.msg ? r.msg : 'Erreur');
return;
}
$collapse.find('.promoteur-hub-stats-placeholder').replaceWith(r.html || '');
if (r.flash) {
$collapse.closest('.promoteur-hub-card').find('.promoteur-hub-card-flash-wrap').html(r.flash);
}
$collapse.data('hub-loaded', 1);
})
.fail(function () {
$collapse.find('.promoteur-hub-stats-placeholder').text('Erreur chargement');
})
.always(function () {
fxHubHideLoader();
});
}
function fxHubLoadLinks($collapse) {
if ($collapse.data('hub-links-loaded') || !strAjaxUrl) {
return;
}
var intEve = $collapse.data('hub-eve-id');
var strLang = $collapse.data('hub-lang') || 'fr';
fxHubShowLoader();
$.getJSON(strAjaxUrl, { a: 'event_links', eve_id: intEve, lang: strLang })
.done(function (r) {
if (!r || !r.ok) {
$collapse.find('.promoteur-hub-links-placeholder').text(r && r.msg ? r.msg : 'Erreur');
return;
}
$collapse.find('.promoteur-hub-links-placeholder').replaceWith(r.html || '');
$collapse.data('hub-links-loaded', 1);
})
.fail(function () {
$collapse.find('.promoteur-hub-links-placeholder').text('Erreur chargement');
})
.always(function () {
fxHubHideLoader();
});
}
$(document).on('show.bs.collapse', '.promoteur-hub-epreuves-collapse', function () {
var $card = $(this).closest('.promoteur-hub-card');
$card.find('.promoteur-hub-epreuves-collapse.show, .promoteur-hub-functions.show').not(this).collapse('hide');
fxHubLoadStats($(this));
});
$(document).on('show.bs.collapse', '.promoteur-hub-functions', function () {
var $card = $(this).closest('.promoteur-hub-card');
$card.find('.promoteur-hub-epreuves-collapse.show, .promoteur-hub-functions.show').not(this).collapse('hide');
fxHubLoadLinks($(this));
});
})();