2017-12-01 14:45:45 +00:00
|
|
|
import {GlobalStore} from './lib/gstore-es6'
|
|
|
|
|
|
|
|
window.gstore = new GlobalStore();
|
2017-12-03 15:02:18 +00:00
|
|
|
|
|
|
|
// Header
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('header_title', 'ndli1718');
|
|
|
|
gstore.add('info', {
|
2017-12-04 18:19:15 +00:00
|
|
|
active: false,
|
|
|
|
type: 'warning',
|
2017-12-01 14:45:45 +00:00
|
|
|
message: 'Warning! blabla'
|
|
|
|
});
|
2017-12-07 17:17:32 +00:00
|
|
|
gstore.add('notif', {
|
|
|
|
emergency: { class: 'emergency', data: [], count: 0 },
|
|
|
|
event: { class: 'event', data: [], count: 0 },
|
|
|
|
inbox: { class: 'message', data: [], count: 0 },
|
|
|
|
dashboard: { class: 'menu', data: [], count: 0 }
|
|
|
|
})
|
2017-12-03 15:02:18 +00:00
|
|
|
|
|
|
|
// Menu
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('menu_item', {
|
2017-12-01 14:45:45 +00:00
|
|
|
dashboard: {
|
2017-12-07 17:17:32 +00:00
|
|
|
label: 'Accueil',
|
|
|
|
theme: 'dashboard'
|
|
|
|
}, emergency: {
|
|
|
|
label: 'Urgences',
|
|
|
|
theme: 'emergency'
|
|
|
|
}, event: {
|
|
|
|
label: 'Signalements',
|
|
|
|
theme: 'event'
|
2017-12-01 14:45:45 +00:00
|
|
|
}, inbox: {
|
2017-12-07 17:17:32 +00:00
|
|
|
label: 'Messagerie',
|
|
|
|
theme: 'inbox'
|
2017-12-01 14:45:45 +00:00
|
|
|
}
|
2017-12-03 15:02:18 +00:00
|
|
|
});
|
2017-12-04 10:48:32 +00:00
|
|
|
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, ''));
|
2017-12-07 14:33:01 +00:00
|
|
|
gstore.add('is_local', document.URL.replace(/^http:\/\/([^\/]+).*$/, '$1') == 'ndli1718');
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('min_menu', false);
|
2017-12-04 22:29:02 +00:00
|
|
|
|
|
|
|
// Proccess current page from url
|
2017-12-05 17:41:39 +00:00
|
|
|
if( /^\/(\w+)(?:\/?.*)$/.test(gstore.data.URI) ){
|
|
|
|
var mi_keys = Object.keys( gstore.data.menu_item );
|
2017-12-04 22:29:02 +00:00
|
|
|
|
|
|
|
// if current page exists
|
2017-12-05 17:41:39 +00:00
|
|
|
if( !!~mi_keys.indexOf(RegExp.$1) ) gstore.add('menu_item_active', RegExp.$1);
|
|
|
|
else gstore.add('menu_item_active', 'dashboard');
|
2017-12-04 22:29:02 +00:00
|
|
|
|
|
|
|
}else
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('menu_item_active', 'dashboard');
|
2017-12-04 10:48:32 +00:00
|
|
|
|
|
|
|
// Functions
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.add('func', {
|
2017-12-05 13:00:27 +00:00
|
|
|
nav: function(router, uri){
|
|
|
|
|
|
|
|
// {1} Update view (vue-router) //
|
2017-12-05 17:55:07 +00:00
|
|
|
if( typeof uri == 'string' )
|
|
|
|
router.push('/'+uri);
|
2017-12-05 13:00:27 +00:00
|
|
|
|
2017-12-05 17:55:07 +00:00
|
|
|
// {2} if no @uri -> Extract route from @router //
|
|
|
|
else if( /^\/([^\/]+).*$/.test( router.app.$route.path ) )
|
|
|
|
uri = RegExp.$1;
|
|
|
|
|
|
|
|
// {3} If no @uri -> exit //
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {4} Activate current menu_item //
|
2017-12-05 17:41:39 +00:00
|
|
|
gstore.data.menu_item_active = uri;
|
2017-12-05 13:00:27 +00:00
|
|
|
|
2017-12-05 17:55:07 +00:00
|
|
|
// {5} Manage notifications //
|
2017-12-07 17:17:32 +00:00
|
|
|
for( var id in gstore.data.notif )
|
|
|
|
if( id == uri ) // if notif links to current page
|
|
|
|
gstore.data.notif[id].count = 0;
|
2017-12-05 13:00:27 +00:00
|
|
|
|
|
|
|
},
|
2017-12-07 19:47:03 +00:00
|
|
|
toggleMenuSize: function(){ gstore.data.min_menu=!gstore.data.min_menu; },
|
|
|
|
bbcode: function(msg){
|
|
|
|
/* (1) Escape HTML
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
msg = msg.replace(/&/g, '&');
|
|
|
|
msg = msg.replace(/</g, '<');
|
|
|
|
msg = msg.replace(/>/g, '>');
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Manage text format
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Manage bold */
|
|
|
|
msg = msg.replace(/\*([^\*]+)\*/g, "<b>$1</b>");
|
|
|
|
|
|
|
|
/* (2) italic */
|
|
|
|
msg = msg.replace(/_([^_]+)_/g, "<i>$1</i>");
|
|
|
|
|
|
|
|
/* (3) underline */
|
|
|
|
msg = msg.replace(/\[([^\]]+)\]/g, "<ins>$1</ins>");
|
|
|
|
|
|
|
|
/* (4) Code */
|
|
|
|
msg = msg.replace(/`([^`]+)`/g, "<span class='code'>$1</span>");
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Manage emojis
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Smileys */
|
|
|
|
msg = msg.replace(/:D/g, "<span class='utf8'>😃</span>");
|
|
|
|
msg = msg.replace(/:\)/g, "<span class='utf8'>🙂</span>");
|
|
|
|
msg = msg.replace(/:B/g, "<span class='utf8'>😎</span>");
|
|
|
|
msg = msg.replace(/:3/g, "<span class='utf8'>😗</span>");
|
|
|
|
msg = msg.replace(/;\)/g, "<span class='utf8'>😉</span>");
|
|
|
|
msg = msg.replace(/:P/g, "<span class='utf8'>😋</span>");
|
|
|
|
msg = msg.replace(/;P/g, "<span class='utf8'>😜</span>");
|
|
|
|
msg = msg.replace(/xD/g, "<span class='utf8'>😆</span>");
|
|
|
|
msg = msg.replace(/:O/ig, "<span class='utf8'>😲</span>");
|
|
|
|
msg = msg.replace(/:S/g, "<span class='utf8'>😖</span>");
|
|
|
|
msg = msg.replace(/\^\^/g, "<span class='utf8'>😊</span>");
|
|
|
|
|
|
|
|
/* (2) Emojis */
|
|
|
|
msg = msg.replace(/:poop:/g, "<span class='utf8 br'>💩</span>");
|
|
|
|
msg = msg.replace(/:fuck:/g, "<span class='utf8'>🖕</span>");
|
|
|
|
msg = msg.replace(/\+1/g, "<span class='utf8 bl'>👍</span>");
|
|
|
|
msg = msg.replace(/-1/g, "<span class='utf8 bl'>👎</span>");
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
2017-12-05 12:32:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// new-message container
|
2017-12-07 17:38:27 +00:00
|
|
|
gstore.add('new_msg', {
|
|
|
|
inbox: '',
|
|
|
|
emergency: '',
|
|
|
|
event: ''
|
|
|
|
});
|
|
|
|
// if message loader
|
|
|
|
gstore.add('msg_pending', {
|
|
|
|
inbox: true,
|
|
|
|
emergency: true,
|
|
|
|
event: true
|
|
|
|
}); // true when message send pending
|
2017-12-06 20:38:04 +00:00
|
|
|
|
|
|
|
// notification stack visibility
|
2017-12-07 21:36:04 +00:00
|
|
|
gstore.add('nstack', false);
|
|
|
|
|
|
|
|
// location
|
|
|
|
gstore.add('loc', [0, 0]);
|