2016-04-05 13:08:42 +00:00
|
|
|
/* [-1] On attend le chargement du document
|
|
|
|
=========================================================*/
|
|
|
|
// document.onload = function(){
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
DOM = {
|
|
|
|
WRAPPER: $('WRAPPER'),
|
|
|
|
HEADER: $('HEADER'),
|
|
|
|
MENUSIDE: $('MENU-SIDE'),
|
|
|
|
CONTAINER: $('CONTAINER')
|
|
|
|
};
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
/* [0] Instanciation
|
|
|
|
===========================================*/
|
|
|
|
var pageManager = new pageManagerClass();
|
2016-04-06 14:24:45 +00:00
|
|
|
pageManager.setPage(null, '/view', DOM.CONTAINER, ['dashboard', 'input', 'analytics', 'charts', 'settings'] );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
var api = new APIClass('/api/');
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-10 11:20:37 +00:00
|
|
|
|
|
|
|
/* [1] Toggle du sub-menu-side <-> navigation
|
|
|
|
===========================================*/
|
|
|
|
function navSubMenu(subsection){
|
|
|
|
/* [1] Format du param
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Contient l'element courant
|
|
|
|
var current = document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub > span[data-sublink="'+pageManager.vars[0]+'"]');
|
|
|
|
|
|
|
|
// Contiendra l'element cible
|
|
|
|
var target = null;
|
|
|
|
|
|
|
|
// si @subsection est un element, on le prends
|
|
|
|
target = (subsection instanceof Element) ? subsection : null;
|
|
|
|
|
|
|
|
// Si string, on trouve l'element correspondant
|
|
|
|
target = (typeof subsection == 'string') ? document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub > span[data-sublink="'+subsection+'"]') : target;
|
|
|
|
|
|
|
|
// Si rien trouve, on prend le premier element correspondant a la premiere page
|
|
|
|
target = (target == null) ? document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub > 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');
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
|
|
|
|
// On active le nouveau
|
|
|
|
if( target != null ){
|
|
|
|
target.addClass('active');
|
|
|
|
|
|
|
|
// On affiche la section associee
|
|
|
|
var targetSection = document.querySelector('#CONTAINER > section[data-sublink="'+target.getData('sublink')+'"]');
|
|
|
|
if( targetSection != null )
|
|
|
|
targetSection.addClass('active');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [3] Gestion de pageManager
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Si element, on recupere le data-link
|
|
|
|
var page = null;
|
|
|
|
|
|
|
|
// Si erreur, on retourne FALSE
|
|
|
|
if( !target.getData('sublink') ) return false
|
|
|
|
|
|
|
|
var mustRefresh = pageManager.vars[0] != target.getData('sublink');
|
|
|
|
|
|
|
|
// On met a jour la variable page-manager si data-link trouve
|
|
|
|
pageManager.vars[0] = target.getData('sublink');
|
|
|
|
|
|
|
|
if( mustRefresh )
|
|
|
|
// navMenu(pageManager.page);
|
|
|
|
pageManager.updateURL();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [4 Toggle du side-menu <-> navigation
|
2016-04-05 13:08:42 +00:00
|
|
|
===========================================*/
|
|
|
|
function navMenu(section){
|
|
|
|
|
|
|
|
/* [1] Format du param
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Contient l'element courant
|
|
|
|
var current = document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.page+'"]');
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// Contiendra l'element cible
|
|
|
|
var target = null;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// si @section est un element, on le prends
|
|
|
|
target = (section instanceof Element) ? section : null;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// Si string, on trouve l'element correspondant
|
|
|
|
target = (typeof section == 'string') ? document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+section+'"]') : target;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// 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;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// Si le param n'est toujours pas bon, on retourne une erreur
|
|
|
|
if( target == null ) return false;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +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');
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
/* [3] Gestion de pageManager
|
|
|
|
------------------------------------------------*/
|
|
|
|
// Si element, on recupere le data-link
|
|
|
|
var page = null;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// On charge la page si data-link trouve
|
|
|
|
if( target.getData('link') ){
|
|
|
|
DOM.HEADER.addClass('loading'); // Animation de chargement
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
pageManager.setPage( target.getData('link') );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
pageManager.activeXHR.addEventListener('loadend', function(){
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-10 11:20:37 +00:00
|
|
|
// On gere la navigation du sous-menu (si defini, utilise)
|
|
|
|
var subSectionExists = pageManager.vars.length >= 1 && document.querySelector('#CONTAINER > section[data-sublink="'+pageManager.vars[0]+'"]') != null;
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
// GESTION DE LA NAVIGATION DU SOUS-MENU
|
|
|
|
// si le sous-menu existe
|
|
|
|
var smenu = document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub');
|
|
|
|
if( smenu != null )
|
|
|
|
smenu.addEventListener('click', function(e){
|
|
|
|
var target = e.target;
|
|
|
|
|
|
|
|
while( target != document.body && !target.getData('sublink') )
|
|
|
|
target = target.parentNode;
|
|
|
|
|
|
|
|
if( target.getData('sublink') )
|
|
|
|
navSubMenu(target);
|
|
|
|
}, false);
|
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// On retire l'icone de chargement
|
|
|
|
DOM.HEADER.remClass('loading');
|
|
|
|
}, false);
|
|
|
|
}
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
}navMenu(pageManager.page);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-10 11:20:37 +00:00
|
|
|
/* [5] Gestion de la navigation (physique)
|
2016-04-05 13:08:42 +00:00
|
|
|
===========================================*/
|
|
|
|
DOM.MENUSIDE.addEventListener('click', function(e){
|
|
|
|
var target = e.target;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// On remonte dans les parents au bon niveau
|
|
|
|
while( target != document.body && !target.getData('link') )
|
|
|
|
target = target.parentNode;
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// Si on a trouve l'element, on l'utilise pour la page
|
|
|
|
if( target.getData('link') )
|
|
|
|
navMenu(target.getData('link'));
|
|
|
|
}, false);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
/* [6] Gestion du rechargement de page
|
|
|
|
=========================================================*/
|
|
|
|
function reload(){ navMenu( pageManager.page ); }
|
|
|
|
|
|
|
|
|
2016-04-12 10:03:15 +00:00
|
|
|
/* [7] Gestion du toggle de la page de login
|
|
|
|
=========================================================*/
|
|
|
|
var LOGIN = {
|
|
|
|
show: document.getElementById('user-data'),
|
|
|
|
hide: document.getElementById('login-close'),
|
2016-04-12 14:30:14 +00:00
|
|
|
page: document.getElementById('LOGIN'),
|
|
|
|
|
|
|
|
login: document.getElementById('login-login'),
|
|
|
|
password: document.getElementById('login-password'),
|
|
|
|
submit: document.getElementById('login-submit')
|
2016-04-12 10:03:15 +00:00
|
|
|
};
|
|
|
|
|
2016-04-12 14:30:14 +00:00
|
|
|
/* (1) Gestion de l'affichage de la page de login */
|
2016-04-12 10:03:15 +00:00
|
|
|
LOGIN.show.addEventListener('click', function(e){ LOGIN.page.className = 'active'; }, false);
|
|
|
|
|
2016-04-12 14:30:14 +00:00
|
|
|
/* (2) Gestion de la fermeture de la page de login */
|
2016-04-12 10:03:15 +00:00
|
|
|
LOGIN.hide.addEventListener('click', function(e){ LOGIN.page.className = ''; }, false);
|
|
|
|
|
2016-04-12 14:30:14 +00:00
|
|
|
/* (3) Gestion du login */
|
|
|
|
LOGIN.submit.addEventListener('click', function(e){
|
|
|
|
// Creation de la requete de connexion
|
|
|
|
var request = {
|
|
|
|
path: 'users/login',
|
|
|
|
login: LOGIN.login.value,
|
|
|
|
password: LOGIN.password.value
|
|
|
|
};
|
|
|
|
|
|
|
|
// On lance la requete et recupere la reponse
|
|
|
|
api.send(request, function(answer){
|
|
|
|
console.log( answer );
|
|
|
|
if( answer.ModuleError == 0 ) // Si on est bien connecte, on recharge la page
|
|
|
|
document.location = '/';
|
|
|
|
}, js_access_token);
|
|
|
|
|
|
|
|
}, false);
|
2016-04-12 10:03:15 +00:00
|
|
|
|
2016-04-05 13:08:42 +00:00
|
|
|
// }
|