X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=b3f5c8342cf64b4c3bc1e309e5d5a960616774b5;hb=19e49c0a2463b90c3468903672d8ba600da217d2;hp=32045077468117ca98e05cc6efe537f41a810e51;hpb=7df20dec7dcc9aa6d1aa657d24f273e1a82c60fc;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 3204507..b3f5c83 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -145,7 +145,7 @@ function filterSoneId(soneId) { * The date and time of the last update (formatted for display) */ function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated, lastUpdatedText) { - var updateSone = sone.find(".sone." + filterSoneId(soneId)); + var updateSone = sone.find(".sone." + filterSoneId(soneId)); updateSone.toggleClass("unknown", status == "unknown"). toggleClass("idle", status == "idle"). toggleClass("inserting", status == "inserting"). @@ -718,6 +718,7 @@ function ajaxifyPost(postElement) { sone.find(".post#post-" + postId + " .create-reply .sender").hide(); sone.find(".post#post-" + postId + " .create-reply .select-sender").show(); sone.find(".post#post-" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId()); + updateReplyTimes(replyId); } else { alert(error); } @@ -1193,7 +1194,13 @@ function checkForRemovedReplies(oldNotification, newNotification) { } function getStatus() { - ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}, function(data, textStatus) { + var parameters = isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}; + $.extend(parameters, { + "elements": JSON.stringify($(".linked-element.not-loaded").map(function () { + return $(this).attr("title"); + }).toArray()) + }); + ajaxGet("getStatus.ajax", parameters, function(data, textStatus) { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { @@ -1215,6 +1222,9 @@ function getStatus() { loadNewReply(value.id, value.sone, value.post, value.postSone); }); } + if (data.linkedElements) { + loadLinkedElements(data.linkedElements) + } /* do it again in 5 seconds. */ setTimeout(getStatus, 5000); } else { @@ -1519,6 +1529,41 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { }); } +function loadLinkedElements(links) { + var failedElements = links.filter(function(element) { + return element.failed; + }); + if (failedElements.length > 0) { + failedElements.forEach(function(element) { + getLinkedElements(element.link).each(function() { + $(this).remove() + }); + }); + } + var loadedElements = links.filter(function(element) { + return !element.loading && !element.failed; + }); + if (loadedElements.length > 0) { + ajaxGet("getLinkedElement.ajax", { + "elements": JSON.stringify(loadedElements.map(function(element) { + return element.link; + })) + }, function (data, textStatus) { + if ((data != null) && (data.success)) { + data.linkedElements.forEach(function (linkedElement) { + getLinkedElements(linkedElement.link).each(function() { + $(this).replaceWith(linkedElement.html); + }); + }); + } + }); + } +} + +function getLinkedElements(link) { + return $(".linked-element[title='" + link + "']") +} + /** * Marks the given Sone as known if it is still new. * @@ -1946,11 +1991,11 @@ $(document).ready(function() { /* Ajaxifies all posts. */ /* calling getTranslation here will cache the necessary values. */ - getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) { - getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(text) { - getTranslation("WebInterface.DefaultText.Reply", function(text) { - getTranslation("WebInterface.Button.Comment", function(text) { - sone.find(".post").each(function() { + getTranslation("WebInterface.Confirmation.DeletePostButton", function() { + getTranslation("WebInterface.Confirmation.DeleteReplyButton", function() { + getTranslation("WebInterface.DefaultText.Reply", function() { + getTranslation("WebInterface.Button.Comment", function () { + sone.find(".post").each(function() { ajaxifyPost(this); }); });