Better logging
This commit is contained in:
@@ -6,14 +6,14 @@
|
||||
|
||||
?>
|
||||
|
||||
log('Script "custom.js" loaded');
|
||||
log('[tpl] Script "custom.js" loaded');
|
||||
|
||||
var loaderCount = 2;
|
||||
var showLoader = function() {
|
||||
if (loaderCount < 1) {
|
||||
$('#preloader').removeClass('preloader-hide');
|
||||
loaderCount = 0;
|
||||
log('Loader shown');
|
||||
log('[tpl] Loader shown');
|
||||
}
|
||||
loaderCount ++;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ var hideLoader = function() {
|
||||
if (loaderCount < 1) {
|
||||
$('#preloader').addClass('preloader-hide');
|
||||
loaderCount = 0;
|
||||
log('Loader hidden');
|
||||
log('[tpl] Loader hidden');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ function eraseCookie(e) {createCookie(e, "", -1)}
|
||||
$(document).ready(function(){
|
||||
'use strict'
|
||||
|
||||
log('Document ready');
|
||||
log('[tpl] Document ready');
|
||||
|
||||
function init_template(){
|
||||
|
||||
log('Initializing template...');
|
||||
log('[tpl] Initializing template...');
|
||||
|
||||
//ADD YOUR CUSTOM JAVASCRIPT CODES HERE!
|
||||
//Do not put inside HTML files.
|
||||
@@ -111,21 +111,23 @@ $(document).ready(function(){
|
||||
//Disable Page Jump on Empty Links.
|
||||
$('a').on('click', function(){var attrs = $(this).attr('href'); if(attrs === '#'){return false;}});
|
||||
|
||||
log('[tpl] init menus');
|
||||
|
||||
//Adding Background for Gradient
|
||||
if(!$('.menu-hider').length){$('#page').append('<div class="menu-hider"><div>');}
|
||||
|
||||
var menuOpened = function() {
|
||||
log('Menu opened', history.state);
|
||||
log('[tpl] Menu opened', history.state);
|
||||
if ((history.state === null) || (history.state.menu !== 'opened')) {
|
||||
history.pushState({ menu: 'opened' }, '');
|
||||
log('state pushed');
|
||||
log('[tpl] state pushed');
|
||||
}
|
||||
}
|
||||
var menuClosed = function() {
|
||||
log('Menu closed', history.state);
|
||||
log('[tpl] Menu closed', history.state);
|
||||
if ((history.state !== null) && (history.state.menu === 'opened')) {
|
||||
history.back();
|
||||
log('history.back')
|
||||
log('[tpl] history.back')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ $(document).ready(function(){
|
||||
$.fn.hideMenu = function() {$(this).removeClass('menu-active'); $('#footer-bar').removeClass('footer-menu-hidden');$('.menu-hider').removeClass('menu-active menu-active-clear');$('body').removeClass('modal-open');menuClosed();};
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
log('popstate event fired. location:' + document.location + ', state:' + JSON.stringify(event.state));
|
||||
log('[tpl] popstate event fired. location:' + document.location + ', state:' + JSON.stringify(event.state));
|
||||
if ((event.state === null) || (event.state.menu !== 'opened')) {
|
||||
$('.menu').hideMenu();
|
||||
}
|
||||
@@ -215,6 +217,8 @@ $(document).ready(function(){
|
||||
return false;
|
||||
});
|
||||
|
||||
log('[tpl] init dark mode');
|
||||
|
||||
//Disabling & Enabling Dark Transitions in Dark Mode to Speed up Performance.
|
||||
function allowTransitions(){$('body').find('#transitions-remove').remove();}
|
||||
function removeTransitions(){$('body').append('<style id="transitions-remove">.btn, .header, #footer-bar, .menu-box, .menu-active{transition:all 0ms ease!important;}</style>'); setTimeout(function(){allowTransitions();},10);}
|
||||
@@ -264,6 +268,9 @@ $(document).ready(function(){
|
||||
eraseCookie('sticky_light_mode');
|
||||
eraseCookie('sticky_dark_mode');
|
||||
// END
|
||||
|
||||
log('[tpl] init other ui elements');
|
||||
|
||||
//Footer Menu Active Elements
|
||||
if($('.footer-bar-2, .footer-bar-4, .footer-bar-5').length){
|
||||
if(!$('.footer-bar-2 strong, .footer-bar-4 strong, .footer-bar-5 strong').length){
|
||||
@@ -278,6 +285,8 @@ eraseCookie('sticky_dark_mode');
|
||||
//return false;
|
||||
});
|
||||
|
||||
log('[tpl] detect mobile os');
|
||||
|
||||
//Detect Mobile OS//
|
||||
var isMobile = {
|
||||
Android: function() {return navigator.userAgent.match(/Android/i);},
|
||||
@@ -302,6 +311,7 @@ eraseCookie('sticky_dark_mode');
|
||||
$('.show-android, .show-no-device, .simulate-android, .simulate-iphones').addClass('disabled');
|
||||
}
|
||||
|
||||
log('[tpl] init toasts');
|
||||
|
||||
//Toast, Snackbars and Notifications
|
||||
$('[data-toast]').on('click',function(){
|
||||
@@ -314,6 +324,7 @@ eraseCookie('sticky_dark_mode');
|
||||
$('#'+thisData).toast('hide');
|
||||
});
|
||||
|
||||
log('[tpl] init switches');
|
||||
|
||||
//Switches
|
||||
$('.ios-input, .android-input, .classic-input').on('click',function(){
|
||||
@@ -335,6 +346,8 @@ eraseCookie('sticky_dark_mode');
|
||||
}
|
||||
})
|
||||
|
||||
log('[tpl] init a2h');
|
||||
|
||||
//Adding added-to-homescreen class to be targeted when used as PWA.
|
||||
function ath(){
|
||||
(function(a, b, c) {
|
||||
@@ -360,6 +373,8 @@ eraseCookie('sticky_dark_mode');
|
||||
$('.simulate-android-banner').on('click',function(){$('#menu-install-pwa-android, .menu-hider').addClass('menu-active')})
|
||||
$('.simulate-ios-banner').on('click',function(){$('#menu-install-pwa-ios, .menu-hider').addClass('menu-active')})
|
||||
|
||||
log('[tpl] init offline alerts');
|
||||
|
||||
//Adding Offline Alerts
|
||||
var offlineAlerts = $('.offline-message');
|
||||
if(!offlineAlerts.length){
|
||||
@@ -385,15 +400,17 @@ eraseCookie('sticky_dark_mode');
|
||||
function updateOnlineStatus(event) {
|
||||
var condition = navigator.onLine ? "online" : "offline";
|
||||
isOnline();
|
||||
log( 'Connection: Online');
|
||||
log('[tpl] Connection: Online');
|
||||
}
|
||||
function updateOfflineStatus(event) {
|
||||
isOffline();
|
||||
log( 'Connection: Offline');
|
||||
log('[tpl] Connection: Offline');
|
||||
}
|
||||
window.addEventListener('online', updateOnlineStatus);
|
||||
window.addEventListener('offline', updateOfflineStatus);
|
||||
|
||||
log('[tpl] init share buttons');
|
||||
|
||||
//Sharing
|
||||
var share_link = window.location.href;
|
||||
var share_title = document.title;
|
||||
@@ -404,10 +421,7 @@ eraseCookie('sticky_dark_mode');
|
||||
$('.shareToWhatsApp').prop("href", "whatsapp://send?text=" + share_link)
|
||||
$('.shareToMail').prop("href", "mailto:?body=" + share_link)
|
||||
|
||||
|
||||
//Preload Image
|
||||
var preloadImages = $('.preload-img');
|
||||
$(function() {preloadImages.lazyload({threshold : 500});});
|
||||
log('[tpl] init colors');
|
||||
|
||||
//Style Generator
|
||||
var generatedStyles = $('.generated-styles');
|
||||
@@ -424,12 +438,11 @@ eraseCookie('sticky_dark_mode');
|
||||
}
|
||||
}
|
||||
|
||||
function highlight_colors(){
|
||||
var bodyColor = readCookie('sticky-color-scheme')
|
||||
if(bodyColor == undefined){var bodyColor = $('body').data('highlight');}
|
||||
log('[tpl] init highlight colors');
|
||||
|
||||
var bodyBackground = readCookie('sticky-bg-scheme')
|
||||
if(bodyBackground == undefined){var bodyBackground = $('body').data('background');}
|
||||
function highlight_colors(){
|
||||
var bodyColor = $('body').data('highlight');
|
||||
var bodyBackground = $('body').data('background');
|
||||
|
||||
var data = colorsArray.map(colorsArray => colorsArray[0]);
|
||||
if (data.indexOf(bodyColor) > -1) {
|
||||
@@ -453,15 +466,21 @@ eraseCookie('sticky_dark_mode');
|
||||
}
|
||||
highlight_colors();
|
||||
|
||||
if (!generatedStyles.length){
|
||||
$('body').append('<style class="generated-styles"></style>');
|
||||
$('.generated-styles').append('/*Generated using JS for lower CSS file Size, Easier Editing & Faster Loading*/');
|
||||
colorsArray.forEach(function (colorValue) {$('.generated-styles').append('.bg-'+colorValue[0]+'-light{ background-color: '+colorValue[1]+'!important; color:#FFFFFF!important;} .bg-'+colorValue[0]+'-light i, .bg-'+colorValue[0]+'-dark i{color:#FFFFFF;} .bg-'+colorValue[0]+'-dark{ background-color: '+colorValue[2]+'!important; color:#FFFFFF!important;} .border-'+colorValue[0]+'-light{ border-color:'+colorValue[1]+'!important;} .border-'+colorValue[0]+'-dark{ border-color:'+colorValue[2]+'!important;} .color-'+colorValue[0]+'-light{ color: '+colorValue[1]+'!important;} .color-'+colorValue[0]+'-dark{ color: '+colorValue[2]+'!important;}');});
|
||||
colorsArray.forEach(function (colorFadeValue) {$('.generated-styles').append('.bg-fade-'+colorFadeValue[0]+'-light{ background-color: '+ HEXtoRGBA(colorFadeValue[1]) + '!important; color:#FFFFFF;} .bg-fade-'+colorFadeValue[0]+'-light i, .bg-'+colorFadeValue[0]+'-dark i{color:#FFFFFF;} .bg-fade-'+colorFadeValue[0]+'-dark{ background-color: '+HEXtoRGBA(colorFadeValue[2])+'!important; color:#FFFFFF;} .border-fade-'+colorFadeValue[0]+'-light{ border-color:'+HEXtoRGBA(colorFadeValue[1])+'!important;} .border-fade-'+colorFadeValue[0]+'-dark{ border-color:'+HEXtoRGBA(colorFadeValue[2])+'!important;} .color-fade-'+colorFadeValue[0]+'-light{ color: '+HEXtoRGBA(colorFadeValue[1])+'!important;} .color-fade-'+colorFadeValue[0]+'-dark{ color: '+HEXtoRGBA(colorFadeValue[2])+'!important;}');});
|
||||
colorsArray.forEach(function (gradientValue) {$('.generated-styles').append('.bg-gradient-'+gradientValue[0]+'{background-image: linear-gradient(to bottom, '+gradientValue[1]+' 0, '+gradientValue[2]+' 100%)}')});
|
||||
socialColorArray.forEach(function (socialColorValue) {$('.generated-styles').append('.bg-'+socialColorValue[0]+'{background-color:'+socialColorValue[1]+'!important; color:#FFFFFF;} .color-'+socialColorValue[0]+'{color:'+socialColorValue[1]+'!important;}')});
|
||||
colorsArray.forEach(function (gradientBodyValue) {$('.generated-styles').append('.body-'+gradientBodyValue[0]+'{background-image: linear-gradient(to bottom, '+gradientBodyValue[1]+' 0, '+gradientBodyValue[3]+' 100%)}')});
|
||||
}
|
||||
setTimeout(function(){
|
||||
log('[tpl] init other colors');
|
||||
if (!generatedStyles.length){
|
||||
$('body').append('<style class="generated-styles"></style>');
|
||||
$('.generated-styles').append('/*Generated using JS for lower CSS file Size, Easier Editing & Faster Loading*/');
|
||||
colorsArray.forEach(function (colorValue) {$('.generated-styles').append('.bg-'+colorValue[0]+'-light{ background-color: '+colorValue[1]+'!important; color:#FFFFFF!important;} .bg-'+colorValue[0]+'-light i, .bg-'+colorValue[0]+'-dark i{color:#FFFFFF;} .bg-'+colorValue[0]+'-dark{ background-color: '+colorValue[2]+'!important; color:#FFFFFF!important;} .border-'+colorValue[0]+'-light{ border-color:'+colorValue[1]+'!important;} .border-'+colorValue[0]+'-dark{ border-color:'+colorValue[2]+'!important;} .color-'+colorValue[0]+'-light{ color: '+colorValue[1]+'!important;} .color-'+colorValue[0]+'-dark{ color: '+colorValue[2]+'!important;}');});
|
||||
colorsArray.forEach(function (colorFadeValue) {$('.generated-styles').append('.bg-fade-'+colorFadeValue[0]+'-light{ background-color: '+ HEXtoRGBA(colorFadeValue[1]) + '!important; color:#FFFFFF;} .bg-fade-'+colorFadeValue[0]+'-light i, .bg-'+colorFadeValue[0]+'-dark i{color:#FFFFFF;} .bg-fade-'+colorFadeValue[0]+'-dark{ background-color: '+HEXtoRGBA(colorFadeValue[2])+'!important; color:#FFFFFF;} .border-fade-'+colorFadeValue[0]+'-light{ border-color:'+HEXtoRGBA(colorFadeValue[1])+'!important;} .border-fade-'+colorFadeValue[0]+'-dark{ border-color:'+HEXtoRGBA(colorFadeValue[2])+'!important;} .color-fade-'+colorFadeValue[0]+'-light{ color: '+HEXtoRGBA(colorFadeValue[1])+'!important;} .color-fade-'+colorFadeValue[0]+'-dark{ color: '+HEXtoRGBA(colorFadeValue[2])+'!important;}');});
|
||||
colorsArray.forEach(function (gradientValue) {$('.generated-styles').append('.bg-gradient-'+gradientValue[0]+'{background-image: linear-gradient(to bottom, '+gradientValue[1]+' 0, '+gradientValue[2]+' 100%)}')});
|
||||
socialColorArray.forEach(function (socialColorValue) {$('.generated-styles').append('.bg-'+socialColorValue[0]+'{background-color:'+socialColorValue[1]+'!important; color:#FFFFFF;} .color-'+socialColorValue[0]+'{color:'+socialColorValue[1]+'!important;}')});
|
||||
colorsArray.forEach(function (gradientBodyValue) {$('.generated-styles').append('.body-'+gradientBodyValue[0]+'{background-image: linear-gradient(to bottom, '+gradientBodyValue[1]+' 0, '+gradientBodyValue[3]+' 100%)}')});
|
||||
}
|
||||
log('[tpl] other colors initialized');
|
||||
},0);
|
||||
|
||||
log('[tpl] init welcome banner');
|
||||
|
||||
function welcomeOk() {
|
||||
createCookie('sticky_welcome_banner', true, 1);
|
||||
@@ -477,8 +496,8 @@ eraseCookie('sticky_dark_mode');
|
||||
$('#menu-welcome-a-okay').click(welcomeOk);
|
||||
showWelcome();
|
||||
|
||||
log('Template initialized');
|
||||
log('Initializing app');
|
||||
log('[tpl] Template initialized');
|
||||
log('[tpl] Initializing app');
|
||||
|
||||
initRegatten();
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ var getJSON = function(url, callback) {
|
||||
callback(xhr.status, xhr.response);
|
||||
};
|
||||
xhr.ontimeout = function () {
|
||||
log("getJSON: timeout");
|
||||
log("[db] getJSON: timeout");
|
||||
callback(0, null);
|
||||
}
|
||||
xhr.onerror = function () {
|
||||
log("getJSON: error");
|
||||
log("[db] getJSON: error");
|
||||
callback(0, null);
|
||||
}
|
||||
if (USER_ID != null) {
|
||||
@@ -76,7 +76,7 @@ function dbGetData(table, id = null) {
|
||||
if (code == 200) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
log("Something went wrong (HTTP " + code + ")");
|
||||
log("[db] Something went wrong (HTTP " + code + ")");
|
||||
fail(strings.error_network, 5000);
|
||||
resolve([]);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ function dbGetData(table, id = null) {
|
||||
if (code == 200) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
log("Something went wrong (HTTP " + code + ")");
|
||||
log("[db] Something went wrong (HTTP " + code + ")");
|
||||
fail(strings.error_network, 5000);
|
||||
resolve(null);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ function dbGetDataIndex(table, indexName, value) {
|
||||
if (code == 200) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
log("Something went wrong (HTTP " + code + ")");
|
||||
log("[db] Something went wrong (HTTP " + code + ")");
|
||||
fail(strings.error_network, 5000);
|
||||
resolve([]);
|
||||
}
|
||||
@@ -445,7 +445,7 @@ async function updateSyncStatus() {
|
||||
}
|
||||
|
||||
async function runPageScript() {
|
||||
log('running page script...')
|
||||
log('[db] running page script...')
|
||||
if (canUseLocalDB) {
|
||||
var osUpdateTimes = db.transaction('update_times').objectStore('update_times');
|
||||
osUpdateTimes.get('loggedin').onsuccess = function (event) {
|
||||
@@ -474,10 +474,10 @@ async function runPageScript() {
|
||||
}
|
||||
|
||||
if (typeof siteScript === 'function') {
|
||||
log('loading site script');
|
||||
log('[db] loading site script');
|
||||
siteScript();
|
||||
} else {
|
||||
log('no site script');
|
||||
log('[db] no site script');
|
||||
hideLoader();
|
||||
}
|
||||
}
|
||||
@@ -497,7 +497,7 @@ function sync() {
|
||||
|
||||
syncInProgress = 11;
|
||||
var syncOkay = true;
|
||||
log("Sync Start");
|
||||
log("[db] Sync Start");
|
||||
$('#i-sync').addClass('fa-spin');
|
||||
|
||||
var interval = window.setInterval(function () {
|
||||
@@ -507,7 +507,7 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'last_sync', time: now });
|
||||
}
|
||||
log("Sync Stop");
|
||||
log("[db] Sync Stop");
|
||||
setTimeout(function(){
|
||||
$('#i-sync').removeClass('fa-spin');
|
||||
}, 500);
|
||||
@@ -544,14 +544,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'clubs', time: serverTimes['clubs'] });
|
||||
syncInProgress --;
|
||||
log('clubs synced, remaining:', syncInProgress);
|
||||
log('[db] clubs synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("clubs: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] clubs: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('clubs failed, remaining:', syncInProgress);
|
||||
log('[db] clubs failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -577,14 +577,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'boats', time: serverTimes['boats'] });
|
||||
syncInProgress --;
|
||||
log('boats synced, remaining:', syncInProgress);
|
||||
log('[db] boats synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("boats: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] boats: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('boats failed, remaining:', syncInProgress);
|
||||
log('[db] boats failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -610,14 +610,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'sailors', time: serverTimes['sailors'] });
|
||||
syncInProgress --;
|
||||
log('sailors synced, remaining:', syncInProgress);
|
||||
log('[db] sailors synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("sailors: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] sailors: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('sailors failed, remaining:', syncInProgress);
|
||||
log('[db] sailors failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -659,14 +659,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] });
|
||||
syncInProgress --;
|
||||
log('regattas synced, remaining:', syncInProgress);
|
||||
log('[db] regattas synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("regattas: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] regattas: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('regattas failed, remaining:', syncInProgress);
|
||||
log('[db] regattas failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -692,14 +692,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'results', time: serverTimes['results'] });
|
||||
syncInProgress --;
|
||||
log('results synced, remaining:', syncInProgress);
|
||||
log('[db] results synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("results: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] results: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('results failed, remaining:', syncInProgress);
|
||||
log('[db] results failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -725,14 +725,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'plannings', time: serverTimes['plannings'] });
|
||||
syncInProgress --;
|
||||
log('plannings synced, remaining:', syncInProgress);
|
||||
log('[db] plannings synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("plannings: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] plannings: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('plannings failed, remaining:', syncInProgress);
|
||||
log('[db] plannings failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -759,14 +759,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'trim_boats', time: serverTimes['trim_boats'] });
|
||||
syncInProgress --;
|
||||
log('trim_boats synced, remaining:', syncInProgress);
|
||||
log('[db] trim_boats synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("trim_boats: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] trim_boats: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('trim_boats failed, remaining:', syncInProgress);
|
||||
log('[db] trim_boats failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -792,14 +792,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'trim_users', time: serverTimes['trim_users'] });
|
||||
syncInProgress --;
|
||||
log('trim_users synced, remaining:', syncInProgress);
|
||||
log('[db] trim_users synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("trim_users: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] trim_users: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('trim_users failed, remaining:', syncInProgress);
|
||||
log('[db] trim_users failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -825,14 +825,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'trim_trims', time: serverTimes['trim_trims'] });
|
||||
syncInProgress --;
|
||||
log('trim_trims synced, remaining:', syncInProgress);
|
||||
log('[db] trim_trims synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("trim_trims: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] trim_trims: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('trim_trims failed, remaining:', syncInProgress);
|
||||
log('[db] trim_trims failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -862,14 +862,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'news', time: serverTimes['news'] });
|
||||
syncInProgress --;
|
||||
log('news synced, remaining:', syncInProgress);
|
||||
log('[db] news synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("news: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] news: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('news failed, remaining:', syncInProgress);
|
||||
log('[db] news failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -895,14 +895,14 @@ function sync() {
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'users', time: serverTimes['users'] });
|
||||
syncInProgress --;
|
||||
log('users synced, remaining:', syncInProgress);
|
||||
log('[db] users synced, remaining:', syncInProgress);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
log("users: Something went wrong (HTTP " + code + ")");
|
||||
log("[db] users: Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress --;
|
||||
log('users failed, remaining:', syncInProgress);
|
||||
log('[db] users failed, remaining:', syncInProgress);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -910,7 +910,7 @@ function sync() {
|
||||
}
|
||||
|
||||
} else {
|
||||
log("Something went wrong (HTTP " + code + ")");
|
||||
log("[db] Something went wrong (HTTP " + code + ")");
|
||||
syncOkay = false;
|
||||
syncInProgress = 0;
|
||||
}
|
||||
@@ -932,18 +932,18 @@ function checkSync() {
|
||||
}
|
||||
|
||||
function initDatabase() {
|
||||
log('Initializing DB...');
|
||||
log('[db] Initializing DB...');
|
||||
if (window.indexedDB) {
|
||||
var request = window.indexedDB.open('regatten_app_db_' + BOATCLASS, DB_VERSION);
|
||||
request.onerror = function (event) {
|
||||
log("Cannot open DB: " + event.target);
|
||||
log("[db] Cannot open DB: " + event.target);
|
||||
|
||||
if (typeof onDatabaseLoaded == 'function') onDatabaseLoaded();
|
||||
|
||||
runPageScript();
|
||||
};
|
||||
request.onsuccess = function (event) {
|
||||
log("Database loaded");
|
||||
log("[db] Database loaded");
|
||||
db = event.target.result;
|
||||
|
||||
db.onversionchange = function (event) {
|
||||
@@ -956,7 +956,7 @@ function initDatabase() {
|
||||
}
|
||||
|
||||
db.onerror = function (event) {
|
||||
log("DB Error: " + event.target);
|
||||
log("[db] DB Error: " + event.target);
|
||||
};
|
||||
|
||||
canUseLocalDB = true;
|
||||
@@ -987,10 +987,10 @@ function initDatabase() {
|
||||
var oldVersion = event.oldVersion;
|
||||
var newVersion = event.newVersion;
|
||||
|
||||
log("Datenbank Version Upgrade von " + oldVersion + " auf " + newVersion);
|
||||
log("[db] DB Version Upgrade from " + oldVersion + " to " + newVersion);
|
||||
|
||||
if ((oldVersion < 1) && (newVersion >= 1)) {
|
||||
log('to version 1');
|
||||
log('[db] to version 1');
|
||||
var osClubs = db.createObjectStore('clubs', { keyPath: 'id' });
|
||||
var osBoats = db.createObjectStore('boats', { keyPath: 'id' });
|
||||
var osSailors = db.createObjectStore('sailors', { keyPath: 'id' });
|
||||
@@ -1019,7 +1019,7 @@ function initDatabase() {
|
||||
}
|
||||
|
||||
if ((oldVersion < 2) && (newVersion >= 2)) {
|
||||
log('to version 2');
|
||||
log('[db] to version 2');
|
||||
var osUsers = db.createObjectStore('users', { keyPath: 'id' });
|
||||
osUsers.createIndex('username', 'username', { unique: true });
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
@@ -1027,25 +1027,25 @@ function initDatabase() {
|
||||
}
|
||||
|
||||
if ((oldVersion < 3) && (newVersion >= 3)) {
|
||||
log('to version 3');
|
||||
log('[db] to version 3');
|
||||
var osYears = db.createObjectStore('years', { keyPath: 'year' });
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'regattas', time: 0 });
|
||||
}
|
||||
|
||||
if ((oldVersion < 4) && (newVersion >= 4)) {
|
||||
log('to version 4');
|
||||
log('[db] to version 4');
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
osUpdateTimes.add({ table: 'loggedin', status: isLoggedIn() });
|
||||
}
|
||||
|
||||
if ((oldVersion < 5) && (newVersion >= 5)) {
|
||||
log('to version 5');
|
||||
log('[db] to version 5');
|
||||
var osPushes = db.createObjectStore('settings', { keyPath: 'key' });
|
||||
}
|
||||
|
||||
if ((oldVersion < 6) && (newVersion >= 6)) {
|
||||
log('to version 6');
|
||||
log('[db] to version 6');
|
||||
var osNews = db.createObjectStore('news', { keyPath: 'id' });
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
osUpdateTimes.add({ table: 'news', time: 0 });
|
||||
@@ -1080,7 +1080,7 @@ function resetDb() {
|
||||
osUpdateTimes.put({ table: 'trim_trims', time: 0 });
|
||||
osUpdateTimes.put({ table: 'news', time: 0 });
|
||||
osUpdateTimes.put({ table: 'users', time: 0 });
|
||||
log('DB update times reset');
|
||||
log('[db] DB update times reset');
|
||||
hideLoader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ $(document).ready(function(){
|
||||
//Enabling dismiss button
|
||||
setTimeout(function(){
|
||||
$('.pwa-dismiss').on('click',function(){
|
||||
log('User Closed Add to Home / PWA Prompt')
|
||||
log('[pwa] User Closed Add to Home / PWA Prompt')
|
||||
createCookie('Sticky_pwa_rejected_install', true, 1);
|
||||
$('body').find('#menu-install-pwa-android, #menu-install-pwa-ios, .menu-hider').removeClass('menu-active');
|
||||
});
|
||||
@@ -50,10 +50,10 @@ $(document).ready(function(){
|
||||
|
||||
//Firing PWA prompts for specific versions and when not on home screen.
|
||||
if (isMobile.Android()) {
|
||||
log('Android Detected');
|
||||
log('[pwa] Android Detected');
|
||||
function showInstallPromotion(){
|
||||
if($('#menu-install-pwa-android, .add-to-home').length){
|
||||
log('Triggering PWA Menu for Android');
|
||||
log('[pwa] Triggering PWA Menu for Android');
|
||||
if (!readCookie('Sticky_pwa_rejected_install')) {
|
||||
setTimeout(function(){
|
||||
$('.add-to-home').addClass('add-to-home-visible add-to-home-android');
|
||||
@@ -78,9 +78,9 @@ $(document).ready(function(){
|
||||
deferredPrompt.userChoice
|
||||
.then((choiceResult) => {
|
||||
if (choiceResult.outcome === 'accepted') {
|
||||
log('User accepted the A2HS prompt');
|
||||
log('[pwa] User accepted the A2HS prompt');
|
||||
} else {
|
||||
log('User dismissed the A2HS prompt');
|
||||
log('[pwa] User dismissed the A2HS prompt');
|
||||
}
|
||||
deferredPrompt = null;
|
||||
});
|
||||
@@ -92,11 +92,11 @@ $(document).ready(function(){
|
||||
|
||||
if (isMobile.iOS()) {
|
||||
if(!isInWebAppiOS){
|
||||
log('iOS Detected');
|
||||
log('[pwa] iOS Detected');
|
||||
if($('#menu-install-pwa-ios, .add-to-home').length){
|
||||
if (!readCookie('Sticky_pwa_rejected_install')) {
|
||||
function triggerPwaInstallIos() {
|
||||
log('Triggering PWA / Add to Home Screen Menu for iOS');
|
||||
log('[pwa] Triggering PWA / Add to Home Screen Menu for iOS');
|
||||
setTimeout(function(){
|
||||
$('.add-to-home').addClass('add-to-home-visible add-to-home-ios');
|
||||
$('#menu-install-pwa-ios, .menu-hider').addClass('menu-active');
|
||||
@@ -144,11 +144,11 @@ $(document).ready(function(){
|
||||
function updateOnlineStatus(event) {
|
||||
var condition = navigator.onLine ? "online" : "offline";
|
||||
isOnline();
|
||||
log( 'Connection: Online');
|
||||
log('[pwa] Connection: Online');
|
||||
}
|
||||
function updateOfflineStatus(event) {
|
||||
isOffline();
|
||||
log( 'Connection: Offline');
|
||||
log('[pwa] Connection: Offline');
|
||||
}
|
||||
window.addEventListener('online', updateOnlineStatus);
|
||||
window.addEventListener('offline', updateOfflineStatus);
|
||||
|
||||
@@ -153,7 +153,7 @@ var login = function() {
|
||||
toastError('Du bist momentan offline.<br>Stelle eine Internetverbindung her, um Dich anzumelden');
|
||||
$('#menu-login').hideMenu();
|
||||
} else {
|
||||
log('Login: unbekannter Fehler', status, error);
|
||||
log('[app] Login: unbekannter Fehler', status, error);
|
||||
log(xhr);
|
||||
toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ var logout = function() {
|
||||
hash: localStorage.getItem('auth_hash')
|
||||
}
|
||||
if ((auth.id === null) || (auth.hash === null)) {
|
||||
log('Not logged in');
|
||||
log('[app] Not logged in');
|
||||
logoutClearStorage();
|
||||
return;
|
||||
}
|
||||
@@ -198,13 +198,13 @@ var logout = function() {
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
if (xhr.status == 401) {
|
||||
log('Not logged in');
|
||||
log('[app] Not logged in');
|
||||
logoutClearStorage();
|
||||
} else if (xhr.status == 0) {
|
||||
log('Could not delete auth from server');
|
||||
log('[app] Could not delete auth from server');
|
||||
logoutClearStorage();
|
||||
} else {
|
||||
log('Logout: unbekannter Fehler', status, error);
|
||||
log('[app] Logout: unbekannter Fehler', status, error);
|
||||
log(xhr);
|
||||
toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000);
|
||||
hideLoader();
|
||||
@@ -222,12 +222,12 @@ function deleteDb() {
|
||||
showLoader();
|
||||
var request = window.indexedDB.deleteDatabase('regatten_app_db_' + BOATCLASS);
|
||||
request.onerror = function (event) {
|
||||
log('Cannot delete DB: ', event.target.errorCode);
|
||||
log('[app] Cannot delete DB: ', event.target.errorCode);
|
||||
toastError('Beim Löschen der Datenbank ist ein Fehler aufgetreten.<br>Bitte melde diesen Fehler. (Dev-Menu => Problem melden)', 5000);
|
||||
hideLoader();
|
||||
}
|
||||
request.onsuccess = function (event) {
|
||||
log('DB deleted');
|
||||
log('[app] DB deleted');
|
||||
toastInfo('Die Datenbank wurde gelöscht. Die Seite lädt in wenigen Sekunden neu und erstellt damit eine neue Datenbank.', 10000);
|
||||
hideLoader();
|
||||
setTimeout(function(){ location.reload(); }, 3000);
|
||||
@@ -241,13 +241,13 @@ function deleteCache() {
|
||||
$('#menu-developer').hideMenu();
|
||||
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
||||
for (let registration of registrations) {
|
||||
log('Unregister sW:', registration);
|
||||
log('[app] Unregister sW:', registration);
|
||||
registration.unregister();
|
||||
}
|
||||
});
|
||||
caches.keys().then((keyList) => {
|
||||
return Promise.all(keyList.map((key) => {
|
||||
log('Cache deleted:', key);
|
||||
log('[app] Cache deleted:', key);
|
||||
return caches.delete(key);
|
||||
}));
|
||||
});
|
||||
@@ -273,7 +273,7 @@ function urlB64ToUint8Array(base64String) {
|
||||
}
|
||||
|
||||
function pushesSubscribe() {
|
||||
log('Subscribing');
|
||||
log('[app] Subscribing');
|
||||
const applicationServerKey = urlB64ToUint8Array(PUSH_SERVER_KEY);
|
||||
swRegistration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
@@ -285,14 +285,14 @@ function pushesSubscribe() {
|
||||
updatePushBadge();
|
||||
})
|
||||
.catch(function(err) {
|
||||
log('Failed to subscribe the user: ', err);
|
||||
log('[app] Failed to subscribe the user: ', err);
|
||||
toastError('Da ist leider etwas schief gelaufen. Bitte stelle sicher, dass Du mit dem Internet verbunden bist und versuche es erneut.', 5000);
|
||||
pushesUnSubscribe(true);
|
||||
});
|
||||
}
|
||||
|
||||
function pushesUnSubscribe(silent = false) {
|
||||
log('Unsubscribing');
|
||||
log('[app] Unsubscribing');
|
||||
swRegistration.pushManager.getSubscription()
|
||||
.then(function(subscription) {
|
||||
if (subscription) {
|
||||
@@ -304,7 +304,7 @@ function pushesUnSubscribe(silent = false) {
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
log('Error unsubscribing', error);
|
||||
log('[app] Error unsubscribing', error);
|
||||
$('#menu-pushes').hideMenu();
|
||||
if (!silent) toastError('Da ist leider etwas schief gelaufen. Bitte versuche es erneut oder wende Dich an unseren Support.', 5000);
|
||||
updatePushBadge();
|
||||
@@ -313,7 +313,7 @@ function pushesUnSubscribe(silent = false) {
|
||||
}
|
||||
|
||||
function pushesUpdateServerSubscription(subscription, enabled) {
|
||||
log('updateServer', enabled, subscription);
|
||||
log('[app] updateServer', enabled, subscription);
|
||||
$.ajax({
|
||||
url: QUERY_URL + (enabled ? 'add' : 'remove') + '_subscription',
|
||||
type: 'POST',
|
||||
@@ -440,11 +440,11 @@ async function updateNewsBadge() {
|
||||
var initRegatten = function() {
|
||||
showLoader();
|
||||
|
||||
log('Initializing DB...');
|
||||
log('[app] Initializing DB...');
|
||||
|
||||
initDatabase();
|
||||
|
||||
log('Loading app specific code...');
|
||||
log('[app] Loading app specific code...');
|
||||
|
||||
if (isLoggedIn()) {
|
||||
$('.show-loggedin').show();
|
||||
@@ -465,7 +465,7 @@ var initRegatten = function() {
|
||||
}
|
||||
|
||||
var onServiceWorkerLoaded = function() {
|
||||
log('sW loaded');
|
||||
log('[app] sW loaded');
|
||||
if ((swRegistration !== null) && canUseLocalDB) {
|
||||
pushesPossible = true;
|
||||
updatePushBadge();
|
||||
@@ -475,7 +475,7 @@ var onServiceWorkerLoaded = function() {
|
||||
}
|
||||
|
||||
var onDatabaseLoaded = function() {
|
||||
log('DB loaded');
|
||||
log('[app] DB loaded');
|
||||
if (!canUseLocalDB && !$('#menu-welcome').hasClass('menu-active')) {
|
||||
function NoDbWarningOk() {
|
||||
createCookie('regatten_nodb_banner', true, 1);
|
||||
|
||||
@@ -233,11 +233,11 @@ self.addEventListener('push', async function(event) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown channel:', data.channel);
|
||||
console.log('[sW] Unknown channel:', data.channel);
|
||||
break;
|
||||
}
|
||||
if (!okay) {
|
||||
console.log('Notification channel not subscribed');
|
||||
console.log('[sW] Notification channel not subscribed');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ self.addEventListener('push', async function(event) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Showing notification');
|
||||
console.log('[sW] Showing notification');
|
||||
self.registration.showNotification(data.title, options);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user