128 lines
4.3 KiB
JavaScript
128 lines
4.3 KiB
JavaScript
/**
|
|
* 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;
|
|
|
|
// MSIN-4401 — Session expiree : recharger la page → formulaire de login.
|
|
// Pas de message "Non connecte" qui laisse l'usager bloque.
|
|
function fxHubRedirectIfSessionExpired(r) {
|
|
if (r && (r.code === 'session' || r.msg === 'Non connecté' || r.msg === 'Session expirée')) {
|
|
window.location.reload();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
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 (fxHubRedirectIfSessionExpired(r)) {
|
|
return;
|
|
}
|
|
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 (fxHubRedirectIfSessionExpired(r)) {
|
|
return;
|
|
}
|
|
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));
|
|
});
|
|
})();
|