2016-07-23 14:36:58 +00:00
|
|
|
// TODO: Attendre que API soit chargée, sinon erreur, le CONTAINER prend comme contenu la dépendance JS
|
2016-02-01 22:09:35 +00:00
|
|
|
DOM = {
|
2016-02-14 21:50:07 +00:00
|
|
|
WRAPPER: $('WRAPPER'),
|
|
|
|
HEADER: $('HEADER'),
|
|
|
|
MENUSIDE: $('MENU-SIDE'),
|
2016-02-01 22:09:35 +00:00
|
|
|
CONTAINER: $('CONTAINER')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* [0] Instanciation
|
|
|
|
===========================================*/
|
|
|
|
var pageManager = new pageManagerClass();
|
2016-07-21 10:23:18 +00:00
|
|
|
pageManager.setPage(null, '/view', DOM.CONTAINER, ['history', 'profile', 'machines', 'users', 'groups', 'analytics', 'settings'] );
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-02-14 20:22:07 +00:00
|
|
|
var api = new APIClass('/api/');
|
2016-02-02 10:09:48 +00:00
|
|
|
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
/* [1] Toggle du sub-menu-side <-> navigation
|
|
|
|
===========================================*/
|
|
|
|
function navSubMenu(subsection){
|
|
|
|
/* [1] Format du param
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Contient l'element courant
|
|
|
|
var current = document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink="'+pageManager.vars[0]+'"]');
|
|
|
|
|
|
|
|
// Contiendra l'element cible
|
|
|
|
var target = null;
|
|
|
|
|
|
|
|
// si @subsection est un element, on le prends
|
2016-07-02 15:10:41 +00:00
|
|
|
target = (subsection instanceof Element) ? subsection : null;
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
// Si string, on trouve l'element correspondant
|
|
|
|
target = (typeof subsection == 'string') ? document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink="'+subsection+'"]') : target;
|
|
|
|
|
|
|
|
// Si rien trouve, on prend le premier element correspondant a la premiere page
|
|
|
|
target = (target == null) ? document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink]') : target;
|
|
|
|
|
|
|
|
// Si le param n'est toujours pas bon, on retourne une erreur
|
|
|
|
if( target == null ) return false;
|
|
|
|
|
|
|
|
/* [2] Gestion de l'affichage de l'element
|
|
|
|
------------------------------------------------*/
|
|
|
|
// On desactive l'element courant
|
|
|
|
if( current != null )
|
|
|
|
current.remClass('active');
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-02-06 10:41:50 +00:00
|
|
|
// On cache les sections visibles
|
|
|
|
var visibleSections = document.querySelectorAll('#CONTAINER > section[data-sublink].active');
|
|
|
|
for( var i = 0 ; i < visibleSections.length ; i++ )
|
|
|
|
visibleSections[i].remClass('active');
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
// On active le nouveau
|
2016-02-06 10:41:50 +00:00
|
|
|
if( target != null ){
|
2016-02-03 09:53:41 +00:00
|
|
|
target.addClass('active');
|
|
|
|
|
2016-02-06 10:41:50 +00:00
|
|
|
// On affiche la section associee
|
|
|
|
var targetSection = document.querySelector('#CONTAINER > section[data-sublink="'+target.getData('sublink')+'"]');
|
|
|
|
if( targetSection != null )
|
|
|
|
targetSection.addClass('active');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
/* [3] Gestion de pageManager
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Si element, on recupere le data-link
|
|
|
|
var page = null;
|
|
|
|
|
2016-02-03 11:32:53 +00:00
|
|
|
// Si erreur, on retourne FALSE
|
|
|
|
if( !target.getData('sublink') ) return false
|
|
|
|
|
|
|
|
var mustRefresh = pageManager.vars[0] != target.getData('sublink');
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
// On met a jour la variable page-manager si data-link trouve
|
2016-02-03 11:32:53 +00:00
|
|
|
pageManager.vars[0] = target.getData('sublink');
|
|
|
|
|
|
|
|
if( mustRefresh )
|
2016-02-06 10:41:50 +00:00
|
|
|
// navMenu(pageManager.page);
|
|
|
|
pageManager.updateURL();
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
/* [2] Toggle du side-menu <-> navigation
|
2016-02-02 10:09:48 +00:00
|
|
|
===========================================*/
|
2016-07-20 23:13:48 +00:00
|
|
|
function navMenu(section, persistence){
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
/* [1] Format du param
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Contient l'element courant
|
|
|
|
var current = document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.page+'"]');
|
|
|
|
|
|
|
|
// Contiendra l'element cible
|
|
|
|
var target = null;
|
|
|
|
|
|
|
|
// si @section est un element, on le prends
|
2016-07-02 15:10:41 +00:00
|
|
|
target = (section instanceof Element) ? section : null;
|
2016-02-02 10:09:48 +00:00
|
|
|
|
|
|
|
// Si string, on trouve l'element correspondant
|
|
|
|
target = (typeof section == 'string') ? document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+section+'"]') : target;
|
|
|
|
|
|
|
|
// Si rien trouve, on prend le premier element correspondant a la premiere page
|
|
|
|
target = (target == null) ? document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.pagelist[0]+'"]') : target;
|
|
|
|
|
|
|
|
// Si le param n'est toujours pas bon, on retourne une erreur
|
|
|
|
if( target == null ) return false;
|
|
|
|
|
2016-07-20 23:13:48 +00:00
|
|
|
// Persistence de pageManager.vars (OPTIONNEL)
|
|
|
|
persistence = (persistence===true) ? true : false;
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
/* [2] Gestion de l'affichage de l'element
|
|
|
|
------------------------------------------------*/
|
|
|
|
// On desactive l'element courant
|
|
|
|
if( current != null )
|
|
|
|
current.remClass('active');
|
|
|
|
// On active le nouveau
|
|
|
|
if( target != null )
|
|
|
|
target.addClass('active');
|
|
|
|
|
|
|
|
/* [3] Gestion de pageManager
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Si element, on recupere le data-link
|
|
|
|
var page = null;
|
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
// SI on change de menu, on efface les données URL
|
2016-07-20 23:13:48 +00:00
|
|
|
if( !persistence && current != target )
|
2016-07-12 13:16:07 +00:00
|
|
|
pageManager.vars = [];
|
|
|
|
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
// On charge la page si data-link trouve
|
2016-02-02 13:03:22 +00:00
|
|
|
if( target.getData('link') ){
|
|
|
|
DOM.HEADER.addClass('loading'); // Animation de chargement
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
pageManager.setPage( target.getData('link') );
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
pageManager.activeXHR.addEventListener('loadend', function(){
|
|
|
|
|
|
|
|
// On retire l'icone de chargement
|
|
|
|
DOM.HEADER.remClass('loading');
|
|
|
|
|
2016-02-03 11:32:53 +00:00
|
|
|
// On gere la navigation du sous-menu (si defini, utilise)
|
2016-07-20 23:13:48 +00:00
|
|
|
var subSectionExists = pageManager.vars.length > 0 && document.querySelector('#CONTAINER > .sub-menu-side > [data-sublink="'+pageManager.vars[0]+'"]') != null;
|
2016-02-03 11:32:53 +00:00
|
|
|
if( subSectionExists ) // Si le lien du menu associe existe
|
|
|
|
navSubMenu(pageManager.vars[0]); // on charge la page associee
|
|
|
|
else // sinon
|
|
|
|
navSubMenu(null); // on charge le lien par defaut
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
// GESTION DE LA NAVIGATION DU SOUS-MENU
|
|
|
|
document.querySelector('#CONTAINER > .sub-menu-side').addEventListener('click', function(e){
|
2016-02-03 11:32:53 +00:00
|
|
|
var target = e.target;
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
while( target != document.body && !target.getData('sublink') )
|
|
|
|
target = target.parentNode;
|
|
|
|
|
|
|
|
if( target.getData('sublink') )
|
|
|
|
navSubMenu(target);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}, false);
|
2016-02-02 13:03:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
}navMenu(pageManager.page);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-03 09:53:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Gestion de la navigation (physique)
|
2016-02-01 22:09:35 +00:00
|
|
|
===========================================*/
|
|
|
|
DOM.MENUSIDE.addEventListener('click', function(e){
|
|
|
|
var target = e.target;
|
|
|
|
|
|
|
|
// On remonte dans les parents au bon niveau
|
2016-02-02 10:09:48 +00:00
|
|
|
while( target != document.body && !target.getData('link') )
|
2016-02-01 22:09:35 +00:00
|
|
|
target = target.parentNode;
|
|
|
|
|
|
|
|
// Si on a trouve l'element, on l'utilise pour la page
|
2016-02-02 10:09:48 +00:00
|
|
|
if( target.getData('link') )
|
|
|
|
navMenu(target.getData('link'));
|
|
|
|
}, false);
|