diff --git a/server/content/planning_edit.php b/server/content/planning_edit.php index d816ed4..03c78da 100644 --- a/server/content/planning_edit.php +++ b/server/content/planning_edit.php @@ -19,8 +19,13 @@ // Menu $items = $tpl->load('menu/item-switch', ['In die Saison-Planung aufnehmen', 'html-id' => 'switch-planning-include', 'icon' => 'fa-check']); + $items .= $tpl->load('menu/item-simple', ['', '#', 'html-id' => 'item-boat']); $items .= $tpl->load('menu/item-simple', ['', '#', 'html-id' => 'item-steuermann']); - $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-edit', 'title' => 'Regatta bearbeiten', 'height' => 320]); + $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-edit', 'title' => 'Regatta bearbeiten', 'height' => 400]); + + // Select boat + $items = $tpl->load('input', ['html-id' => 'input-edit-boat-search', 'placeholder' => 'Suche', 'type' => 'text']); + $sp['menus'] .= $tpl->load('menu/modal', [$items, 'html-id' => 'menu-boat', 'height' => 500, 'width' => 350]); // Select sailor $items = $tpl->load('input', ['html-id' => 'input-edit-search', 'placeholder' => 'Suche', 'type' => 'text']); diff --git a/server/content/regatta_plan.php b/server/content/regatta_plan.php index 34165a1..160f132 100644 --- a/server/content/regatta_plan.php +++ b/server/content/regatta_plan.php @@ -1,31 +1,31 @@ '; $content .= '

'; - + $sp['output'] .= $tpl->load('card', [$content]); - + // Plannings $content = '

'; - $thead = 'BenutzerSteuermann/-frauCrew'; + $thead = 'BenutzerBootSteuermann/-frauCrew'; $content .= $tpl->load('table', [$thead, 'html-id' => 'table-plannings', 'css-class' => 'mb-0 text-nowrap']); - + $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-plannings']); - + // Info $content = '

Du planst, hier hinzufahren, aber stehst nicht auf dieser Liste?
'; $content .= 'Das kannst Du ändern! '; $content .= 'Erstelle einfach hier Deine eigene Saison-Planung.'; $content .= 'Melde Dich an oder registriere Dich kostenlos und erstelle Deine eigene Saison-Planung.'; $content .= '

