From 701569d76dbf1916125d5cf81fb2b65c6976d6d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 4 Jun 2011 21:25:10 +0200 Subject: [PATCH] Improve offline marker behaviour. This fixes #199. --- .../pterodactylus/sone/web/ajax/GetStatusAjaxPage.java | 2 +- src/main/resources/static/javascript/sone.js | 15 ++++++++++++--- src/main/resources/templates/include/head.html | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 09b6f40..07fdfa8 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -136,7 +136,7 @@ public class GetStatusAjaxPage extends JsonPage { jsonReply.put("postSone", reply.getPost().getSone().getId()); jsonReplies.add(jsonReply); } - return createSuccessJsonObject().put("sones", jsonSones).put("notifications", jsonNotificationInformations).put("newPosts", jsonPosts).put("newReplies", jsonReplies); + return createSuccessJsonObject().put("loggedIn", currentSone != null).put("sones", jsonSones).put("notifications", jsonNotificationInformations).put("newPosts", jsonPosts).put("newReplies", jsonReplies); } /** diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e07a08b..c9d51c4 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -8,6 +8,9 @@ function ajaxGet(url, data, successCallback, errorCallback) { successCallback(data, textStatus); } }, "error": function(xmlHttpRequest, textStatus, errorThrown) { + if (xmlHttpRequest.status == 403) { + notLoggedIn = true; + } if (typeof errorCallback != "undefined") { errorCallback(); } else { @@ -976,6 +979,10 @@ function getStatus() { $.each(data.sones, function(index, value) { updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated, value.lastUpdatedText); }); + notLoggedIn = !data.loggedIn; + if (!notLoggedIn) { + showOfflineMarker(!online); + } /* search for removed notifications. */ $("#sone #notification-area .notification").each(function() { notificationId = $(this).attr("id"); @@ -1586,7 +1593,7 @@ var statusRequestQueued = true; */ function ajaxError() { online = false; - toggleOfflineMarker(true); + showOfflineMarker(true); if (!statusRequestQueued) { setTimeout(getStatus, 5000); statusRequestQueued = true; @@ -1598,7 +1605,7 @@ function ajaxError() { */ function ajaxSuccess() { online = true; - toggleOfflineMarker(false); + showOfflineMarker(!online || (initiallyLoggedIn && notLoggedIn)); } /** @@ -1608,7 +1615,7 @@ function ajaxSuccess() { * {@code true} to display the offline marker, {@code false} to hide * it */ -function toggleOfflineMarker(visible) { +function showOfflineMarker(visible) { /* jQuery documentation says toggle() works the other way around?! */ $("#sone #offline-marker").toggle(visible); if (visible) { @@ -1624,6 +1631,8 @@ function toggleOfflineMarker(visible) { var focus = true; var online = true; +var initiallyLoggedIn = $("#sone #loggedIn").text() == "true"; +var notLoggedIn = !initiallyLoggedIn; $(document).ready(function() { diff --git a/src/main/resources/templates/include/head.html b/src/main/resources/templates/include/head.html index e80a92c..b37df26 100644 --- a/src/main/resources/templates/include/head.html +++ b/src/main/resources/templates/include/head.html @@ -2,6 +2,7 @@
<% formPassword|html>
+ -- 2.7.4