diff --git a/server/content/index.php b/server/content/index.php
index e35051d..0f054f5 100644
--- a/server/content/index.php
+++ b/server/content/index.php
@@ -11,8 +11,7 @@
// Favorites
$content = '
Deine Favoriten
';
- $thead = '| Segler | Rangliste |
';
- $content .= $tpl->load('table', [$thead, 'html-id' => 'table-favorites', 'css-class' => 'mb-0 mt-3']);
+ $content .= '';
$content .= '';
$content .= 'Du folgst keinen Seglern.
';
$content .= 'Um jemandem zu folgen, gehe zur Segler-Liste und wähle bis zu fünf Segler aus.';
@@ -91,6 +90,10 @@
$items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe']);
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-regatta', 'title' => 'Regatta-Details', 'height' => 320]);
+ // Favorites Menu
+ $items = $tpl->load('menu/item-icon', ['Nicht mehr folgen', '#', 'html-id' => 'menu-item-unfollow', 'icon' => 'fa-heart', 'css-class' => ' border-0']);
+ $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-favorite', 'title' => 'Favorit', 'height' => 150]);
+
$sp['scripts'] .= $scripts->load('onRegattaClicked');
$sp['scripts'] .= $scripts->load('index');
diff --git a/server/content/sailors.php b/server/content/sailors.php
index 29e65f6..42858e7 100644
--- a/server/content/sailors.php
+++ b/server/content/sailors.php
@@ -1,14 +1,14 @@
Segler";
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// Info Years
$content = '
Jahrgänge
';
$content .= '';
@@ -17,30 +17,32 @@
$content .= 'Klicke dazu einfach auf den entsprechenden Segler und wähle Jahrgang bearbeiten aus.
';
$content .= 'Vielen Dank für Deine Unterstützung!';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// List
$content = '';
$content .= $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text', 'css-class' => 'mt-2']);
$content .= '';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-list']);
-
+
// Pagination
$sp['output'] .= $tpl->load('pagination', ['html-id' => 'pagination']);
-
+
// Menu
- $items = $tpl->load('menu/item-icon', ['', '#', 'html-id' => 'menu-item-year', 'icon' => 'fa-edit']);
+ $items = $tpl->load('menu/item-switch', ['Favorit', 'html-id' => 'menu-item-follow', 'icon' => 'fa-heart']);
+ $items .= $tpl->load('menu/item-icon-badge', ['Favorit', '#', 'html-id' => 'menu-item-follow-disabled', 'icon' => 'fa-heart', 'badge-value' => 'MAX REACHED']);
+ $items .= $tpl->load('menu/item-icon', ['', '#', 'html-id' => 'menu-item-year', 'icon' => 'fa-edit']);
$items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe', 'css-class' => 'border-0']);
- $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-sailor', 'title' => 'Segler-Details', 'height' => 200]);
-
+ $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-sailor', 'title' => 'Segler-Details', 'height' => 260]);
+
$items = 'Bitte trage hier den Jahrgang ein:
';
$items .= $tpl->load('input', ['html-id' => 'input-edityear', 'placeholder' => 'Jahrgang', 'type' => 'number']);
$items .= $tpl->load('button', ['Speichern', '#', 'html-id' => 'button-edityear']);
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-edityear', 'height' => 240]);
-
+
$sp['scripts'] .= $scripts->load('pagination', ['pageChange', 'page', 'pageCount', 'pagination']);
$sp['scripts'] .= $scripts->load('sailors');
-
-?>
\ No newline at end of file
+
+?>
diff --git a/server/scripts/index.js b/server/scripts/index.js
index a30f36e..438b91e 100644
--- a/server/scripts/index.js
+++ b/server/scripts/index.js
@@ -2,6 +2,49 @@ var firstCall = true;
var today;
var onUpdatePushBadge;
+var onUnfollowClicked = async function() {
+ var id = $('#menu-item-unfollow').attr('data-sailor-id');
+ showLoader();
+ $('#menu-favorite').hideMenu();
+ var auth = {
+ id: localStorage.getItem('auth_id'),
+ hash: localStorage.getItem('auth_hash')
+ }
+ $.ajax({
+ url: QUERY_URL + 'sailor_unfollow',
+ method: 'POST',
+ data: {
+ auth: auth,
+ sailor: id
+ },
+ error: function (xhr, status, error) {
+ if (xhr.status == 0) {
+ toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Deine Favoriten zu bearbeiten.');
+ } else {
+ log('Unfollow: 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();
+ toastOk('Erfolgreich');
+ hideLoader();
+ }
+ });
+}
+
+var onFavoriteClicked = async function(id) {
+ var sailor = await dbGetData('sailors', id);
+
+ $('#menu-favorite').find('.menu-title').find('p').text(sailor.name);
+
+ $('#menu-item-unfollow').attr('data-sailor-id', sailor.id);
+
+ $('#menu-favorite').showMenu();
+}
+
var siteScript = async function() {
today = getToday();
@@ -33,6 +76,7 @@ var siteScript = async function() {
}
onUpdatePushBadge();
}
+ $('#menu-item-unfollow').click(onUnfollowClicked);
}
if (isLoggedIn()) {
@@ -50,31 +94,41 @@ var siteScript = async function() {
}
if (watched.length > 0) {
var year = (new Date()).getFullYear();
- $('#th-ranking').html('Rangliste ' + year);
var ranking = (await dbGetRanking(parseDate('01.12.' + (year - 1)), parseDate('30.11.' + year), false, false))[0];
- tbody = '';
+ var list = '';
for (i in watched) {
sailor = watched[i];
- tbody += '| ' + sailor.name + ' | ';
+ var club = null;
+ if (sailor.club != null)
+ club = await dbGetData('clubs', sailor.club);
var rank = null;
for (r in ranking) {
if (ranking[r].id == sailor.id) {
- rank = ranking[r].rank;
+ rank = ranking[r];
break;
}
}
+
+ list += '';
+ list += ' ';
+ // Name
+ list += ' ' + sailor.name + ' ';
+ list += ' ';
if (rank == null) {
- tbody += ' nicht in der Rangliste';
+ list += ' Nicht in der Rangliste ';
} else {
- tbody += ' ' + rank + '. Platz';
+ // Rank
+ list += ' Platz ' + rank.rank + ' ';
+ // rlp
+ list += ' ' + rank.rlp.toFixed(3) + ' Punkte ';
}
- tbody += ' |
';
+ list += '';
}
- $('#table-favorites').find('tbody').html(tbody);
+ $('#div-favorites').html(list);
$('#p-favorites').hide();
- $('#table-favorites').show();
+ $('#div-favorites').show();
} else {
- $('#table-favorites').hide();
+ $('#div-favorites').hide();
$('#p-favorites').show();
}
$('#card-favorites').show();
diff --git a/server/scripts/sailors.js b/server/scripts/sailors.js
index d3da25b..3f088ea 100644
--- a/server/scripts/sailors.js
+++ b/server/scripts/sailors.js
@@ -4,6 +4,40 @@ var displayed = [];
var page = 1;
var pageCount = 0;
const showCount = 25;
+var followedSailors = [];
+
+async function onFollowChange() {
+ var id = $('#menu-item-follow').attr('data-sailor-id');
+ showLoader();
+ $('#menu-sailor').hideMenu();
+ var auth = {
+ id: localStorage.getItem('auth_id'),
+ hash: localStorage.getItem('auth_hash')
+ }
+ $.ajax({
+ url: QUERY_URL + ($('#menu-item-follow').prop('checked') ? 'sailor_follow' : 'sailor_unfollow'),
+ method: 'POST',
+ data: {
+ auth: auth,
+ sailor: id
+ },
+ error: function (xhr, status, error) {
+ if (xhr.status == 0) {
+ toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Deine Favoriten zu bearbeiten.');
+ } else {
+ log('Un/Follow: 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();
+ toastOk('Erfolgreich');
+ hideLoader();
+ }
+ });
+}
async function onEditYearClick() {
var id = $('#button-edityear').attr('data-sailor-id');
@@ -50,6 +84,26 @@ async function onListClicked(id) {
$('#menu-sailor').find('.menu-title').find('p').text(sailor.name);
+ // Follow
+ if (isLoggedIn()) {
+ var found = false;
+ for (var i in followedSailors) {
+ if (followedSailors[i].id == sailor.id) found = true;
+ }
+ if (found || (followedSailors.length < 5)) {
+ $('#menu-item-follow').attr('data-sailor-id', sailor.id);
+ $('#menu-item-follow').prop('checked', found);
+ $('#menu-item-follow').parent().parent().show();
+ $('#menu-item-follow-disabled').hide();
+ } else {
+ $('#menu-item-follow').parent().parent().hide();
+ $('#menu-item-follow-disabled').show();
+ }
+ } else {
+ $('#menu-item-follow').parent().parent().hide();
+ $('#menu-item-follow-disabled').hide();
+ }
+
// Edit Year
$('#button-edityear').attr('data-sailor-id', sailor.id);
$('#menu-edityear').find('.menu-title').find('p').text(sailor.name);
@@ -134,6 +188,19 @@ var siteScript = async function() {
$('#input-search').on('input', reSearch);
$('#menu-item-year').click(function(){ $('#menu-sailor').hideMenu(); $('#menu-edityear').showMenu(); });
$('#button-edityear').click(onEditYearClick);
+ $('#menu-item-follow').parent().parent().click(onFollowChange);
+ $('#menu-item-follow-disabled').click(function(){ $('#menu-sailor').hideMenu(); toastInfo('Du kannst maximal 5 Seglern folgen. Entferne erst einen Segler aus Deinen Favoriten, bevor Du andere aufnimmst.', 5000); });
+ }
+
+ if (isLoggedIn()) {
+ var user = await dbGetData('users', USER_ID);
+ followedSailors = [];
+ for (var i = 1; i <= 5; i ++) {
+ sailor_id = user['sailor' + i];
+ if (sailor_id != null) {
+ followedSailors.push(await dbGetData('sailors', sailor_id));
+ }
+ }
}
var results = await dbGetData('sailors');