import {GlobalStore} from './lib/gstore-es6' window.gstore = new GlobalStore(); // Header gstore.add('header_title', 'ndli1718'); gstore.add('info', { active: false, type: 'warning', message: 'Warning! blabla' }); gstore.add('notif', [ { class: 'bell', link: 'notifications', data: [], count: 0 }, { class: 'message', link: 'inbox', data: [], count: 0 }, { class: 'search', link: 'search', data: [], count: 0 }, { class: 'menu', link: 'dashboard', data: [], count: 0 } ]) // Menu gstore.add('menu_item', { dashboard: { label: 'Dashboard', icon: 'dashboard' }, profile: { label: 'Profil', icon: 'profile' }, inbox: { label: 'Messagerie instantannée', icon: 'messages' }, notifications: { label: 'Notifications', icon: 'bell' } }); gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '')); gstore.add('min_menu', false); // Proccess current page from url if( /^\/(\w+)(?:\/?.*)$/.test(gstore.data.URI) ){ var mi_keys = Object.keys( gstore.data.menu_item ); // if current page exists if( !!~mi_keys.indexOf(RegExp.$1) ) gstore.add('menu_item_active', RegExp.$1); else gstore.add('menu_item_active', 'dashboard'); }else gstore.add('menu_item_active', 'dashboard'); // Functions gstore.add('func', { nav: function(router, uri){ // {1} Update view (vue-router) // router.push('/'+uri); // {2} Activate current menu_item // gstore.data.menu_item_active = uri; // {3} Manage notifications // for( var notif of gstore.data.notif ) if( notif.link == uri ) // if notif links to current page notif.count = 0; }, toggleMenuSize: function(){ gstore.data.min_menu=!gstore.data.min_menu; }, sendMessage: function(msg){ /* (1) Send message to WebSocket */ wsc_chat.send(JSON.stringify({message: msg})); /* (2) Add locally */ gstore.data.notif[1].data.push([ gstore.data.server.session.name, msg ]); } }); // new-message container gstore.add('new_msg', '');