'; - + $sp['output'] .= $tpl->load('card', [$content]); - + $sp['scripts'] .= $scripts->load('regatta_plan'); - -?> \ No newline at end of file + +?> diff --git a/server/scripts/onRegattaClicked.js b/server/scripts/onRegattaClicked.js index edb0565..704b908 100644 --- a/server/scripts/onRegattaClicked.js +++ b/server/scripts/onRegattaClicked.js @@ -57,11 +57,18 @@ async function onRegattaClicked(id) { // Your Planning if (planning != null) { $('#menu-item-yourplanning').show(); + var boat = null; + if (planning.boat != null) { + boat = (await dbGetData('boats', planning.boat)).sailnumber; + } var steuermann = null; if (planning.steuermann != null) { steuermann = (await dbGetData('sailors', planning.steuermann)).name; } - var crew = [steuermann == null ? '[noch unklar]' : steuermann]; + var crew = [ + boat == null ? '[Boot unklar]' : boat, + steuermann == null ? '[St.mann unklar]' : steuermann + ]; crewA = planning.crew.split(','); for (i in crewA) { var sailor = await dbGetData('sailors', crewA[i]); diff --git a/server/scripts/planning.js b/server/scripts/planning.js index 3c21b1c..9fc4073 100644 --- a/server/scripts/planning.js +++ b/server/scripts/planning.js @@ -178,6 +178,9 @@ var siteScript = async function() { var club = null; if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); + if (entry.planning.boat !== null) { + entry.planning.boat = (await dbGetData('boats', entry.planning.boat)).sailnumber; + } if (entry.planning.steuermann !== null) { entry.planning.steuermann = (await dbGetData('sailors', entry.planning.steuermann)).name; } @@ -197,6 +200,7 @@ var siteScript = async function() { 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.boat != null) row.keywords.push(entry.planning.boat); if (entry.planning.steuermann != null) row.keywords.push(entry.planning.steuermann); for (c in entry.planning.crew) row.keywords.push(entry.planning.crew[c]); diff --git a/server/scripts/planning_edit.js b/server/scripts/planning_edit.js index 4749738..7578600 100644 --- a/server/scripts/planning_edit.js +++ b/server/scripts/planning_edit.js @@ -141,37 +141,6 @@ async function sailorsSearch() { } } -async function initSailors() { - sailors = []; - known = []; - var plannings = await dbGetDataIndex('plannings', 'user', USER_ID); - knownIds = {}; - for (var p in plannings) { - p = plannings[p]; - if (p.steuermann !== null) knownIds[p.steuermann] = true; - var crew = p.crew.split(','); - for (var c in crew) { - c = crew[c]; - if (c != '') knownIds[c] = true; - } - } - var dbSailors = await dbGetData('sailors'); - dbSailors.sort(function(a,b){ - return a.name.localeCompare(b.name); - }); - for (var s in dbSailors) { - var item = ''; - item += '' + dbSailors[s].name + ''; - item += ''; - item += ''; - sailors.push({ - keywords: [dbSailors[s].name], - content: item - }); - if (dbSailors[s].id in knownIds) known.push(item); - } -} - async function planningChangeCrew(sid = null) { if (sid !== null) { showLoader(); @@ -230,6 +199,136 @@ async function planningChangeSteuermann() { $('#input-edit-search').focus(); } +var boats = []; +var boatKnownIds = []; +var boatKnown = []; + +async function boatSelected(bid) { + $('#menu-boat').hideMenu(); + showLoader(); + var rid = $('#switch-planning-include').data('regatta'); + var action = 'planning_set_boat'; + // add boat + var auth = { + id: localStorage.getItem('auth_id'), + hash: localStorage.getItem('auth_hash') + } + $.ajax({ + url: QUERY_URL + action, + method: 'POST', + data: { + auth: auth, + regatta: rid, + boat: bid + }, + error: function (xhr, status, error) { + if (xhr.status == 401) { + log('authentification failed'); + toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); + } else if (xhr.status == 0) { + toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um die Änderungen zu speichern'); + } else { + log(action + ': unbekannter Fehler', status, error); + log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + hideLoader(); + }, + success: async function (data, status, xhr) { + await sync(); + if ((bid === null) || (bid in boatKnownIds)) { + planningEdit(rid); + hideLoader(); + } else { + location.reload(); + } + } + }); +} + +async function boatsSearch() { + $('.item-boat-search').remove(); + var item = ''; + item += 'noch unklar'; + item += ''; + item += ''; + $('#menu-boat').find('.content').find('.list-group').append(item); + if ($('#input-edit-boat-search').val().length == 0) { + boatKnown.forEach(function (entry) { + $('#menu-boat').find('.content').find('.list-group').append(entry); + }); + } + if ($('#input-edit-boat-search').val().length >= 3) { + boats.forEach(function (entry) { + if (search($('#input-edit-boat-search').val(), entry.keywords)) { + $('#menu-boat').find('.content').find('.list-group').append(entry.content); + } + }); + } else { + var item = ''; + $('#menu-boat').find('.content').find('.list-group').append(item); + } +} + +async function planningChangeBoat() { + $('#input-edit-boat-search').val('').trigger('focusin').trigger('focusout'); + boatsSearch(); + $('#menu-edit').hideMenu(); + $('#menu-boat').find('.menu-title').find('h1').text('Boot bearbeiten'); + $('#menu-boat').showMenu(); + $('#input-edit-boat-search').focus(); +} + +async function initBoatsSailors() { + boats = []; + sailors = []; + boatKnown = []; + known = []; + var plannings = await dbGetDataIndex('plannings', 'user', USER_ID); + boatKnownIds = {}; + knownIds = {}; + for (var p in plannings) { + p = plannings[p]; + if (p.boat !== null) boatKnownIds[p.boat] = true; + if (p.steuermann !== null) knownIds[p.steuermann] = true; + var crew = p.crew.split(','); + for (var c in crew) { + c = crew[c]; + if (c != '') knownIds[c] = true; + } + } + var dbBoats = await dbGetData('boats'); + dbBoats.sort(function(a,b){ + return a.sailnumber.localeCompare(b.sailnumber); + }); + for (var b in dbBoats) { + var item = ''; + item += '' + dbBoats[b].sailnumber + ' - ' + dbBoats[b].name + ''; + item += ''; + item += ''; + boats.push({ + keywords: [dbBoats[b].sailnumber, dbBoats[b].name], + content: item + }); + if (dbBoats[b].id in boatKnownIds) boatKnown.push(item); + } + var dbSailors = await dbGetData('sailors'); + dbSailors.sort(function(a,b){ + return a.name.localeCompare(b.name); + }); + for (var s in dbSailors) { + var item = ''; + item += '' + dbSailors[s].name + ''; + item += ''; + item += ''; + sailors.push({ + keywords: [dbSailors[s].name], + content: item + }); + if (dbSailors[s].id in knownIds) known.push(item); + } +} + async function planningEdit(id) { var regatta = await dbGetData('regattas', id); @@ -249,7 +348,13 @@ async function planningEdit(id) { $('#switch-planning-include').data('regatta', id); if (planning !== null) { $('#switch-planning-include').prop('checked', true); + $('#item-boat').show(); $('#item-steuermann').show(); + if (planning.boat !== null) { + $('#item-boat').find('span').text('Boot: ' + (await dbGetData('boats', planning.boat)).sailnumber); + } else { + $('#item-boat').find('span').html('Boot: noch unklar'); + } if (planning.steuermann !== null) { $('#item-steuermann').find('span').text('Am Steuer: ' + (await dbGetData('sailors', planning.steuermann)).name); } else { @@ -274,6 +379,7 @@ async function planningEdit(id) { $('#menu-edit').find('.content').find('.list-group').append(item); } else { $('#switch-planning-include').prop('checked', false); + $('#item-boat').hide(); $('#item-steuermann').hide(); $('.item-crew').remove(); } @@ -332,9 +438,11 @@ var siteScript = async function() { $('#select-year').change(selectChange); $('#input-search').on('input', drawList); $('#switch-planning-include').parent().parent().click(planningSwitchChanged); + $('#item-boat').click(planningChangeBoat); $('#item-steuermann').click(planningChangeSteuermann); $('#input-edit-search').on('input', sailorsSearch); - initSailors(); + $('#input-edit-boat-search').on('input', boatsSearch); + initBoatsSailors(); } today = getToday(); @@ -393,6 +501,9 @@ var siteScript = async function() { if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); if (entry.planning !== null) { + if (entry.planning.boat !== null) { + entry.planning.boat = (await dbGetData('boats', entry.planning.boat)).sailnumber; + } if (entry.planning.steuermann !== null) { entry.planning.steuermann = (await dbGetData('sailors', entry.planning.steuermann)).name; } @@ -488,10 +599,15 @@ var siteScript = async function() { // ZEILE 5 row.content += '
'; - row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'noch unklar') + '
'; + row.content += '
' + (entry.planning.boat !== null ? entry.planning.boat : 'Boot unklar') + '
'; row.content += '
'; - // ZEILE 6... + // ZEILE 6 + row.content += '
'; + row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'St.mann unklar') + '
'; + row.content += '
'; + + // ZEILE 7... for (var i in entry.planning.crew) { row.content += '
'; row.content += '
' + entry.planning.crew[i] + '
'; diff --git a/server/scripts/planning_view.js b/server/scripts/planning_view.js index 8864be9..dbe148d 100644 --- a/server/scripts/planning_view.js +++ b/server/scripts/planning_view.js @@ -124,6 +124,9 @@ var siteScript = async function() { var club = null; if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); + if (entry.planning.boat !== null) { + entry.planning.boat = (await dbGetData('boats', entry.planning.boat)).sailnumber; + } if (entry.planning.steuermann !== null) { entry.planning.steuermann = (await dbGetData('sailors', entry.planning.steuermann)).name; } @@ -143,6 +146,7 @@ var siteScript = async function() { 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.boat != null) row.keywords.push(entry.planning.boat); if (entry.planning.steuermann != null) row.keywords.push(entry.planning.steuermann); for (c in entry.planning.crew) row.keywords.push(entry.planning.crew[c]); @@ -215,10 +219,15 @@ var siteScript = async function() { // ZEILE 5 row.content += '
'; - row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'noch unklar') + '
'; + row.content += '
' + (entry.planning.boat !== null ? entry.planning.boat : 'Boot unklar') + '
'; row.content += '
'; - // ZEILE 6... + // ZEILE 6 + row.content += '
'; + row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'St.mann unklar') + '
'; + row.content += '
'; + + // ZEILE 7... for (var i in entry.planning.crew) { row.content += '
'; row.content += '
' + entry.planning.crew[i] + '
'; diff --git a/server/scripts/regatta_plan.js b/server/scripts/regatta_plan.js index 67102e0..eb582d1 100644 --- a/server/scripts/regatta_plan.js +++ b/server/scripts/regatta_plan.js @@ -14,7 +14,7 @@ var siteScript = async function() { var dateFrom = parseDate(regatta['date']); var dateTo = parseDate(regatta['date']); dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0)); - + $('#h1-title').text(regatta.name); if (regatta.length < 1) { if (formatDate('d.m', dateFrom) == '01.01') { @@ -25,7 +25,7 @@ var siteScript = async function() { } else { $('#p-title').html(formatDate('d.m.Y', dateFrom) + ' - ' + formatDate('d.m.Y', dateTo)); } - + var plannings = await dbGetDataIndex('plannings', 'regatta', regatta.id); if (plannings.length > 0) { $('#table-plannings').show(); @@ -33,17 +33,23 @@ var siteScript = async function() { var tbody = ''; for (var p in plannings) { var planning = plannings[p]; - + tbody += ''; - + tbody += '' + (await dbGetData('users', planning.user)).username + ''; - + + if (planning.boat != null) { + tbody += '' + (await dbGetData('boats', planning.boat)).sailnumber + ''; + } else { + tbody += '(noch unklar)'; + } + if (planning.steuermann != null) { tbody += '' + (await dbGetData('sailors', planning.steuermann)).name + ''; } else { tbody += '(noch unklar)'; } - + var crew = []; var cr = planning.crew.split(','); for (c in cr) { @@ -51,7 +57,7 @@ var siteScript = async function() { if (s != null) crew.push(s.name); } tbody += '' + crew.join('
') + ''; - + tbody += ''; } $('#table-plannings').find('tbody').html(tbody); @@ -60,6 +66,6 @@ var siteScript = async function() { $('#p-info').show(); $('#table-plannings').hide(); } - + hideLoader(); -} \ No newline at end of file +}