2020-10-07 22:49:51 +02:00
|
|
|
jQuery = $;
|
2020-09-13 00:56:56 +02:00
|
|
|
window.$ = window.jQuery = $;
|
|
|
|
import 'bootstrap';
|
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
2020-11-14 23:00:36 +01:00
|
|
|
import './main.css';
|
2020-10-07 22:49:51 +02:00
|
|
|
import './font-awesome.scss';
|
2020-10-19 22:16:24 +02:00
|
|
|
import 'bootstrap-datepicker';
|
2020-10-22 23:56:09 +02:00
|
|
|
import '../node_modules/bootstrap-toggle/css/bootstrap-toggle.css';
|
|
|
|
import '../node_modules/bootstrap-toggle/js/bootstrap-toggle.js';
|
2020-10-19 22:16:24 +02:00
|
|
|
import '../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css';
|
|
|
|
import 'time-input-polyfill/auto';
|
2020-11-05 00:08:54 +01:00
|
|
|
import 'jquery-pjax';
|
|
|
|
|
2020-11-27 23:53:14 +01:00
|
|
|
console.log("Commit: "+process.env.GIT_VERSION);
|
|
|
|
console.log("Date: "+process.env.GIT_AUTHOR_DATE);
|
|
|
|
console.log("Bundle mode: "+process.env.BUNDLE_MODE);
|
|
|
|
console.log("Bundle date: "+process.env.BUNDLE_DATE);
|
|
|
|
|
2020-11-13 22:38:52 +01:00
|
|
|
$(document).pjax('a:not(.pjax_disable)', '#content', {timeout: 100000});
|
2020-11-05 00:08:54 +01:00
|
|
|
$(document).on('pjax:start', function() {
|
|
|
|
if(window.loadTable_interval !== undefined){
|
|
|
|
clearInterval(window.loadTable_interval);
|
|
|
|
window.loadTable_interval = undefined;
|
|
|
|
}
|
|
|
|
})
|
2020-09-13 00:56:56 +02:00
|
|
|
|
2020-10-27 01:15:23 +01:00
|
|
|
// Cookie functions from w3schools
|
|
|
|
function setCookie(cname, cvalue, exdays) {
|
|
|
|
var d = new Date();
|
|
|
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
|
|
var expires = "expires=" + d.toUTCString();
|
|
|
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
|
|
|
}
|
|
|
|
function getCookie(cname) {
|
|
|
|
var name = cname + "=";
|
|
|
|
var decodedCookie = decodeURIComponent(document.cookie);
|
|
|
|
var ca = decodedCookie.split(';');
|
|
|
|
for (var i = 0; i < ca.length; i++) {
|
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0) === ' ') {
|
|
|
|
c = c.substring(1);
|
|
|
|
}
|
|
|
|
if (c.indexOf(name) === 0) {
|
|
|
|
return c.substring(name.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-10-18 00:22:11 +02:00
|
|
|
$( document ).ajaxError(function(event, xhr, settings, error) {
|
|
|
|
console.error("Error requesting content: "+error+" - status code "+xhr.status);
|
|
|
|
console.log(event);
|
|
|
|
console.log(xhr);
|
|
|
|
console.log(settings);
|
|
|
|
});
|
|
|
|
|
2020-10-27 01:15:23 +01:00
|
|
|
if (getCookie("authenticated")) {
|
|
|
|
if ('serviceWorker' in navigator) {
|
2020-10-09 14:35:20 +02:00
|
|
|
window.addEventListener('load', () => {
|
2020-11-05 00:08:54 +01:00
|
|
|
navigator.serviceWorker.register('sw.js').then(registration => {
|
2020-10-11 00:33:42 +02:00
|
|
|
console.log('SW registered: ', registration);
|
|
|
|
}).catch(registrationError => {
|
|
|
|
console.log('SW registration failed: ', registrationError);
|
|
|
|
});
|
2020-10-09 14:35:20 +02:00
|
|
|
});
|
2020-10-27 01:15:23 +01:00
|
|
|
}
|
2020-10-18 00:22:11 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:22:26 +01:00
|
|
|
function fillTable(data, replaceLatLngWithMap=false){
|
2020-10-24 00:17:01 +02:00
|
|
|
$("#table_body").empty();
|
2020-11-13 15:22:26 +01:00
|
|
|
$.each(data, function(row_num, item) {
|
|
|
|
let row = document.createElement("tr");
|
2020-11-21 21:41:37 +01:00
|
|
|
row.id = "row-"+row_num;
|
2020-11-13 15:22:26 +01:00
|
|
|
$.each(item, function(cell_num, i) {
|
2020-10-24 00:17:01 +02:00
|
|
|
if(i !== null){
|
2020-11-13 15:22:26 +01:00
|
|
|
if(replaceLatLngWithMap && i.match(/[+-]?\d+([.]\d+)?[;][+-]?\d+([.]\d+)?/gm)){
|
|
|
|
let lat = i.split(";")[0];
|
|
|
|
let lng = i.split(";")[1];
|
|
|
|
let mapDiv = document.createElement("div");
|
|
|
|
mapDiv.className = "map";
|
|
|
|
mapDiv.id = "map-"+row_num;
|
|
|
|
var mapScript = document.createElement("script");
|
|
|
|
mapScript.appendChild(document.createTextNode("load_map("+lat+", "+lng+", \"map-"+row_num+"\", false)"));
|
|
|
|
mapDiv.appendChild(mapScript);
|
|
|
|
let cell = document.createElement("td");
|
|
|
|
cell.appendChild(mapDiv);
|
|
|
|
row.appendChild(cell);
|
|
|
|
} else {
|
|
|
|
let cell = document.createElement("td");
|
|
|
|
cell.innerHTML = i;
|
|
|
|
row.appendChild(cell);
|
|
|
|
}
|
2020-10-24 00:17:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
document.getElementById("table_body").appendChild(row);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-25 21:22:32 +01:00
|
|
|
var offline = false;
|
2020-11-05 00:08:54 +01:00
|
|
|
var loadTable_interval = undefined;
|
2020-12-17 00:06:08 +01:00
|
|
|
var old_data = "null";
|
2020-11-06 15:14:59 +01:00
|
|
|
function loadTable(table_page, set_interval=true, interval=10000, onlineReload=false){
|
2020-11-13 15:22:26 +01:00
|
|
|
let replaceLatLngWithMap = table_page == "services" || table_page == "trainings";
|
2020-12-17 00:06:08 +01:00
|
|
|
$.getJSON({ url: "resources/ajax/ajax_"+table_page+".php", data: { "old_data": old_data }, success: function( data, status, xhr ) {
|
|
|
|
old_data = xhr.getResponseHeader('data'); //TODO: refactoring and adding comments
|
|
|
|
console.log(data);
|
|
|
|
if(data.length > 0){
|
|
|
|
fillTable(data, replaceLatLngWithMap);
|
|
|
|
var headers = new Headers();
|
|
|
|
headers.append('date', Date.now());
|
|
|
|
caches.open('tables-1').then((cache) => {
|
|
|
|
cache.put('/table_'+table_page+'.json', new Response(xhr.responseText, {headers: headers}))
|
|
|
|
});
|
|
|
|
}
|
2020-11-06 14:22:37 +01:00
|
|
|
if(window.offline){ // if xhr request successful, client is online
|
2020-11-06 15:14:59 +01:00
|
|
|
console.log(onlineReload);
|
|
|
|
if(onlineReload){
|
|
|
|
location.reload(); //for offline page
|
|
|
|
} else {
|
|
|
|
$("#offline_alert").hide(400);
|
|
|
|
window.offline = false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 00:06:08 +01:00
|
|
|
}}).fail(function(data, status) {
|
2020-11-06 14:22:37 +01:00
|
|
|
if(status == "parsererror"){
|
2020-11-13 15:22:26 +01:00
|
|
|
if($("#table_body").children().length == 0) { //this is a server-side authentication error on some cheap hosting providers
|
|
|
|
loadTable(table_page, set_interval, interval); //retry
|
2020-11-06 14:22:37 +01:00
|
|
|
} // else nothing
|
|
|
|
} else {
|
2020-10-24 00:17:01 +02:00
|
|
|
caches.open('tables-1').then(cache => {
|
|
|
|
cache.match("/table_"+table_page+".json").then(response => {
|
|
|
|
response.json().then(data => {
|
2020-11-13 15:22:26 +01:00
|
|
|
fillTable(data, replaceLatLngWithMap);
|
2020-10-24 00:17:01 +02:00
|
|
|
console.log("Table loaded from cache");
|
2020-10-25 21:22:32 +01:00
|
|
|
$("#offline_update").text(new Date(parseInt(response.headers.get("date"))).toLocaleString());
|
2020-10-18 00:22:11 +02:00
|
|
|
});
|
|
|
|
});
|
2020-10-24 00:17:01 +02:00
|
|
|
});
|
2020-10-25 21:22:32 +01:00
|
|
|
if(!window.offline){ // if xhr request fails, client is offline
|
|
|
|
$("#offline_alert").show(400);
|
|
|
|
window.offline = true;
|
|
|
|
}
|
2020-11-05 00:08:54 +01:00
|
|
|
}
|
2020-11-06 14:22:37 +01:00
|
|
|
});
|
|
|
|
if(set_interval){
|
|
|
|
window.loadTable_interval = setInterval(function() {
|
2020-11-06 15:14:59 +01:00
|
|
|
window.loadTable(table_page, false, interval, onlineReload);
|
2020-11-06 14:22:37 +01:00
|
|
|
}, interval);
|
|
|
|
}
|
2020-10-18 00:22:11 +02:00
|
|
|
}
|
2020-11-06 14:22:37 +01:00
|
|
|
|
2020-11-14 23:00:36 +01:00
|
|
|
function chat() {
|
|
|
|
setCookie("chat", "true", 1);
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('securitypolicyviolation',console.error.bind(console));
|
|
|
|
|
|
|
|
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
|
|
|
|
function menu() {
|
|
|
|
var x = document.getElementById("myTopnav");
|
|
|
|
//var z = document.getElementById("logout");
|
|
|
|
if (x.className === "topnav") {
|
|
|
|
x.className += " responsive";
|
|
|
|
//z.className = " logout_sx";
|
|
|
|
} else {
|
|
|
|
x.className = "topnav";
|
|
|
|
//z.className = " logout_dx";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 00:08:54 +01:00
|
|
|
window.loadTable_interval = loadTable_interval;
|
2020-10-24 00:17:01 +02:00
|
|
|
window.fillTable = fillTable;
|
2020-11-13 15:22:26 +01:00
|
|
|
window.loadTable = loadTable;
|
|
|
|
window.setCookie = setCookie;
|
2020-11-14 23:00:36 +01:00
|
|
|
window.getCookie = getCookie;
|
|
|
|
window.chat = chat;
|
|
|
|
window.menu = menu;
|