X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=a0bbf8aa47441c97bd003ee799785dad5ed0871b;hb=ecf753a31601e558b681daab0598009fe9eec99a;hp=fa2b1cf84372b01b57f7627447e7bf23a45c093d;hpb=693da3f2d937022bca8377d95e57df8ea8ee10f9;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index fa2b1cf..a0bbf8a 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -47,6 +47,7 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op textarea.show(); } $(inputField.get(0).form).submit(function() { + inputField.attr("disabled", "disabled"); if (!optional && (textarea.val() == "")) { return false; } @@ -64,10 +65,11 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op * The element to add a “comment” link to */ function addCommentLink(postId, element, insertAfterThisElement) { - if ($(element).find(".show-reply-form").length > 0) { + if (($(element).find(".show-reply-form").length > 0) || (getPostElement(element).find(".create-reply").length == 0)) { return; } commentElement = (function(postId) { + separator = $(" · ").addClass("separator"); var commentElement = $("
Comment
").addClass("show-reply-form").click(function() { markPostAsKnown(getPostElement(this)); replyElement = $("#sone .post#" + postId + " .create-reply"); @@ -87,6 +89,7 @@ function addCommentLink(postId, element, insertAfterThisElement) { return commentElement; })(postId); $(insertAfterThisElement).after(commentElement.clone(true)); + $(insertAfterThisElement).after(separator); } var translations = {}; @@ -105,7 +108,7 @@ function getTranslation(key, callback) { callback(translations[key]); return; } - $.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) { + $.getJSON("getTranslation.ajax", {"key": key}, function(data, textStatus) { if ((data != null) && data.success) { translations[key] = data.value; callback(data.value); @@ -150,7 +153,13 @@ function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated) { toggleClass("modified", modified); $("#sone .sone." + filterSoneId(soneId) + " .lock").toggleClass("hidden", locked); $("#sone .sone." + filterSoneId(soneId) + " .unlock").toggleClass("hidden", !locked); - $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated); + if (lastUpdated != null) { + $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated); + } else { + getTranslation("View.Sone.Text.UnknownDate", function(unknown) { + $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(unknown); + }); + } $("#sone .sone." + filterSoneId(soneId) + " .profile-link a").text(name); } @@ -201,7 +210,7 @@ function enhanceDeleteButton(button, text, deleteCallback) { */ function enhanceDeletePostButton(button, postId, text) { enhanceDeleteButton(button, text, function() { - $.getJSON("ajax/deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) { + $.getJSON("deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) { if (data == null) { return; } @@ -232,7 +241,7 @@ function enhanceDeletePostButton(button, postId, text) { */ function enhanceDeleteReplyButton(button, replyId, text) { enhanceDeleteButton(button, text, function() { - $.getJSON("ajax/deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) { + $.getJSON("deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) { if (data == null) { return; } @@ -256,7 +265,7 @@ function getFormPassword() { } function getSoneElement(element) { - return $(element).parents(".sone"); + return $(element).closest(".sone"); } /** @@ -301,6 +310,17 @@ function getPostTime(element) { return getPostElement(element).find(".post-time").text(); } +/** + * Returns the author of the post the given element belongs to. + * + * @param element + * The element whose post to get the author for + * @returns The ID of the authoring Sone + */ +function getPostAuthor(element) { + return getPostElement(element).find(".post-author").text(); +} + function getReplyElement(element) { return $(element).closest(".reply"); } @@ -313,8 +333,19 @@ function getReplyTime(element) { return getReplyElement(element).find(".reply-time").text(); } +/** + * Returns the author of the reply the given element belongs to. + * + * @param element + * The element whose reply to get the author for + * @returns The ID of the authoring Sone + */ +function getReplyAuthor(element) { + return getReplyElement(element).find(".reply-author").text(); +} + function likePost(postId) { - $.getJSON("ajax/like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) { + $.getJSON("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) { if ((data == null) || !data.success) { return; } @@ -327,7 +358,7 @@ function likePost(postId) { } function unlikePost(postId) { - $.getJSON("ajax/unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) { + $.getJSON("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) { if ((data == null) || !data.success) { return; } @@ -340,7 +371,7 @@ function unlikePost(postId) { } function updatePostLikes(postId) { - $.getJSON("ajax/getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) { + $.getJSON("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) { if ((data != null) && data.success) { $("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0) $("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes); @@ -352,7 +383,7 @@ function updatePostLikes(postId) { } function likeReply(replyId) { - $.getJSON("ajax/like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) { + $.getJSON("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) { if ((data == null) || !data.success) { return; } @@ -365,7 +396,7 @@ function likeReply(replyId) { } function unlikeReply(replyId) { - $.getJSON("ajax/unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) { + $.getJSON("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) { if ((data == null) || !data.success) { return; } @@ -377,8 +408,76 @@ function unlikeReply(replyId) { }); } +/** + * Trusts the Sone with the given ID. + * + * @param soneId + * The ID of the Sone to trust + */ +function trustSone(soneId) { + $.getJSON("trustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) { + if ((data != null) && data.success) { + updateTrustControls(soneId, data.trustValue); + } + }); +} + +/** + * Distrusts the Sone with the given ID, i.e. assigns a negative trust value. + * + * @param soneId + * The ID of the Sone to distrust + */ +function distrustSone(soneId) { + $.getJSON("distrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) { + if ((data != null) && data.success) { + updateTrustControls(soneId, data.trustValue); + } + }); +} + +/** + * Untrusts the Sone with the given ID, i.e. removes any trust assignment. + * + * @param soneId + * The ID of the Sone to untrust + */ +function untrustSone(soneId) { + $.getJSON("untrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) { + if ((data != null) && data.success) { + updateTrustControls(soneId, data.trustValue); + } + }); +} + +/** + * Updates the trust controls for all posts and replies of the given Sone, + * according to the given trust value. + * + * @param soneId + * The ID of the Sone to update all trust controls for + * @param trustValue + * The trust value for the Sone + */ +function updateTrustControls(soneId, trustValue) { + $("#sone .post").each(function() { + if (getPostAuthor(this) == soneId) { + getPostElement(this).find(".post-trust").toggleClass("hidden", trustValue != null); + getPostElement(this).find(".post-distrust").toggleClass("hidden", trustValue != null); + getPostElement(this).find(".post-untrust").toggleClass("hidden", trustValue == null); + } + }); + $("#sone .reply").each(function() { + if (getReplyAuthor(this) == soneId) { + getReplyElement(this).find(".reply-trust").toggleClass("hidden", trustValue != null); + getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null); + getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null); + } + }); +} + function updateReplyLikes(replyId) { - $.getJSON("ajax/getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) { + $.getJSON("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) { if ((data != null) && data.success) { $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0) $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes); @@ -392,6 +491,8 @@ function updateReplyLikes(replyId) { /** * Posts a reply and calls the given callback when the request finishes. * + * @param sender + * The ID of the sender * @param postId * The ID of the post the reply refers to * @param text @@ -400,14 +501,14 @@ function updateReplyLikes(replyId) { * 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) { +function postReply(sender, postId, text, callbackFunction) { + $.getJSON("createReply.ajax", { "formPassword" : getFormPassword(), "sender": sender, "post" : postId, "text": text }, function(data, textStatus) { if (data == null) { /* TODO - show error */ return; } if (data.success) { - callbackFunction(true, null, data.reply); + callbackFunction(true, null, data.reply, data.sone); } else { callbackFunction(false, data.error); } @@ -426,7 +527,7 @@ function postReply(postId, text, callbackFunction) { * replyDisplayTime, text, html) */ function getReply(replyId, callbackFunction) { - $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) { + $.getJSON("getReply.ajax", { "reply" : replyId }, function(data, textStatus) { if ((data != null) && data.success) { callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html); } @@ -446,19 +547,25 @@ function ajaxifyPost(postElement) { return false; }); $(postElement).find(".create-reply button:submit").click(function() { - inputField = $(this.form).find(":input:enabled").get(0); + sender = $(this.form).find(":input[name=sender]").val(); + inputField = $(this.form).find(":input[name=text]:enabled").get(0); postId = getPostId(this); text = $(inputField).val(); - $(inputField).val(""); - postReply(postId, text, function(success, error, replyId) { - if (success) { - loadNewReply(replyId); - markPostAsKnown(getPostElement(inputField)); - $("#sone .post#" + postId + " .create-reply").addClass("hidden"); - } else { - alert(error); - } - }); + (function(sender, postId, text, inputField) { + postReply(sender, postId, text, function(success, error, replyId, soneId) { + if (success) { + $(inputField).val(""); + loadNewReply(replyId, soneId, postId); + markPostAsKnown(getPostElement(inputField)); + $("#sone .post#" + postId + " .create-reply").addClass("hidden"); + $("#sone .post#" + postId + " .create-reply .sender").hide(); + $("#sone .post#" + postId + " .create-reply .select-sender").show(); + $("#sone .post#" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId()); + } else { + alert(error); + } + }); + })(sender, postId, text, inputField); return false; }); @@ -482,6 +589,20 @@ function ajaxifyPost(postElement) { return false; }); + /* convert trust control buttons to javascript functions. */ + $(postElement).find(".post-trust").submit(function() { + trustSone(getPostAuthor(this)); + return false; + }); + $(postElement).find(".post-distrust").submit(function() { + distrustSone(getPostAuthor(this)); + return false; + }); + $(postElement).find(".post-untrust").submit(function() { + untrustSone(getPostAuthor(this)); + return false; + }); + /* add “comment” link. */ addCommentLink(getPostId(postElement), postElement, $(postElement).find(".post-status-line .time")); @@ -497,8 +618,20 @@ function ajaxifyPost(postElement) { }); }); + /* process sender selection. */ + $(".select-sender", postElement).css("display", "inline"); + $(".sender", postElement).hide(); + $(".select-sender button", postElement).click(function() { + $(".sender", postElement).show(); + $(".select-sender", postElement).hide(); + return false; + }); + /* mark everything as known on click. */ - $(postElement).click(function() { + $(postElement).click(function(event) { + if ($(event.target).hasClass("click-to-show")) { + return false; + } markPostAsKnown(this); }); @@ -532,9 +665,23 @@ function ajaxifyReply(replyElement) { })(replyElement); addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time")); + /* convert trust control buttons to javascript functions. */ + $(replyElement).find(".reply-trust").submit(function() { + trustSone(getReplyAuthor(this)); + return false; + }); + $(replyElement).find(".reply-distrust").submit(function() { + distrustSone(getReplyAuthor(this)); + return false; + }); + $(replyElement).find(".reply-untrust").submit(function() { + untrustSone(getReplyAuthor(this)); + return false; + }); + /* mark post and all replies as known on click. */ $(replyElement).click(function() { - markPostAsKnown(getPostElement(replyElement)); + markPostAsKnown(getPostElement(this)); }); } @@ -545,11 +692,19 @@ function ajaxifyReply(replyElement) { * jQuery object representing the notification. */ function ajaxifyNotification(notification) { - notification.find("form.dismiss").submit(function() { + notification.find("form").submit(function() { return false; }); + notification.find("input[name=returnPage]").val($.url.attr("relative")); + if (notification.find(".short-text").length > 0) { + notification.find(".short-text").removeClass("hidden"); + notification.find(".text").addClass("hidden"); + } + notification.find("form.mark-as-read button").click(function() { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); + }); notification.find("form.dismiss button").click(function() { - $.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) { + $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) { /* dismiss in case of error, too. */ notification.slideUp(); }, function(xmlHttpRequest, textStatus, error) { @@ -560,11 +715,11 @@ function ajaxifyNotification(notification) { } function getStatus() { - $.getJSON("ajax/getStatus.ajax", {}, function(data, textStatus) { + $.getJSON("getStatus.ajax", {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { - updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdated); + updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated); }); /* process notifications. */ $.each(data.notifications, function(index, value) { @@ -583,11 +738,11 @@ function getStatus() { }); /* process new posts. */ $.each(data.newPosts, function(index, value) { - loadNewPost(value); + loadNewPost(value.id, value.sone, value.recipient, value.time); }); /* process new replies. */ $.each(data.newReplies, function(index, value) { - loadNewReply(value); + loadNewReply(value.id, value.sone, value.post, value.postSone); }); /* do it again in 5 seconds. */ setTimeout(getStatus, 5000); @@ -602,6 +757,16 @@ function getStatus() { } /** + * Returns the ID of the currently logged in Sone. + * + * @return The ID of the current Sone, or an empty string if no Sone is logged + * in + */ +function getCurrentSoneId() { + return $("#currentSoneId").text(); +} + +/** * Returns the content of the page-id attribute. * * @returns The page ID @@ -636,7 +801,7 @@ function isViewSonePage() { * * @returns The ID of the currently shown Sone */ -function getSoneId() { +function getShownSoneId() { return $("#sone .sone-id").text(); } @@ -656,21 +821,64 @@ function isViewPostPage() { * * @returns The ID of the currently shown post */ -function getPostId() { +function getShownPostId() { return $("#sone .post-id").text(); } -var loadedPosts = {}; -var loadedReplies = {}; +/** + * Returns whether the current page is the “known Sones” page. + * + * @returns {Boolean} true if the current page is the “known + * Sones” page, false otherwise + */ +function isKnownSonesPage() { + return getPageId() == "known-sones"; +} -function loadNewPost(postId) { - if (postId in loadedPosts) { +/** + * Returns whether a post with the given ID exists on the current page. + * + * @param postId + * The post ID to check for + * @returns {Boolean} true if a post with the given ID already + * exists on the page, false otherwise + */ +function hasPost(postId) { + return $(".post#" + postId).length > 0; +} + +/** + * Returns whether a reply with the given ID exists on the current page. + * + * @param replyId + * The reply ID to check for + * @returns {Boolean} true if a reply with the given ID already + * exists on the page, false otherwise + */ +function hasReply(replyId) { + return $("#sone .reply#" + replyId).length > 0; +} + +function loadNewPost(postId, soneId, recipientId, time) { + if (hasPost(postId)) { + return; + } + if (!isIndexPage()) { + if (!isViewPostPage() || (getShownPostId() != postId)) { + if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId))) { + return; + } + } + } + if (getPostTime($("#sone .post").last()) > time) { return; } - loadedPosts[postId] = true; - $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) { + $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { - if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) { + if (hasPost(data.post.id)) { + return; + } + if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) { return; } var firstOlderPost = null; @@ -683,8 +891,6 @@ function loadNewPost(postId) { newPost = $(data.post.html).addClass("hidden"); if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); - } else { - $("#sone .post:last").append(newPost); } ajaxifyPost(newPost); newPost.slideDown(); @@ -693,14 +899,19 @@ function loadNewPost(postId) { }); } -function loadNewReply(replyId) { - if (replyId in loadedReplies) { +function loadNewReply(replyId, soneId, postId, postSoneId) { + if (hasReply(replyId)) { return; } - loadedReplies[replyId] = true; - $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) { + if (!hasPost(postId)) { + return; + } + $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) { /* find post. */ if ((data != null) && data.success) { + if (hasReply(data.reply.id)) { + return; + } $("#sone .post#" + data.reply.postId).each(function() { var firstNewerReply = null; $(this).find(".replies .reply").each(function() { @@ -722,6 +933,7 @@ function loadNewReply(replyId) { ajaxifyReply(newReply); newReply.slideDown(); setActivity(); + return false; }); } }); @@ -732,8 +944,9 @@ function markPostAsKnown(postElements) { postElement = this; if ($(postElement).hasClass("new")) { (function(postElement) { - $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) { $(postElement).removeClass("new"); + $(".click-to-show", postElement).removeClass("new"); }); })(postElement); } @@ -746,7 +959,7 @@ function markReplyAsKnown(replyElements) { replyElement = this; if ($(replyElement).hasClass("new")) { (function(replyElement) { - $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) { $(replyElement).removeClass("new"); }); })(replyElement); @@ -792,6 +1005,91 @@ function createNotification(id, text, dismissable) { return notification; } +/** + * Shows the details of the notification with the given ID. + * + * @param notificationId + * The ID of the notification + */ +function showNotificationDetails(notificationId) { + $("#sone .notification#" + notificationId + " .text").show(); + $("#sone .notification#" + notificationId + " .short-text").hide(); +} + +/** + * Deletes the field with the given ID from the profile. + * + * @param fieldId + * The ID of the field to delete + */ +function deleteProfileField(fieldId) { + $.getJSON("deleteProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId}, function(data, textStatus) { + if (data && data.success) { + $("#sone .profile-field#" + data.field.id).slideUp(); + } + }); +} + +/** + * Renames a profile field. + * + * @param fieldId + * The ID of the field to rename + * @param newName + * The new name of the field + * @param successFunction + * Called when the renaming was successful + */ +function editProfileField(fieldId, newName, successFunction) { + $.getJSON("editProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "name": newName}, function(data, textStatus) { + if (data && data.success) { + successFunction(); + } + }); +} + +/** + * Moves the profile field with the given ID one slot in the given direction. + * + * @param fieldId + * The ID of the field to move + * @param direction + * The direction to move in (“up” or “down”) + * @param successFunction + * Function to call on success + */ +function moveProfileField(fieldId, direction, successFunction) { + $.getJSON("moveProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "direction": direction}, function(data, textStatus) { + if (data && data.success) { + successFunction(); + } + }); +} + +/** + * Moves the profile field with the given ID up one slot. + * + * @param fieldId + * The ID of the field to move + * @param successFunction + * Function to call on success + */ +function moveProfileFieldUp(fieldId, successFunction) { + moveProfileField(fieldId, "up", successFunction); +} + +/** + * Moves the profile field with the given ID down one slot. + * + * @param fieldId + * The ID of the field to move + * @param successFunction + * Function to call on success + */ +function moveProfileFieldDown(fieldId, successFunction) { + moveProfileField(fieldId, "down", successFunction); +} + // // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE // @@ -803,11 +1101,40 @@ $(document).ready(function() { /* this initializes the status update input field. */ getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) { registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false); + $("#sone #update-status .select-sender").css("display", "inline"); + $("#sone #update-status .sender").hide(); + $("#sone #update-status .select-sender button").click(function() { + $("#sone #update-status .sender").show(); + $("#sone #update-status .select-sender").hide(); + return false; + }); $("#sone #update-status").submit(function() { + if ($(this).find(":input.default:enabled").length > 0) { + return false; + } + sender = $(this).find(":input[name=sender]").val(); + text = $(this).find(":input[name=text]:enabled").val(); + $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "sender": sender, "text": text }, function(data, textStatus) { + if ((data != null) && data.success) { + loadNewPost(data.postId, data.sone, data.recipient); + } + }); + $(this).find(":input[name=sender]").val(getCurrentSoneId()); + $(this).find(":input[name=text]:enabled").val("").blur(); + $(this).find(".sender").hide(); + $(this).find(".select-sender").show(); + return false; + }); + }); + + /* ajaxify input field on “view Sone” page. */ + getTranslation("WebInterface.DefaultText.Message", function(defaultText) { + registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false); + $("#sone #post-message").submit(function() { text = $(this).find(":input:enabled").val(); - $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) { + $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "text": text }, function(data, textStatus) { if ((data != null) && data.success) { - loadNewPost(data.postId); + loadNewPost(data.postId, getCurrentSoneId()); } }); $(this).find(":input:enabled").val("").blur(); @@ -828,30 +1155,32 @@ $(document).ready(function() { }); /* hides all replies but the latest two. */ - getTranslation("WebInterface.ClickToShow.Replies", function(text) { - $("#sone .post .replies").each(function() { - allReplies = $(this).find(".reply"); - if (allReplies.length > 2) { - newHidden = false; - for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) { - $(allReplies[replyIndex]).addClass("hidden"); - newHidden |= $(allReplies[replyIndex]).hasClass("new"); - } - clickToShowElement = $("
").addClass("click-to-show"); - if (newHidden) { - clickToShowElement.addClass("new"); + if (!isViewPostPage()) { + getTranslation("WebInterface.ClickToShow.Replies", function(text) { + $("#sone .post .replies").each(function() { + allReplies = $(this).find(".reply"); + if (allReplies.length > 2) { + newHidden = false; + for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) { + $(allReplies[replyIndex]).addClass("hidden"); + newHidden |= $(allReplies[replyIndex]).hasClass("new"); + } + clickToShowElement = $("
").addClass("click-to-show"); + if (newHidden) { + clickToShowElement.addClass("new"); + } + (function(clickToShowElement, allReplies, text) { + clickToShowElement.text(text); + clickToShowElement.click(function() { + allReplies.removeClass("hidden"); + clickToShowElement.addClass("hidden"); + }); + })(clickToShowElement, allReplies, text); + $(allReplies[0]).before(clickToShowElement); } - (function(clickToShowElement, allReplies, text) { - clickToShowElement.text(text); - clickToShowElement.click(function() { - allReplies.removeClass("hidden"); - clickToShowElement.addClass("hidden"); - }); - })(clickToShowElement, allReplies, text); - $(allReplies[0]).before(clickToShowElement); - } + }); }); - }); + } /* * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something @@ -859,7 +1188,7 @@ $(document).ready(function() { */ $("#sone .follow").submit(function() { var followElement = this; - $.getJSON("ajax/followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { $(followElement).addClass("hidden"); $(followElement).parent().find(".unfollow").removeClass("hidden"); }); @@ -867,7 +1196,7 @@ $(document).ready(function() { }); $("#sone .unfollow").submit(function() { var unfollowElement = this; - $.getJSON("ajax/unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { $(unfollowElement).addClass("hidden"); $(unfollowElement).parent().find(".follow").removeClass("hidden"); }); @@ -875,7 +1204,7 @@ $(document).ready(function() { }); $("#sone .lock").submit(function() { var lockElement = this; - $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { $(lockElement).addClass("hidden"); $(lockElement).parent().find(".unlock").removeClass("hidden"); }); @@ -883,7 +1212,7 @@ $(document).ready(function() { }); $("#sone .unlock").submit(function() { var unlockElement = this; - $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { $(unlockElement).addClass("hidden"); $(unlockElement).parent().find(".lock").removeClass("hidden"); });