Element.prototype.documentOffsetTop = function() { return this.offsetTop + (this.offsetParent ? this.offsetParent.documentOffsetTop() : 0); }; function scrollToToday() { window.scrollTo({ top: document.getElementById('div-today').documentOffsetTop() - (window.innerHeight / 2), behavior: 'smooth' }); } function selectChange(callSiteScript = true) { var val = $('#select-year').val(); if (val == "user") { $('#input-from').trigger('focusin').trigger('focusout').parent().show(); $('#input-to').trigger('focusin').trigger('focusout').parent().show(); $('#button-show').show(); } else { $('#input-from').parent().hide(); $('#input-to').parent().hide(); $('#button-show').hide(); $('#input-from').val(val + '-01-01'); $('#input-to').val(val + '-12-31'); if (callSiteScript && (typeof siteScript === 'function')) { history.replaceState(null, '', '?year=' + val); showLoader(); siteScript(); } } } function buttonShowPressed() { if (typeof siteScript === 'function') { history.replaceState(null, '', '?year=user&from=' + $('#input-from').val() + "&to=" + $('#input-to').val()); showLoader(); siteScript(); } } function initYear() { return new Promise(async function (resolve) { var year = findGetParameter('year'); if (year === null) year = await dbGetCurrentYear(); $('#select-year').html(''); $('#select-year').val(year); if (year == "user") { var from = findGetParameter('from'); var to = findGetParameter('to'); if (from === null) from = formatDate('Y-m-d') if (to === null) to = formatDate('Y-m-d') $('#input-from').val(from).trigger('focusin').trigger('focusout'); $('#input-to').val(to).trigger('focusin').trigger('focusout'); } selectChange(false); resolve(); }); } var firstCall = true; var rows = []; var today; async function drawList () { window.setTimeout(function () { var list = ''; rows.forEach(function (entry) { if (entry == null) { list += '
Heute ist der ' + formatDate('d.m.Y', today) + '
'; } else if (search($('#input-search').val(), entry.keywords)) { list += entry.content; } }); $('#div-regattas').html(list); }, 0); } var siteScript = async function() { if (firstCall) { firstCall = false; await initYear(); $('#select-year').change(selectChange); $('#button-show').click(buttonShowPressed); $('#input-search').on('input', drawList); $('#button-totoday').click(scrollToToday); } today = getToday(); var minDate = parseDate($('#input-from').val()); var maxDate = parseDate($('#input-to').val()); var regattas = await dbGetRegattasRange(minDate, maxDate); if (minDate <= today && maxDate >= today) $('#button-totoday').parent().parent().show(); else $('#button-totoday').parent().parent().hide(); var selectedYear = $('#select-year').val(); var years = await dbGetData('years'); years.sort(function (a, b) { if (a['year'] > b['year']) return -1; if (a['year'] < b['year']) return 1; return 0; }); var options = ''; for (id in years) { var year = years[id]['year']; options += ''; } $('#select-year').html(options); $('#select-year').val(selectedYear); var count = regattas.length; if (count > 0) { if (count == 1) { $('#p-count').html('Es wurde 1 Regatta gefunden!'); } else { $('#p-count').html('Es wurden ' + count + ' Regatten gefunden!'); } $('#div-regattas').show(); $('#input-search').parent().show(); var heute = false; rows = []; var specialFields = await dbGetClassProp('special-fields'); if (specialFields === null) specialFields = {}; var specialShown = {}; for (id in regattas) { var entry = regattas[id]; var club = null; if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); var plannings = await dbGetDataIndex('plannings', 'regatta', entry['id']); var dateFrom = entry['dateFrom']; var dateTo = entry['dateTo']; var row = { keywords: [], content: '' }; row.keywords.push(entry['name']); if (entry['number'] != null) row.keywords.push(entry['number']); if (club != null) row.keywords.push(club['kurz'], club['name']); if (!heute && (today <= dateFrom)) { rows.push(null); heute = true; } row.content += '
'; // ZEILE 1 // Name row.content += '
' + (entry['canceled'] == 1 ? '' : '') + entry['name'] + (entry['canceled'] == 1 ? '' : '') + '
'; // ZEILE 2 row.content += '
'; // Number row.content += '
' + ((entry['number'] != null) ? ('# ' + entry['number']) : '') + '
'; // Club row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special if (entry.special.substr(0, 1) == '#') { entry.special = entry.special.substr(1); if (typeof specialFields[entry.special] !== 'undefined') { specialShown[entry.special] = specialFields[entry.special]; entry.special = '* ' + entry.special; } else { entry.special = 'ERROR'; } } // replace placeholders var pos; while ((pos = entry.special.indexOf('$')) >= 0) { var pos2 = entry.special.indexOf('$', pos + 1); if (pos2 < 0) break; var key = entry.special.substring(pos + 1, pos2); var value = ''; // age class if ((key.substr(0, 1) == 'U') && (!isNaN(value = parseInt(key.substr(1))))) { var year = parseDate(entry.date).getFullYear(); year = year - value + 1; var text = 'Jahrgänge ' + year + ' und jünger'; value = 'U-' + value; specialShown[value] = text; } else { break; } entry.special = entry.special.replace('$' + key + '$', value); } row.content += '
' + entry.special + '
'; // Icons var icons = []; if (entry['info'] != '') icons.push(''); if ((entry['meldung'] != '') && (dateTo >= today) && (entry['meldungOffen'] == '1')) { var color = ''; var planning = null; if (isLoggedIn()) { var plannings = await dbGetDataIndex('plannings', 'regatta', entry['id']); for (id in plannings) { if (plannings[id]['user'] == USER_ID) { planning = plannings[id]; break; } } } if (entry['meldungSchluss'] != null) { if ((planning == null) || (planning['gemeldet'] == '0')) { var ms = 0; if (entry['meldungEarly'] != null) { ms = parseDate(entry['meldungEarly']); } if (ms < today) { ms = parseDate(entry['meldungSchluss']); } var diff = Math.round((ms - today) / 86400000); if (ms < today) { color = ' color-red2-dark'; } else if (diff < 7) { color = ' color-yellow2-dark'; } } } if ((planning != null) && (planning['gemeldet'] == '0')) { color += ' fa-blink'; } icons.push(''); } if (entry['bericht'] != '') icons.push(''); if (entry['canceled'] == '1') { icons.push(''); } else if (entry['results'] == '1') { icons.push(''); } row.content += '
' + icons.join(' ') + '
'; row.content += '
'; // ZEILE 3 row.content += '
'; // Date if (entry['length'] < 1) { if (formatDate('d.m', dateFrom) == '01.01') { row.content += '
Datum noch unklar
'; } else { row.content += '
' + formatDate("d.m.Y", dateFrom) + ' - Datum nicht final
'; } } else { row.content += '
' + formatDate("d.m.Y", dateFrom) + ' - ' + formatDate("d.m.Y", dateTo) + '
'; } // RLF row.content += '
' + parseFloat(entry['rlf']).toFixed(2) + '
'; row.content += '
'; rows.push(row); } if (!heute) { rows.push(null); } var specialKeys = Object.keys(specialShown); if (specialKeys.length > 0) { specialKeys.sort(); var specialText = ''; for (i in specialKeys) { var key = specialKeys[i]; specialText += '* ' + key + ': ' + specialShown[key] + '
'; } $('#card-special').find('p').html(specialText); $('#card-special').show(); } else { $('#card-special').hide(); } drawList(); } else { $('#p-count').html('Keine Regatten gefunden!'); $('#div-regattas').hide(); $('#input-search').parent().hide(); $('#card-special').hide(); } hideLoader(); }