Altersklassen

This commit is contained in:
ostertun
2020-12-22 18:44:05 +01:00
parent fba8c8e958
commit a1facbca85
2 changed files with 52 additions and 5 deletions

View File

@@ -6,15 +6,38 @@ async function onRegattaClicked(id) {
var dateTo = parseDate(regatta['date']); var dateTo = parseDate(regatta['date']);
dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0)); dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0));
var text = [];
var specialFields = await dbGetClassProp('special-fields'); var specialFields = await dbGetClassProp('special-fields');
if (specialFields === null) specialFields = {}; if (specialFields === null) specialFields = {};
if (regatta.special.substr(0, 1) == '#') { if (regatta.special.substr(0, 1) == '#') {
regatta.special = regatta.special.substr(1); regatta.special = regatta.special.substr(1);
if (typeof specialFields[regatta.special] !== 'undefined') { if (typeof specialFields[regatta.special] !== 'undefined') {
$('#menu-item-special').text(specialFields[regatta.special]); text.push(specialFields[regatta.special]);
} else {
$('#menu-item-special').text('ERROR');
} }
}
var pos;
while ((pos = regatta.special.indexOf('$')) >= 0) {
var pos2 = regatta.special.indexOf('$', pos + 1);
if (pos2 < 0) break;
var key = regatta.special.substring(pos + 1, pos2);
// age class
if ((key.substr(0, 1) == 'U') && (!isNaN(value = parseInt(key.substr(1))))) {
var year = parseDate(regatta.date).getFullYear();
year = year - value + 1;
text.push('Jahrgänge ' + year + ' und jünger');
} else {
break;
}
regatta.special = regatta.special.replace('$' + key + '$', '');
}
if (text.length > 0) {
text.sort();
for (i in text) {
text[i] = $('<div />').text(text[i]).html();
}
$('#menu-item-special').html(text.join('<br>'));
$('#menu-item-special').show(); $('#menu-item-special').show();
} else { } else {
$('#menu-item-special').hide(); $('#menu-item-special').hide();

View File

@@ -162,6 +162,27 @@ var siteScript = async function() {
entry.special = 'ERROR'; 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 += '<div>' + entry.special + '</div>'; row.content += '<div>' + entry.special + '</div>';
// Icons // Icons
@@ -239,9 +260,12 @@ var siteScript = async function() {
rows.push(null); rows.push(null);
} }
if (Object.keys(specialShown).length > 0) { var specialKeys = Object.keys(specialShown);
if (specialKeys.length > 0) {
specialKeys.sort();
var specialText = ''; var specialText = '';
for (key in specialShown) { for (i in specialKeys) {
var key = specialKeys[i];
specialText += '* ' + key + ': ' + specialShown[key] + '<br>'; specialText += '* ' + key + ': ' + specialShown[key] + '<br>';
} }
$('#card-special').find('p').html(specialText); $('#card-special').find('p').html(specialText);