75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
import {GlobalStore} from '../lib/gstore'
|
|
import {APIClient} from '../lib/api-client'
|
|
import {PopUp} from '../lib/pop-up'
|
|
import {OnBlurManager} from '../lib/onblur'
|
|
require('../lib/css-class-override')
|
|
|
|
window.gstore = new GlobalStore();
|
|
|
|
|
|
/* (1) Global data
|
|
---------------------------------------------------------*/
|
|
/* (1) Get URL host */
|
|
gstore.add('HOST', document.URL.replace(/^((?:https?:\/\/)?[^\/]+)*(?:.+)$/, '$1'));
|
|
|
|
/* (2) Get list of URI arguments */
|
|
gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '').split('/').filter(function(i){ return i.length; }));
|
|
|
|
/* (3) Get if local version or prod */
|
|
gstore.add('is_local', document.URL.replace(/^https?:\/\/([^\/:]+).*$/, '$1') == 'ptut.com');
|
|
|
|
/* (4) API instance */
|
|
window.api = new APIClient(gstore.get.is_local ? 'http://ptut.com:8080/api/v/1.0/' : `${gstore.get.HOST}/api/v/1.0/`);
|
|
|
|
/* (5) PopUp instance */
|
|
window.popup = new PopUp();
|
|
|
|
/* (6) Create class in window */
|
|
window.onblur = new OnBlurManager(document.body);
|
|
|
|
|
|
|
|
|
|
/* (2) Main components
|
|
---------------------------------------------------------*/
|
|
/* (1) Header */
|
|
gstore.add('header_title', 'ndli1718');
|
|
|
|
/* (2) Menu */
|
|
gstore.add('menu_item', {
|
|
home: {
|
|
label: 'Accueil',
|
|
url: 'home',
|
|
icon: 'home'
|
|
}, teacher: {
|
|
label: 'Enseignants',
|
|
url: 'teacher',
|
|
icon: 'teacher'
|
|
}, ue: {
|
|
label: 'Gestion UE',
|
|
url: 'ue',
|
|
icon: 'ue'
|
|
}, settings: {
|
|
label: 'Administration',
|
|
url: 'settings',
|
|
icon: 'settings'
|
|
}
|
|
});
|
|
|
|
/* (3) Gestion du login/logout */
|
|
if( _SERVER.session.connected ) gstore.get.menu_item.logout = { label: 'Déconnexion', url: 'logout', icon: 'logout' };
|
|
else gstore.get.menu_item.login = { label: 'Connexion', url: 'login', icon: 'login' };
|
|
|
|
|
|
|
|
|
|
/* (4) Set current page active in menu */
|
|
if( gstore.get.URI.length > 0 && gstore.get.menu_item.hasOwnProperty(gstore.get.URI[0]) )
|
|
gstore.add('menu_item_active', gstore.get.menu_item[gstore.get.URI[0]].url);
|
|
else
|
|
gstore.add('menu_item_active', 'home');
|
|
|
|
|
|
gstore.add('navigate', function(uri){
|
|
console.log(uri);
|
|
}); |