function selectChange() { var val = $('#select-year').val(); if (typeof siteScript === 'function') { history.replaceState(null, '', '?year=' + val); siteScript(); } } function initYear() { var year = findGetParameter('year'); if (year === null) year = new Date().getFullYear(); $('#select-year').html(''); $('#select-year').val(year); } 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() { var userid = findGetParameter('user'); var user = null; if (userid !== null) { user = await dbGetData('users', userid); } if (user === null) { location.href = LINK_PRE + 'planning_list'; return; } $('#p-username').text(user.username); if (firstCall) { firstCall = false; initYear(); $('#select-year').change(selectChange); $('#input-search').on('input', drawList); } today = getToday(); var selectedYear = $('#select-year').val(); var minDate = parseDate(selectedYear + '-01-01'); var maxDate = parseDate(selectedYear + '-12-31'); var regattas = await dbGetRegattasRange(minDate, maxDate); var plannings = await dbGetDataIndex('plannings', 'user', user.id); for (var i = regattas.length - 1; i >= 0; i --) { var entry = regattas[i]; var okay = false; for (p in plannings) { if (plannings[p].regatta == entry.id) { regattas[i].planning = plannings[p]; okay = true; break; } } if (!okay) { regattas.splice(i, 1); } } var regattaResults = []; for (id in regattas) { var entry = regattas[id]; var results = await dbGetDataIndex('results', 'regatta', entry['id']); regattaResults[entry['id']] = (results.length > 0); } 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 = []; for (id in regattas) { var entry = regattas[id]; var club = null; if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); if (entry.planning.steuermann !== null) { entry.planning.steuermann = (await dbGetData('sailors', entry.planning.steuermann)).name; } var crewString = entry.planning.crew.split(','); entry.planning.crew = []; for (c in crewString) { var sailor = await dbGetData('sailors', crewString[c]); if (sailor !== null) { entry.planning.crew.push(sailor.name); } } 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 (entry.planning.steuermann != null) row.keywords.push(entry.planning.steuermann); for (c in entry.planning.crew) row.keywords.push(entry.planning.crew[c]); 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']) : '') + '
'; // Special row.content += '
' + entry['special'] + '
'; // Club row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; 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 += '
'; // ZEILE 4 row.content += '
'; // ZEILE 5 row.content += '
'; row.content += '
' + entry.planning.steuermann + '
'; row.content += '
'; // ZEILE 6... for (var i in entry.planning.crew) { row.content += '
'; row.content += '
' + entry.planning.crew[i] + '
'; row.content += '
'; } row.content += '
'; /* // ZEILE 2 row.content += '
'; // Number row.content += '
' + ((entry['number'] != null) ? ('# ' + entry['number']) : '') + '
'; // Club row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special row.content += '
' + entry['special'] + '
'; // Icons var icons = []; if (entry['info'] != '') icons.push(''); if ((entry['meldung'] != '') && (dateTo >= today) && (entry['meldungOffen'] == '1')) { var color = ''; if (entry['meldungSchluss'] != null) { 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'; } } icons.push(''); } if (entry['bericht'] != '') icons.push(''); if (entry['canceled'] == '1') { icons.push(''); } else if (regattaResults[entry['id']]) { 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); } drawList(); } else { $('#p-count').html(user.username + ' hat noch keine Regatten in seiner/ihrer Saison-Planung!'); $('#div-regattas').hide(); $('#input-search').parent().hide(); } hideLoader(); }