X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=01c04a1cbb60d82c7cf171a8114db44129bb12be;hb=fd5860dbb46063f229492354af88f1ad3701772c;hp=bd372c1e013404bf1869ceb7618f9f8de91aef09;hpb=c2db2042b846b7a220e1b2bcbce538e42cd2de3f;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index bd372c1..01c04a1 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -100,17 +100,20 @@ function getTranslation(key, callback) { * * @param soneId * The ID of the Sone + * @param local + * true if the Sone is local, false + * otherwise */ -function getSoneStatus(soneId) { +function getSoneStatus(soneId, local) { $.getJSON("ajax/getSoneStatus.ajax", {"sone": soneId}, function(data, textStatus) { updateSoneStatus(soneId, data.name, data.status, data.modified, data.lastUpdated); /* seconds! */ updateInterval = 60; - if (data.modified || (data.status == "downloading") || (data.status == "inserting")) { + if (local || data.modified || (data.status == "downloading") || (data.status == "inserting")) { updateInterval = 5; } setTimeout(function() { - getSoneStatus(soneId); + getSoneStatus(soneId, local); }, updateInterval * 1000); }); } @@ -157,15 +160,18 @@ var watchedSones = {}; * * @param soneId * The ID of the Sone to watch + * @param local + * true if the Sone is local, false + * otherwise */ -function watchSone(soneId) { +function watchSone(soneId, local) { if (watchedSones[soneId]) { return; } watchedSones[soneId] = true; (function(soneId) { setTimeout(function() { - getSoneStatus(soneId); + getSoneStatus(soneId, local); }, 5000); })(soneId); } @@ -363,3 +369,41 @@ function updateReplyLikes(replyId) { } }); } + +/** + * Posts a reply and calls the given callback when the request finishes. + * + * @param postId + * The ID of the post the reply refers to + * @param text + * The text to post + * @param callbackFunction + * The callback function to call when the request finishes (takes 3 + * parameters: success, error, replyId) + */ +function postReply(postId, text, callbackFunction) { + $.getJSON("ajax/createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) { + if (data.success) { + callbackFunction(true, null, data.reply); + } else { + callbackFunction(false, data.error); + } + }); +} + +/** + * Requests information about the reply with the given ID. + * + * @param replyId + * The ID of the reply + * @param callbackFunction + * A callback function (parameters soneId, soneName, replyTime, + * replyDisplayTime, text, html) + */ +function getReply(replyId, callbackFunction) { + $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) { + if (data.success) { + callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html); + } + }); +}